gur111

Grades Watch

Sep 1st, 2020 (edited)
366
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.12 KB | None | 0 0
  1. import requests as r
  2. import time
  3. import winsound
  4.  
  5. USER = YOUR_USERNAME_HERE
  6. PASS = YOUR_PASSWORD_HERE
  7.  
  8. s = r.Session()
  9.  
  10. last_th = -1
  11.  
  12. while True:
  13.     res = s.post('https://grades.cs.technion.ac.il',
  14.                  {'ID': USER, 'Password':PASS, 'submit': 'proceed', 'Page': 'grades.html', 'Login': 1})
  15.     if '=xxx' in res.headers.get('Set-Cookie', ''):
  16.         raise Exception('Failed to login')
  17.     res = s.post('https://grades.cs.technion.ac.il',
  18.                  {'COOKIE': res.cookies['LastGradesCookie'], 'RecreatePath': 1, 'SEM': '201902'})
  19.  
  20.     res_str = res.text.lower()
  21.  
  22.     if 'finala' not in res_str:
  23.         raise Exception('Not in grades page')
  24.  
  25.     if last_th == -1:
  26.         last_th = res_str.count("<th>")
  27.         continue
  28.     elif res_str.count('<th>') != last_th or 'proj' in res_str:
  29.         print('Hurray, you have new grades!!!')
  30.         duration = 300  # milliseconds
  31.         freq = 2000  # Hz
  32.         for i in range(100):
  33.             winsound.Beep(freq, duration)
  34.             time.sleep(duration/3000)
  35.         break
  36.     else:
  37.         print('No grades yet. Sorry :-(')
  38.  
  39.     time.sleep(600)
Add Comment
Please, Sign In to add comment