Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
API Twitch updated to helix and proxy list text add
  • Loading branch information
giovannidias1 committed Feb 26, 2020
1 parent d3b7fcb commit 2f121c5
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 15 deletions.
Empty file added proxies/__init__.py
Empty file.
20 changes: 20 additions & 0 deletions proxies/proxy_list.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
1.0.128.18:8080
1.0.179.252:8080
1.0.190.245:8080
1.10.135.10:8080
1.10.136.240:8080
1.10.137.153:8080
1.10.187.149:44976
1.10.188.203:45476
1.10.141.220:31670
1.10.185.8:42106
1.10.186.141:47331
1.10.186.15:61641
1.10.186.153:32731
1.10.186.167:51907
1.10.186.180:46096
1.10.186.210:53777
1.10.186.219:58989
1.10.186.240:52005
1.10.186.93:53711
1.10.187.13:51064
33 changes: 18 additions & 15 deletions twitch-viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@
import argparse
import logging
import os
import pwd
from lxml.html import fromstring
from datetime import datetime, timedelta
from datetime import date

def get_username():
return pwd.getpwuid( os.getuid() )[ 0 ]
proxies_file = "proxies/proxy_list.txt"

def get_channel(args):
global user
Expand All @@ -31,7 +29,7 @@ def get_channel(args):
processes = []

def get_proxies():
url = 'https://free-proxy-list.net/uk-proxy.html'
url = 'https://free-proxy-list.net/'
response = requests.get(url)
parser = fromstring(response.text)
proxies = set()
Expand All @@ -42,7 +40,11 @@ def get_proxies():
proxies.add(proxy)
#Check if Proxies are empty
if not proxies:
proxies = ['46.101.1.221:80', '68.183.220.18:80', '206.189.205.65:80']
try:
proxies = [line.rstrip("\n") for line in open(proxies_file)]
except IOError as e:
print("An error has occurred while trying to read the list of proxies: %s" % e.strerror)
sys.exit(1)
return proxies

def get_url():
Expand Down Expand Up @@ -118,23 +120,24 @@ def prepare_processes():
print('')

# THis Section is for logging and checking view count
def get_id_for_user(user):
headers = {'Client-ID': clientid, 'Accept': "application/vnd.twitchtv.v5+json"}
url = "https://api.twitch.tv/kraken/users?login=" + user
def get_id_for_user(user, clientid):
headers = {'Client-ID': clientid}
url = "https://api.twitch.tv/helix/users?login=" + user
r = requests.get(url, headers=headers)
if r.status_code != 200:
raise Exception("Could not get user ID calling URL {0} with headers {1} - HTTP {2} - {3}".format(url, headers, r.status_code, r.content))
res = r.json()
user_id = res['users'][0]["_id"]
user_id = res["data"][0]["id"]
print("Found id:" + user_id)
return user_id

def get_viewers(clientid, user):
user_id = get_id_for_user(user)
user_id = get_id_for_user(user, clientid)
headers = {'Client-ID': clientid, 'Accept': 'application/vnd.twitchtv.v5+json'}
url = "https://api.twitch.tv/kraken/streams/"+user_id+"?client_id="+clientid
# print(url)
print(url)

r = requests.get(url)
r = requests.get(url, headers=headers)
if r.status_code != 200:
raise Exception("API returned {0} : {1}".format(r.status_code, r.content))
infos = r.json()
Expand All @@ -152,9 +155,9 @@ def get_viewers(clientid, user):
stream_results['Viewers'] = viewers
results = {'online':True,'title':title,'viewers':viewers}

results['time'] = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
results['time'] = date.today().strftime('%Y-%m-%d %H:%M:%S')
results['stream'] = user
return stream_results
return results
# End Logging

if __name__ == "__main__":
Expand Down

0 comments on commit 2f121c5

Please sign in to comment.