-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.pyw
More file actions
117 lines (101 loc) · 2.97 KB
/
main.pyw
File metadata and controls
117 lines (101 loc) · 2.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import myParser
import urllib.request
import time
from tkinter.messagebox import askquestion,showerror,showinfo
from tkinter import Tk
from webbrowser import open_new
from hashlib import md5
import os
FAIL=0
SUCCESS=1
class stack():
def __init__(self):
self.sta=[]
def push(self,item):
self.sta.append(item)
def pop(self):
return self.sta.pop()
def ifEmpty(self):
if len(self.sta)==0:
return True
else:
return False
def refresh():
page=urllib.request.urlopen('http://www.jwc.sjtu.edu.cn/web/sjtu/198076.htm')
pageF=page.read().decode(encoding="gb2312",errors="strict")
getinfo=myParser.myParser()
getinfo.feed(pageF)
result=getinfo.getResult()
return result
def refreshData(result):
db=open('data','r')
db.seek(0)
dbMd5=db.read(32)
k=0
for item in result:
if dbMd5 == md5((item[0]).encode()).hexdigest():
break
else:
k+=1
db.close()
db=open('data','w')
LatestMD5=md5((result[0][0]).encode()).hexdigest()
db.write(LatestMD5+'\n')
for items in result:
db.write(items[0]+'\n')
db.write(items[1]+'\n')
return k
def main():
init=False
if os.path.exists('init'):
init=True
if not os.path.exists('data'):
data=open('data','w')
data.close()
root=Tk()
root.withdraw()
while True:
result=refresh()
news=refreshData(result)
mesgBox=stack()
if news>0:
i=0
while (i < news):
mesgBox.push(result[i])
i+=1
log=open('log.log',mode='a')
log.write(str(i)+" piece(s) of news updated"+(time.strftime('%X %x '))+'\n')
log.close()
else:
log=open('log.log',mode='a')
log.write("Nothing new "+(time.strftime('%X %x'))+'\n')
log.close()
while not mesgBox.ifEmpty() :
info=mesgBox.pop()
if init:
flag=askquestion('教务处的新通知',info[0]+'\n'+"是否查看?",icon='info')
if flag=='yes':
open_new('http://www.jwc.sjtu.edu.cn/web/sjtu/'+info[1])
if not init:
init_file=open('init',mode='w')
init_file.close()
showinfo('First Start','jwcViewer 1.1 initialized.')
time.sleep(300)
last_status=SUCCESS
while True:
try:
main()
if last_status==FAIL:
last_status=SUCCESS
log=open('log.log',mode='a')
log.write("Update Success "+(time.strftime('%X %x'))+'\n')
log.close()
except:
if last_status==SUCCESS:
showerror('Error', 'Please check your network or update this program.')
log=open('log.log',mode='a')
log.write("Unknown Error "+(time.strftime('%X %x'))+'\n')
log.close()
last_status=FAIL
else:
time.sleep(300)