Initial commit with framework class for twitch-requests

This commit is contained in:
2017-10-08 23:12:12 +03:00
parent 6c6585226e
commit 529e5980e4
3 changed files with 29 additions and 0 deletions

3
.gitignore vendored Normal file
View file

@ -0,0 +1,3 @@
src/__pycache__
*.swp
src/.token

14
src/main.py Executable file
View file

@ -0,0 +1,14 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from twitch import TwitchClient
def main():
with open('.token', 'r') as reader:
twitch_token = reader.read().strip()
client = TwitchClient(twitch_token)
print(client.raw_query('streams?first=20'))
if __name__ == '__main__':
main()

12
src/twitch.py Normal file
View file

@ -0,0 +1,12 @@
import requests
class TwitchClient:
def __init__(self, token):
self.token = token
self.header = {'Client-ID': self.token}
self.urlbase = 'https://api.twitch.tv/helix/'
def raw_query(self, q):
r = requests.get(self.urlbase+q, headers=self.header)
return r.text