Skip to content

Instantly share code, notes, and snippets.

@BtbN
Created January 21, 2018 20:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BtbN/ad8779b5749765f1c655869b41db0b6e to your computer and use it in GitHub Desktop.
Save BtbN/ad8779b5749765f1c655869b41db0b6e to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import os
import sys
import time
import signal
from twitch import TwitchClient
os.chdir(os.path.dirname(os.path.abspath(__file__)))
class AlarmException(Exception):
pass
def alarm_handler(signum, frame):
raise AlarmException
signal.signal(signal.SIGALRM, alarm_handler)
twc = TwitchClient(client_id="...", oauth_token="xxx") # <- Client ID and Channel Owners oauth token with needed permissions here
while True:
pipe_name = 'sub_pipe'
if not os.path.exists(pipe_name):
os.mkfifo(pipe_name)
time.sleep(1)
signal.alarm(300)
try:
pipe_out = open(pipe_name, 'w')
except AlarmException:
continue
except KeyboardInterrupt:
sys.exit(0)
signal.alarm(0)
try:
max_len=100
offset=0
total_count=0
sub_points=0
while True:
res = twc.channels.get_subscribers('65444226', limit=max_len, offset=offset) # <- Put Channel ID of channel in question here
if not res:
break
offset = offset + max_len
for sub in res:
if sub['user']['name'] in ['sayvitv', 'sayvibot']: # <- exclude certain people, like free-subbed-bots and channel owner
continue
total_count = total_count + 1
if int(sub['sub_plan']) == 2000:
sub_points += 2
elif int(sub['sub_plan']) == 3000:
sub_points += 6
else:
sub_points += 1
if len(res) < max_len:
break
print("%s Subs and %s" % (total_count, sub_points), file=pipe_out)
except:
print("Error enumerating subscribers.", file=pipe_out)
finally:
pipe_out.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment