Advertisement
Guest User

Untitled

a guest
Sep 8th, 2018
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.58 KB | None | 0 0
  1. import requests
  2. from lxml import html
  3. import re
  4. import time
  5. import os
  6. import getpass
  7.  
  8. USERNAME = input('Username: ')
  9. PASSWORD = getpass.getpass('Password: ')
  10.  
  11. LOGIN_URL = "https://www.simpleplanes.com/Account/LogIn"
  12. URL = "https://www.simpleplanes.com"
  13. global notif0
  14. global notif1
  15. notif0 = 0
  16. notif1 = 0
  17.  
  18. def main():
  19.     global notif0
  20.     global notif1
  21.     session_requests = requests.session()
  22.  
  23.     result = session_requests.get(LOGIN_URL)
  24.     tree = html.fromstring(result.text)
  25.     authenticity_token = list(set(tree.xpath("//input[@name='__RequestVerificationToken']/@value")))[0]
  26.  
  27.     payload = {
  28.         "UserName": USERNAME,
  29.         "Password": PASSWORD,
  30.         "__RequestVerificationToken": authenticity_token
  31.     }
  32.  
  33.     result = session_requests.post(LOGIN_URL, data = payload, headers = dict(referer = LOGIN_URL))
  34.  
  35.     result = session_requests.get(URL)
  36.     data = result.text
  37.     notif = re.search('<span class="label label-danger">(.*) New</span>', data)
  38.  
  39.     if notif is None:
  40.         notif0 = 0
  41.     else:
  42.         notif0 = int(notif.group(1))
  43.  
  44.     print('Current notifications: ' + str(notif0))
  45.     print('Last notifications:    ' + str(notif1))
  46.  
  47.     if (notif0 > notif1):
  48.         os.system('notify-send -i /home/derek/notify.png "SimplePlanes" "You have ' + str(notif0) + ' new notifications."')
  49.         #os.system('notify-send test')
  50.         print('Notification sent')
  51.    
  52.     notif1 = notif0
  53.  
  54.     return 1
  55.  
  56. while 1:
  57.     try:
  58.         main()
  59.     except Exception:
  60.         print('Could not connect to the server')
  61.     print('-----')
  62.     time.sleep(30)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement