irgendwas

wot casting updates.py

Apr 24th, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.38 KB | None | 0 0
  1. #!python3
  2. import httplib2
  3. import bs4
  4. import os
  5. import sys
  6.  
  7.  
  8. URL = 'https://kvhcasting.com/'  # hendry's site
  9. TITLE = 'WOT'  # title for notifications
  10.  
  11.  
  12. def notify(preset, text):
  13.     """notification function for visual feedback
  14.     i made this for awesomewm under gnu/linux
  15.     replace with call to your OS' notificatoon lib"""
  16.     os.system('''echo 'local naughty = require("naughty"); naughty.notify({preset=naughty.config.presets.'''\
  17.               + preset +\
  18.               ''', title="'''\
  19.               + TITLE +\
  20.               '''", text="'''\
  21.               + text +\
  22.               '''"})'| awesome-client''')
  23.  
  24. ### this is where the magic begins, DO NOT change this
  25. h = httplib2.Http('.cache')
  26. res, content = h.request(URL, 'GET')
  27. content_parsed = bs4.BeautifulSoup(content, features="html.parser")
  28. cards = content_parsed.findAll(attrs={'data-ux': 'ContentCard'})
  29. the_card = None
  30. for i in cards:
  31.     if i.findChild(text='THE WHEEL OF TIME'):
  32.         the_card = i
  33.         break
  34. if not the_card:  # no WoT card
  35.     notify('info', 'card not found')
  36.     sys.exit(1)
  37.  
  38. link = the_card.findChild(name='a')
  39. if link:
  40.     notify('critical', f'Casting is open: {link["href"]}')  # submission mail address
  41.  
  42. card_cont = the_card.findChild(attrs={'data-ux': 'ContentCard'}).findChild(name='p')
  43. if card_cont != 'UPDATES COMING SOON':
  44.     notify('critical', f'update:\n{card_cont}')  # updates?
Advertisement
Add Comment
Please, Sign In to add comment