discord-guild-notifications/streams.py

35 lines
828 B
Python
Raw Normal View History

2017-07-10 08:58:51 +00:00
#! /usr/bin/python3
2017-12-13 11:37:31 +00:00
"""
Streams Cron
"""
2017-07-10 08:58:51 +00:00
import time
import sys
2017-12-13 11:37:31 +00:00
import redis
import requests
2017-07-10 08:58:51 +00:00
import webhook
import conf
now = time.time()
wh = webhook.Webhook(conf.url_discord_webhook_news)
2017-07-10 08:58:51 +00:00
r = redis.StrictRedis(host='localhost', charset="utf-8", decode_responses=True, db=1)
2017-07-10 08:58:51 +00:00
twitch_api = "https://api.twitch.tv/kraken/streams/followed?oauth_token={0}".format(conf.twitch_token)
r.zremrangebyscore("bot:twitch", "-inf", now-(60*15))
t = requests.get(url=twitch_api).json()
if "streams" not in t:
2017-12-13 11:37:31 +00:00
print(t)
sys.exit()
2017-07-10 08:58:51 +00:00
for stream in t["streams"]:
2017-12-13 11:37:31 +00:00
if r.zadd("bot:twitch", now, stream["channel"]["name"]) == 0:
continue
2017-07-10 08:58:51 +00:00
2017-12-13 11:37:31 +00:00
wh.send("{3} **{0}** está stremeando: [{2}](<{1}>)".format(stream["channel"]["name"], stream["channel"]["url"], stream["channel"]["status"], conf.icon_twitch))
time.sleep(2)