Guest User

Untitled

a guest
Jan 24th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. import requests
  2. import time
  3. import self
  4.  
  5. client_id = "jzkbprff40iqj646a697cyrvl0zt2m6"
  6. def check_user():
  7. # 0: online,
  8. # 1: offline,
  9. # 2: not found,
  10. # 3: error
  11. url = 'https://api.twitch.tv/kraken/streams/bratishkinoff'
  12. info = None
  13. status = 3
  14. try:
  15. r = requests.get(url, headers = {"Client-ID" : client_id}, timeout = 15)
  16. r.raise_for_status()
  17. info = r.json()
  18. if info['stream'] == None:
  19. status = 1
  20. else:
  21. status = 0
  22. except requests.exceptions.RequestException as e:
  23. if e.response:
  24. if e.response.reason == 'Not Found' or e.response.reason == 'Unprocessable Entity':
  25. status = 2
  26.  
  27. return status, info
  28.  
  29. def loopcheck():
  30. while True:
  31. status, info = self.check_user()
  32. if status == 0:
  33. print('STREAM IS LIVE!')
  34. time.sleep(refresh)
Add Comment
Please, Sign In to add comment