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..31e1b88 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,29 @@ 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) + 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