server.starttls() server.login(fromaddr, "password") server.sendmail(fromaddr, toaddr, msg) server.quit() print('send email ok -- '+ type) print("Actual time:") loc = pytz.utc.localize(datetime.utcnow()) paristime = loc.astimezone(pytz.timezone('Europe/Paris')) fmt = '%Y-%m-%d %H:%M:%S %Z%z' print(paristime.strftime(fmt)+'\n\n') body = '' try: rescours = AnalyseCours.analyse(inners=cours_download.connectEsv(writeFile=False, usr='******', pwd='ZWTzwt940331', nbWeeks = 8)) except: rescours = 'bug' if (rescours == 'changed'): body = 'You have new cours or cours changed, check it if you want\n' elif(rescours == 'bug'): body = 'Get cours information bugged, check your code\n' if body != '': sendmail('cours', body) print('result cours:'+ rescours+'\n\n') loc = pytz.utc.localize(datetime.utcnow()) paristime = loc.astimezone(pytz.timezone('Europe/Paris'))
def __init__(self, master=None, **kwargs): global usr global pwd global choice tk.Frame.__init__(self, master, **kwargs) master.title("Window to check information") master.geometry('%dx%d+%d+%d' % (1200, 800, (master.winfo_screenwidth() - 1200) / 2, 0)) # 1200*800 is size of window. screenwidth-1200/2 to center the window self.information = tkst.ScrolledText(self, wrap=tk.WORD, height=20, width=100) self.btn1 = tk.Button(self, text='Cours', command=self.CoursButton, height=3, width=40) self.btn2 = tk.Button(self, text='Absences', command=self.AbsButton, height=3, width=40) self.btn3 = tk.Button(self, text='Notes', command=self.NotesButton, height=3, width=40) self.btn5 = tk.Button(self, text='Update Cours', command=self.UpdateCours, height=3, width=40) self.btn6 = tk.Button(self, text='Update Absences', command=self.UpdateAbsences, height=3, width=40) self.btn7 = tk.Button(self, text='Update Notes', command=self.UpdateNotes, height=3, width=40) self.btn8 = tk.Button(self, text='Update All', command=self.UpdateAll, height=3, width=40) self.text_search = tk.Entry(self, width=40) self.information.config(font=font.Font(size=15)) self.information.configure(background='#C0C0C0') self.btn2.config(font=font.Font(size=12)) self.btn3.config(font=font.Font(size=12)) self.btn1.config(font=font.Font(size=12)) self.btn5.config(font=font.Font(size=12)) self.btn6.config(font=font.Font(size=12)) self.btn7.config(font=font.Font(size=12)) self.btn8.config(font=font.Font(size=12)) self.text_search.config(font=font.Font(size=12)) self.information.insert( tk.INSERT, 'Click the boutons on the left side to check information from localhost file.\nClick the boutons on the right side to update information from website.\nAnd the area of text is for the search of cours with key word.\n' ) self.information.grid(row=0, column=0, columnspan=2) self.btn1.grid(row=1, column=0) self.btn2.grid(row=2, column=0) self.btn3.grid(row=3, column=0) self.text_search.grid(row=4, column=0) self.btn5.grid(row=1, column=1) self.btn6.grid(row=2, column=1) self.btn7.grid(row=3, column=1) self.btn8.grid(row=4, column=1) self.text_search.bind("<Return>", self.SearchCours) if (choice == 1): try: resabs = AnalyseAbs.analyse(inners=abs_download.connectEsv( writeFile=False, usr=usr, pwd=pwd)) except: resabs = 'bug' self.information.delete("1.0", tk.END) if (resabs == 'unchanged'): self.information.insert(tk.INSERT, 'ABS isn\'t changed\n') elif (resabs == 'changed'): self.information.insert(tk.INSERT, 'New ABS has been saved\n') elif (resabs == 'bug'): self.information.insert(tk.INSERT, 'ABS bugged\n') elif (resabs == 'zero'): self.information.insert(tk.INSERT, 'You don\'t have any absence now\n') self.information.insert(tk.INSERT, '\n') elif (choice == 2): try: resnotes = AnalyseNotes.analyse( inners=notes_download.connectEsv( writeFile=False, usr=usr, pwd=pwd)) except: resnotes = 'bug' self.information.delete("1.0", tk.END) if (resnotes == 'unchanged'): self.information.insert(tk.INSERT, 'Note isn\'t changed\n') elif (resnotes == 'changed'): self.information.insert(tk.INSERT, 'New note has been saved\n') elif (resnotes == 'bug'): self.information.insert(tk.INSERT, 'Notes bugged\n') self.information.insert(tk.INSERT, '\n') elif (choice == 3): try: rescours = AnalyseCours.analyse( inners=cours_download.connectEsv( writeFile=False, usr=usr, pwd=pwd, nbWeeks=5)) except: rescours = 'bug' self.information.delete("1.0", tk.END) if (rescours == 'unchanged'): self.information.insert( tk.INSERT, 'Cours are not changed or totally included by old one\n') elif (rescours == 'changed'): self.information.insert( tk.INSERT, 'New cours have been saved or some cours are changed\n') elif (rescours == 'bug'): self.information.insert(tk.INSERT, 'Cours bugged\n') self.information.insert(tk.INSERT, '\n') elif (choice == 4): try: resabs = AnalyseAbs.analyse(inners=abs_download.connectEsv( writeFile=False, usr=usr, pwd=pwd)) except: resabs = 'bug' self.information.delete("1.0", tk.END) if (resabs == 'unchanged'): self.information.insert(tk.INSERT, 'ABS isn\'t changed\n') elif (resabs == 'changed'): self.information.insert(tk.INSERT, 'New ABS has been saved\n') elif (resabs == 'bug'): self.information.insert(tk.INSERT, 'ABS bugged\n') elif (resabs == 'zero'): self.information.insert(tk.INSERT, 'You don\'t have any absence now\n') try: resnotes = AnalyseNotes.analyse( inners=notes_download.connectEsv( writeFile=False, usr=usr, pwd=pwd)) except: resnotes = 'bug' if (resnotes == 'unchanged'): self.information.insert(tk.INSERT, 'Note isn\'t changed\n') elif (resnotes == 'changed'): self.information.insert(tk.INSERT, 'New note has been saved\n') elif (resnotes == 'bug'): self.information.insert(tk.INSERT, 'Notes bugged\n') try: rescours = AnalyseCours.analyse( inners=cours_download.connectEsv( writeFile=False, usr=usr, pwd=pwd, nbWeeks=5)) except: rescours = 'bug' if (rescours == 'unchanged'): self.information.insert( tk.INSERT, 'Cours are not changed or totally included by old one\n') elif (rescours == 'changed'): self.information.insert( tk.INSERT, 'New cours have been saved or some cours are changed\n') elif (rescours == 'bug'): self.information.insert(tk.INSERT, 'Cours bugged\n') self.information.insert(tk.INSERT, '\n') choice = 0
except: resabs = 'bug' if (resabs == 'changed'): body = 'You have new abs, check it if you want' try: resnotes = AnalyseNotes.analyse(inners=notes_download.connectEsv(writeFile=False, usr='******', pwd='???')) except: resnotes = 'bug' if (resnotes == 'changed'): body = 'You have new notes, check it if you want' try: rescours = AnalyseCours.analyse( inners=cours_download.connectEsv(writeFile=False, usr='******', pwd='???', nbWeeks=10)) except: pass if body != '': import smtplib from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText fromaddr = "*****@*****.**" toaddr = "*****@*****.**" msg = MIMEMultipart() msg['From'] = fromaddr msg['To'] = toaddr msg['Subject'] = "CHANGEMENT OF E-SERVICES"