Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions APIExample.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand All @@ -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')
31 changes: 31 additions & 0 deletions eztv_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from bs4 import BeautifulSoup
import requests
import re
from datetime import datetime

URL = "http://eztv.it"

Expand Down Expand Up @@ -40,6 +41,10 @@ class EpisodeNotFound(EztvException):
"""
Episode Not Found Exception
"""
class DayNotFound(EztvException):
"""
Episode Not Found Exception
"""

class EztvAPI(object):
"""
Expand Down Expand Up @@ -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