Guest User

Terry Davis Live-Stream Notifier v6.0

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