Guest User

Terry Davis Live-Stream Notifier v6.03

a guest
Oct 6th, 2017
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.19 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # Terry Davis Live-Stream Notifier v6.03
  3. # Requires installing the "Requests" Python library (pip install requests)
  4. # Compatibile with Pyhton 2, Python 3, Windows, Mac, and Linux
  5.  
  6. import requests
  7. import platform
  8. from time import sleep
  9. from os import system
  10. from sys import stdout
  11.  
  12. def notify(opsys, title, msg, audiomsg):
  13.     print("\n" + msg)
  14.     if opsys == "Linux":
  15.         system('notify-send "{}" "{}"'.format(title, msg))
  16.         system('spd-say " {} "'.format(audiomsg))
  17.     elif opsys == "Darwin":
  18.         system('osascript -e "display notification "{}" with title "{}"'.format(msg, title))
  19.         system('system("say {}")'.format(audiomsg))
  20.     elif opsys == "Windows":
  21.         print('\a')
  22.     else:
  23.         print('\a')
  24.  
  25. def isstreaming():
  26.     streaming, offline, failed = True, False, False
  27.     title = "Alert"
  28.     msg = "Terry Davis is live-streaming."
  29.     audiomsg = "Hey faggot, Terry Davis is live-streaming."
  30.     notify(opsys, title, msg, audiomsg)
  31.     return streaming, offline, failed
  32.  
  33. def isoffline():
  34.     offline, streaming, failed = True, False, False
  35.     title = "Alert"
  36.     msg = "Terry Davis is offline."
  37.     audiomsg = msg
  38.     notify(opsys, title, msg, audiomsg)
  39.     return offline, streaming, failed
  40.  
  41. def isfail():
  42.     failed, streaming, offline = True, False, False
  43.     title = "Alert"
  44.     msg = "Failed to connect to templeos.org."
  45.     audiomsg = "Failed to connect to temple oh ess dot org."
  46.     notify(opsys, title, msg, audiomsg)
  47.     return failed, streaming, offline
  48.  
  49. opsys = platform.system()
  50. streaming, offline, failed = False, False, False
  51.  
  52. while True:
  53.     try:
  54.         res = requests.head('http://www.templeos.org/hls/templeos.m3u8', timeout=3)
  55.         if res.reason == "OK":
  56.             if streaming == False:
  57.                 streaming, offline, failed = isstreaming()
  58.             else: pass
  59.         elif res.reason != "OK":
  60.             if offline == False:
  61.                 offline, streaming, failed = isoffline()
  62.             else: pass
  63.     except:
  64.         if failed == False:
  65.             failed, streaming, offline = isfail()
  66.         else:
  67.             pass
  68.     stdout.write('.')
  69.     for i in range(30): sleep(1)
Add Comment
Please, Sign In to add comment