Last active
August 28, 2015 03:20
-
-
Save ask-compu/272f6a6614984c890e20 to your computer and use it in GitHub Desktop.
timer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class EpReminder | |
def __init__(self, phenny): | |
self.phenny = phenny | |
_thread.start_new_thread(cycle_to_next_ep()) | |
def cycle_to_next_ep(self): | |
prev_j = {} | |
while True: | |
j = get_ep_info | |
if j is prev_j: | |
sleep(1800) | |
else: | |
try: | |
epname = jsonstring['episodes'][0]['name'] | |
eps = str(jsonstring['episodes'][0]['season']) | |
epe = str(jsonstring['episodes'][0]['episode']) | |
etimeun = jsonstring['episodes'][0]['air_date'] | |
movie = jsonstring['episodes'][0]['is_movie'] | |
except: | |
try: | |
epname = jsonstring['episodes']['name'] | |
eps = str(jsonstring['episodes']['season']) | |
epe = str(jsonstring['episodes']['episode']) | |
etimeun = jsonstring['episodes']['air_date'] | |
movie = jsonstring['episodes']['is_movie'] | |
except: | |
epname = jsonstring['episode']['name'] | |
eps = str(jsonstring['episode']['season']) | |
epe = str(jsonstring['episode']['episode']) | |
etimeun = jsonstring['episode']['air_date'] | |
movie = jsonstring['episode']['is_movie'] | |
start_ep_timer(j['air_date']) | |
prev_j = j | |
sleep(1800) | |
def start_ep_timer(self, eptimein): | |
#set reminderText to something | |
eptime_first = eptimein - 3600 #First reminder, 1 hour before airdate | |
eptime_second = eptimein - 1800 #Second reminder, 30 minutes before airdate | |
eptime_urgent = eptimein | |
while eptimemin > (cur_time = time.time()): | |
time.sleep(600) | |
if cur_time >= eptimemin: | |
send_to_channels(phenny.config.episode_reminder, reminderText) | |
elif cur_time >= eptimemin: | |
send_to_channels(phenny.config.episode_reminder, reminderText) | |
send_to_channels(phenny.config.episode_reminder, reminderText) | |
def get_ep_info(self): | |
uri = 'http://ponyapi.apps.xeserv.us/newest' | |
rec_bytes = web.get(uri) | |
return json.loads(rec_bytes) | |
def send_to_channels(self, channels, msgtext): | |
for c in channels: | |
self.phenny.msg(c, msgtext) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment