Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- import time
- import self
- client_id = "jzkbprff40iqj646a697cyrvl0zt2m6"
- def check_user():
- # 0: online,
- # 1: offline,
- # 2: not found,
- # 3: error
- url = 'https://api.twitch.tv/kraken/streams/bratishkinoff'
- info = None
- status = 3
- try:
- r = requests.get(url, headers = {"Client-ID" : client_id}, timeout = 15)
- r.raise_for_status()
- info = r.json()
- if info['stream'] == None:
- status = 1
- else:
- status = 0
- except requests.exceptions.RequestException as e:
- if e.response:
- if e.response.reason == 'Not Found' or e.response.reason == 'Unprocessable Entity':
- status = 2
- return status, info
- def loopcheck():
- while True:
- status, info = self.check_user()
- if status == 0:
- print('STREAM IS LIVE!')
- time.sleep(refresh)
Add Comment
Please, Sign In to add comment