From 5e98bff65bd0699267e02b5a7361f06f8d2a13b5 Mon Sep 17 00:00:00 2001 From: ueg1990 Date: Mon, 17 Mar 2014 18:18:28 -0400 Subject: [PATCH 1/2] Added function that returns list of tv shows on a given day --- APIExample.py | 7 +++++-- eztv_api.py | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/APIExample.py b/APIExample.py index de9c56c..48a584f 100644 --- a/APIExample.py +++ b/APIExample.py @@ -2,7 +2,7 @@ test_api = EztvAPI().tv_show('Game Of Thrones') -# get all the seasons from Game Of Thrones +#get all the seasons from Game Of Thrones seasons = test_api.seasons() for season in seasons: for episode in seasons[season]: @@ -15,5 +15,8 @@ # will print the magnet link for all episodes print episodes[episode] -# specific episode +#specific episode print test_api.episode(3, 10) + +# get upcoming shows of given day +print test_api.get_upcoming_tvshows_on_given_day('SUNDAY') diff --git a/eztv_api.py b/eztv_api.py index 0bbaf5f..0e0add0 100644 --- a/eztv_api.py +++ b/eztv_api.py @@ -8,6 +8,7 @@ from bs4 import BeautifulSoup import requests import re +from datetime import datetime URL = "http://eztv.it" @@ -40,6 +41,10 @@ class EpisodeNotFound(EztvException): """ Episode Not Found Exception """ +class DayNotFound(EztvException): + """ + Episode Not Found Exception + """ class EztvAPI(object): """ @@ -197,3 +202,30 @@ def update(self): episodes, magnet. """ return self.load_tv_show_data() + + def get_upcoming_tvshows_on_given_day(self, day=None): + result = {} + days_of_week = ['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday'] + current_day_index = datetime.today().weekday() + if day == None: + day = days_of_week[current_day_index] + else: + day = day.lower() + if days_of_week.index(day) == current_day_index or days_of_week.index(day) == (current_day_index - 1) % 7 or days_of_week.index(day) == (current_day_index + 1) % 7 : + req = requests.get(URL + '/calendar/', timeout=5) + soup = BeautifulSoup(req.content) + index = current_day_index - days_of_week.index(day) + table = soup.find_all('table')[0] + days_in_table = table.find_all('td', {"class": "forum_thread_header"}) + for index, value in enumerate(days_in_table): + if day.capitalize() == value.text.strip(): + listofShows = table.find_all('table', {"class" : "forum_header_border"})[index] + for i in listofShows.find_all('tr')[1].find_all('td', {"class" : "forum_thread_post"}): + if i.find('a', {"class" : "thread_link"}): + result[i.text.strip()] = URL + i.find('a').get('href') + break + else: + raise DayNotFound( + 'The day %s is not within one day of the current day, %s.' % (day.capitalize(), days_of_week[current_day_index].capitalize()), None) + + return result \ No newline at end of file From 9896b5e0cd729946bbc4278b4cc02286cd7c35bf Mon Sep 17 00:00:00 2001 From: ueg1990 Date: Mon, 17 Mar 2014 23:20:55 -0400 Subject: [PATCH 2/2] Added function that returns list of tv shows on a given day --- eztv_api.py | 1 - 1 file changed, 1 deletion(-) diff --git a/eztv_api.py b/eztv_api.py index 0e0add0..31e1b88 100644 --- a/eztv_api.py +++ b/eztv_api.py @@ -214,7 +214,6 @@ def get_upcoming_tvshows_on_given_day(self, day=None): if days_of_week.index(day) == current_day_index or days_of_week.index(day) == (current_day_index - 1) % 7 or days_of_week.index(day) == (current_day_index + 1) % 7 : req = requests.get(URL + '/calendar/', timeout=5) soup = BeautifulSoup(req.content) - index = current_day_index - days_of_week.index(day) table = soup.find_all('table')[0] days_in_table = table.find_all('td', {"class": "forum_thread_header"}) for index, value in enumerate(days_in_table):