botofmy


SUBMITTED BY: bitcoinsachen

DATE: Dec. 20, 2016, 12:09 p.m.

FORMAT: Python 3

SIZE: 3.3 kB

HITS: 839

  1. import smtplib
  2. from time import *
  3. import time
  4. import requests
  5. import re
  6. from email.mime.multipart import MIMEMultipart
  7. from email.mime.text import MIMEText
  8. import difflib
  9. import os
  10. #from difflib_data import *
  11. from lxml.html.clean import Cleaner
  12. LOGIN_URL = 'https://iu.zid.tuwien.ac.at/AuthServ.portal'
  13. DATA_URL2 = 'https://iu.zid.tuwien.ac.at/AuthServ.authenticate?app=36'
  14. DATA_URL = 'https://tiss.tuwien.ac.at/education/favorites.xhtml?windowId=895'
  15. DATA_URL_FAV='https://tuwel.tuwien.ac.at/mod/page/view.php?id=276628'
  16. #DATA_URL = 'https://tiss.tuwien.ac.at/education/course/examDateList.xhtml?windowId=a86&courseNr=101132&semester=2015W'
  17. payload = {
  18. 'name': 'matrikelnr',
  19. 'pw': 'PASSWORT_HIER_REIN'
  20. }
  21. def sendmail(datain):
  22. to = '...@student.tuwien.ac.at'
  23. gmail_user = '...@student.tuwien.ac.at'
  24. gmail_pwd = 'PASSWORT_HIER_REIN'
  25. smtpserver = smtplib.SMTP("mail.student.tuwien.ac.at",587)
  26. smtpserver.ehlo()
  27. smtpserver.starttls()
  28. smtpserver.ehlo
  29. smtpserver.login(gmail_user, gmail_pwd)
  30. header = 'To:' + to + '\n' + 'From: ' + gmail_user + '\n' + 'Subject:testing \n'
  31. print (header)
  32. #msg = header + '\n this \n'
  33. msg = MIMEMultipart('alternative')
  34. msg['Subject'] = "Seitenupdate Tuwel"
  35. msg['From'] = gmail_user
  36. msg['To'] = 'you'
  37. part1 = MIMEText(datain, 'plain')
  38. part2 = MIMEText(datain, 'html')
  39. msg.attach(part1)
  40. msg.attach(part2)
  41. smtpserver.sendmail(gmail_user, to, msg.as_string())
  42. #smtpserver.sendmail(gmail_user, to, msg)
  43. print ('done!')
  44. smtpserver.close()
  45. return 0
  46. with requests.Session() as s:
  47. cleaner = Cleaner(page_structure=False)
  48. s.post(LOGIN_URL, data=payload)
  49. s.get(DATA_URL2)
  50. r = s.get(DATA_URL_FAV)
  51. #htmlold=cleaner.clean_html(r.content)
  52. r = s.get(DATA_URL_FAV)
  53. htmlold=cleaner.clean_html(r.content)
  54. htmlold=re.sub('id="[^"]','',htmlold)
  55. # htmlold=re.sub('<ul[^>]','',htmlold)
  56. htmlold=re.sub('............_group','',htmlold)
  57. # f = open("htmlold.txt","r")
  58. # htmlold = f.read()
  59. # f.close()
  60. while 1:
  61. r=s.get(DATA_URL_FAV)
  62. htmlnew=cleaner.clean_html(r.content)
  63. #changes
  64. htmlnew=re.sub('id="[^"]','',htmlnew)
  65. # htmlnew=re.sub('<ul[^>]','',htmlnew)
  66. htmlnew=re.sub('............_group','',htmlnew)
  67. #
  68. f = open("htmlold.txt","w")
  69. f.write(htmlold)
  70. f.close()
  71. f = open("htmlnew.txt","w")
  72. f.write(htmlnew)
  73. f.close()
  74. if htmlnew == htmlold:
  75. print (strftime("true: %H:%M:%S", localtime()))
  76. else:
  77. os.system("bash -c \"diff htmlold.txt htmlnew.txt\" > changes.txt")
  78. f = open("changes.txt","r")
  79. changes = f.read()
  80. f.close()
  81. while(changes.find("img src=")!=-1):
  82. i=changes.find("img src=")
  83. changes=changes[1:i]+"IMG"+changes[i+3:len(changes)]
  84. changes=changes[1:i+8]+"https://tiss.tuwien.ac.at"+changes[i+8:len(changes)]
  85. sendmail("<div>alt --- > neu</div>"+changes)
  86. # print(changes)
  87. htmlold=htmlnew
  88. time.sleep(600)
  89. # time.sleep(3600)

comments powered by Disqus