From 529e5980e47e481cf46ebc39a9e5bedb3282f0aa Mon Sep 17 00:00:00 2001 From: Date: Sun, 8 Oct 2017 23:12:12 +0300 Subject: [PATCH] Initial commit with framework class for twitch-requests --- .gitignore | 3 +++ src/main.py | 14 ++++++++++++++ src/twitch.py | 12 ++++++++++++ 3 files changed, 29 insertions(+) create mode 100644 .gitignore create mode 100755 src/main.py create mode 100644 src/twitch.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..91a03f3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +src/__pycache__ +*.swp +src/.token diff --git a/src/main.py b/src/main.py new file mode 100755 index 0000000..e5d03ce --- /dev/null +++ b/src/main.py @@ -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() diff --git a/src/twitch.py b/src/twitch.py new file mode 100644 index 0000000..b860f98 --- /dev/null +++ b/src/twitch.py @@ -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