Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- from lxml import html
- import re
- import time
- import os
- import getpass
- USERNAME = input('Username: ')
- PASSWORD = getpass.getpass('Password: ')
- LOGIN_URL = "https://www.simpleplanes.com/Account/LogIn"
- URL = "https://www.simpleplanes.com"
- global notif0
- global notif1
- notif0 = 0
- notif1 = 0
- def main():
- global notif0
- global notif1
- session_requests = requests.session()
- result = session_requests.get(LOGIN_URL)
- tree = html.fromstring(result.text)
- authenticity_token = list(set(tree.xpath("//input[@name='__RequestVerificationToken']/@value")))[0]
- payload = {
- "UserName": USERNAME,
- "Password": PASSWORD,
- "__RequestVerificationToken": authenticity_token
- }
- result = session_requests.post(LOGIN_URL, data = payload, headers = dict(referer = LOGIN_URL))
- result = session_requests.get(URL)
- data = result.text
- notif = re.search('<span class="label label-danger">(.*) New</span>', data)
- if notif is None:
- notif0 = 0
- else:
- notif0 = int(notif.group(1))
- print('Current notifications: ' + str(notif0))
- print('Last notifications: ' + str(notif1))
- if (notif0 > notif1):
- os.system('notify-send -i /home/derek/notify.png "SimplePlanes" "You have ' + str(notif0) + ' new notifications."')
- #os.system('notify-send test')
- print('Notification sent')
- notif1 = notif0
- return 1
- while 1:
- try:
- main()
- except Exception:
- print('Could not connect to the server')
- print('-----')
- time.sleep(30)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement