mirror of
https://github.com/SickGear/SickGear.git
synced 2025-01-07 10:33:38 +00:00
Merge pull request #57 from JackDandy/feature/FixCalendarThisWeek
Feature/fix calendar this week
This commit is contained in:
commit
ac1cf1879a
2 changed files with 93 additions and 42 deletions
|
@ -725,17 +725,22 @@ class CMD_ComingEpisodes(ApiCall):
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
""" display the coming episodes """
|
""" display the coming episodes """
|
||||||
today = datetime.date.today().toordinal()
|
today_dt = datetime.date.today()
|
||||||
next_week = (datetime.date.today() + datetime.timedelta(days=7)).toordinal()
|
today = today_dt.toordinal()
|
||||||
recently = (datetime.date.today() - datetime.timedelta(days=sickbeard.COMING_EPS_MISSED_RANGE)).toordinal()
|
yesterday_dt = today_dt - datetime.timedelta(days=1)
|
||||||
|
yesterday = yesterday_dt.toordinal()
|
||||||
|
tomorrow = (datetime.date.today() + datetime.timedelta(days=1)).toordinal()
|
||||||
|
next_week_dt = (datetime.date.today() + datetime.timedelta(days=7))
|
||||||
|
next_week = (next_week_dt + datetime.timedelta(days=1)).toordinal()
|
||||||
|
recently = (yesterday_dt - datetime.timedelta(days=sickbeard.COMING_EPS_MISSED_RANGE)).toordinal()
|
||||||
|
|
||||||
done_show_list = []
|
done_show_list = []
|
||||||
qualList = Quality.DOWNLOADED + Quality.SNATCHED + [ARCHIVED, IGNORED]
|
qualList = Quality.DOWNLOADED + Quality.SNATCHED + [ARCHIVED, IGNORED]
|
||||||
|
|
||||||
myDB = db.DBConnection(row_type="dict")
|
myDB = db.DBConnection()
|
||||||
sql_results = myDB.select(
|
sql_results = myDB.select(
|
||||||
"SELECT airdate, airs, episode, name AS 'ep_name', description AS 'ep_plot', network, season, showid AS 'indexerid', show_name, tv_shows.quality AS quality, tv_shows.status AS 'show_status', tv_shows.paused AS 'paused' FROM tv_episodes, tv_shows WHERE season != 0 AND airdate >= ? AND airdate < ? AND tv_shows.indexer_id = tv_episodes.showid AND tv_episodes.status NOT IN (" + ','.join(
|
"SELECT airdate, airs, episode, name AS 'ep_name', description AS 'ep_plot', network, season, showid AS 'indexerid', show_name, tv_shows.quality AS quality, tv_shows.status AS 'show_status', tv_shows.paused AS 'paused' FROM tv_episodes, tv_shows WHERE season != 0 AND airdate >= ? AND airdate <= ? AND tv_shows.indexer_id = tv_episodes.showid AND tv_episodes.status NOT IN (" + ','.join(
|
||||||
['?'] * len(qualList)) + ")", [today, next_week] + qualList)
|
['?'] * len(qualList)) + ")", [yesterday, next_week] + qualList)
|
||||||
for cur_result in sql_results:
|
for cur_result in sql_results:
|
||||||
done_show_list.append(int(cur_result["indexerid"]))
|
done_show_list.append(int(cur_result["indexerid"]))
|
||||||
|
|
||||||
|
@ -748,17 +753,42 @@ class CMD_ComingEpisodes(ApiCall):
|
||||||
sql_results += more_sql_results
|
sql_results += more_sql_results
|
||||||
|
|
||||||
more_sql_results = myDB.select(
|
more_sql_results = myDB.select(
|
||||||
"SELECT airdate, airs, episode, name AS 'ep_name', description AS 'ep_plot', network, season, showid AS 'indexerid', show_name, tv_shows.quality AS quality, tv_shows.status AS 'show_status', tv_shows.paused AS 'paused' FROM tv_episodes, tv_shows WHERE season != 0 AND tv_shows.indexer_id = tv_episodes.showid AND airdate < ? AND airdate >= ? AND tv_episodes.status = ? AND tv_episodes.status NOT IN (" + ','.join(
|
"SELECT airdate, airs, episode, name AS 'ep_name', description AS 'ep_plot', network, season, showid AS 'indexerid', show_name, tv_shows.quality AS quality, tv_shows.status AS 'show_status', tv_shows.paused AS 'paused' FROM tv_episodes, tv_shows WHERE season != 0 AND tv_shows.indexer_id = tv_episodes.showid AND airdate <= ? AND airdate >= ? AND tv_episodes.status = ? AND tv_episodes.status NOT IN (" + ','.join(
|
||||||
['?'] * len(qualList)) + ")", [today, recently, WANTED] + qualList)
|
['?'] * len(qualList)) + ")", [tomorrow, recently, WANTED] + qualList)
|
||||||
sql_results += more_sql_results
|
sql_results += more_sql_results
|
||||||
|
|
||||||
# sort by air date
|
sql_results = list(set(sql_results))
|
||||||
|
|
||||||
|
# make a dict out of the sql results
|
||||||
|
sql_results = [dict(row) for row in sql_results]
|
||||||
|
|
||||||
|
# multi dimension sort
|
||||||
sorts = {
|
sorts = {
|
||||||
'date': (lambda x, y: cmp(int(x["airdate"]), int(y["airdate"]))),
|
'date': (lambda a, b: cmp(
|
||||||
'show': (lambda a, b: cmp(a["show_name"], b["show_name"])),
|
(a['parsed_datetime'],
|
||||||
'network': (lambda a, b: cmp(a["network"], b["network"])),
|
(a['show_name'], re.sub(r'(?i)^(The|A|An)\s', '', a['show_name']))[not sickbeard.SORT_ARTICLE],
|
||||||
|
a['season'], a['episode']),
|
||||||
|
(b['parsed_datetime'],
|
||||||
|
(b['show_name'], re.sub(r'(?i)^(The|A|An)\s', '', b['show_name']))[not sickbeard.SORT_ARTICLE],
|
||||||
|
b['season'], b['episode']))),
|
||||||
|
'show': (lambda a, b: cmp(
|
||||||
|
((a['show_name'], re.sub(r'(?i)^(The|A|An)\s', '', a['show_name']))[not sickbeard.SORT_ARTICLE],
|
||||||
|
a['parsed_datetime'], a['season'], a['episode']),
|
||||||
|
((b['show_name'], re.sub(r'(?i)^(The|A|An)\s', '', b['show_name']))[not sickbeard.SORT_ARTICLE],
|
||||||
|
b['parsed_datetime'], b['season'], b['episode']))),
|
||||||
|
'network': (lambda a, b: cmp(
|
||||||
|
(a['network'], a['parsed_datetime'],
|
||||||
|
(a['show_name'], re.sub(r'(?i)^(The|A|An)\s', '', a['show_name']))[not sickbeard.SORT_ARTICLE],
|
||||||
|
a['season'], a['episode']),
|
||||||
|
(b['network'], b['parsed_datetime'],
|
||||||
|
(b['show_name'], re.sub(r'(?i)^(The|A|An)\s', '', b['show_name']))[not sickbeard.SORT_ARTICLE],
|
||||||
|
b['season'], b['episode'])))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# add parsed_datetime to the dict
|
||||||
|
for index, item in enumerate(sql_results):
|
||||||
|
sql_results[index]['parsed_datetime'] = network_timezones.parse_date_time(item['airdate'], item['airs'], item['network'])
|
||||||
|
|
||||||
sql_results.sort(sorts[self.sort])
|
sql_results.sort(sorts[self.sort])
|
||||||
finalEpResults = {}
|
finalEpResults = {}
|
||||||
|
|
||||||
|
@ -777,9 +807,7 @@ class CMD_ComingEpisodes(ApiCall):
|
||||||
if ep["paused"] and not self.paused:
|
if ep["paused"] and not self.paused:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
ep['airs'] = str(ep['airs']).replace('am', ' AM').replace('pm', ' PM').replace(' ', ' ')
|
ep['airdate'] = int(ep["airdate"])
|
||||||
dtEpisodeAirs = sbdatetime.sbdatetime.convert_to_setting(network_timezones.parse_date_time(int(ep['airdate']), ep['airs'], ep['network']))
|
|
||||||
ep['airdate'] = dtEpisodeAirs.toordinal()
|
|
||||||
|
|
||||||
status = "soon"
|
status = "soon"
|
||||||
if ep["airdate"] < today:
|
if ep["airdate"] < today:
|
||||||
|
@ -801,12 +829,13 @@ class CMD_ComingEpisodes(ApiCall):
|
||||||
|
|
||||||
ep["quality"] = _get_quality_string(ep["quality"])
|
ep["quality"] = _get_quality_string(ep["quality"])
|
||||||
# clean up tvdb horrible airs field
|
# clean up tvdb horrible airs field
|
||||||
ep['airs'] = sbdatetime.sbdatetime.sbftime(dtEpisodeAirs, t_preset=timeFormat).lstrip('0').replace(' 0', ' ')
|
ep['airs'] = str(ep['airs']).replace('am', ' AM').replace('pm', ' PM').replace(' ', ' ')
|
||||||
# start day of the week on 1 (monday)
|
# start day of the week on 1 (monday)
|
||||||
ep['weekday'] = 1 + datetime.date.fromordinal(dtEpisodeAirs.toordinal()).weekday()
|
ep['weekday'] = 1 + datetime.date.fromordinal(ep['airdate']).weekday()
|
||||||
# Add tvdbid for backward compability
|
# Add tvdbid for backward compability
|
||||||
ep["tvdbid"] = ep['indexerid']
|
ep["tvdbid"] = ep['indexerid']
|
||||||
ep['airdate'] = sbdatetime.sbdatetime.sbfdate(dtEpisodeAirs, d_preset=dateFormat)
|
ep['airdate'] = sbdatetime.sbdatetime.sbfdate(datetime.date.fromordinal(ep['airdate']), d_preset=dateFormat)
|
||||||
|
ep['parsed_datetime'] = sbdatetime.sbdatetime.sbfdatetime(ep['parsed_datetime'], d_preset=dateFormat, t_preset='%H:%M %z')
|
||||||
|
|
||||||
# TODO: check if this obsolete
|
# TODO: check if this obsolete
|
||||||
if not status in finalEpResults:
|
if not status in finalEpResults:
|
||||||
|
|
|
@ -350,45 +350,67 @@ class MainHandler(RequestHandler):
|
||||||
redirect("/comingEpisodes/")
|
redirect("/comingEpisodes/")
|
||||||
|
|
||||||
def comingEpisodes(self, layout="None"):
|
def comingEpisodes(self, layout="None"):
|
||||||
|
""" display the coming episodes """
|
||||||
today1 = datetime.date.today() - datetime.timedelta(days=1)
|
today_dt = datetime.date.today()
|
||||||
today = today1.toordinal()
|
#today = today_dt.toordinal()
|
||||||
tommorrow = (datetime.date.today() + datetime.timedelta(days=1))
|
yesterday_dt = today_dt - datetime.timedelta(days=1)
|
||||||
next_week1 = (datetime.date.today() + datetime.timedelta(days=7))
|
yesterday = yesterday_dt.toordinal()
|
||||||
next_week = (next_week1 + datetime.timedelta(days=1)).toordinal()
|
tomorrow = (datetime.date.today() + datetime.timedelta(days=1)).toordinal()
|
||||||
recently = (today1 - datetime.timedelta(days=sickbeard.COMING_EPS_MISSED_RANGE)).toordinal()
|
next_week_dt = (datetime.date.today() + datetime.timedelta(days=7))
|
||||||
|
next_week = (next_week_dt + datetime.timedelta(days=1)).toordinal()
|
||||||
|
if not (layout and layout in ('calendar')) and not (sickbeard.COMING_EPS_LAYOUT and sickbeard.COMING_EPS_LAYOUT in ('calendar')):
|
||||||
|
recently = (yesterday_dt - datetime.timedelta(days=sickbeard.COMING_EPS_MISSED_RANGE)).toordinal()
|
||||||
|
else:
|
||||||
|
recently = yesterday
|
||||||
|
|
||||||
done_show_list = []
|
done_show_list = []
|
||||||
qualList = Quality.DOWNLOADED + Quality.SNATCHED + [ARCHIVED, IGNORED]
|
qualList = Quality.DOWNLOADED + Quality.SNATCHED + [ARCHIVED, IGNORED]
|
||||||
|
|
||||||
myDB = db.DBConnection()
|
myDB = db.DBConnection()
|
||||||
sql_results = myDB.select(
|
sql_results = myDB.select(
|
||||||
"SELECT *, tv_shows.status as show_status FROM tv_episodes, tv_shows WHERE season != 0 AND airdate >= ? AND airdate < ? AND tv_shows.indexer_id = tv_episodes.showid AND tv_episodes.status NOT IN (" + ','.join(
|
"SELECT *, tv_shows.status as show_status FROM tv_episodes, tv_shows WHERE season != 0 AND airdate >= ? AND airdate <= ? AND tv_shows.indexer_id = tv_episodes.showid AND tv_episodes.status NOT IN (" + ','.join(
|
||||||
['?'] * len(qualList)) + ")", [today, next_week] + qualList)
|
['?'] * len(qualList)) + ")", [yesterday, next_week] + qualList)
|
||||||
|
|
||||||
for cur_result in sql_results:
|
for cur_result in sql_results:
|
||||||
done_show_list.append(int(cur_result["showid"]))
|
done_show_list.append(int(cur_result["showid"]))
|
||||||
|
|
||||||
more_sql_results = myDB.select(
|
if not (layout and layout in ('calendar')) and not (sickbeard.COMING_EPS_LAYOUT and sickbeard.COMING_EPS_LAYOUT in ('calendar')):
|
||||||
"SELECT *, tv_shows.status as show_status FROM tv_episodes outer_eps, tv_shows WHERE season != 0 AND showid NOT IN (" + ','.join(
|
more_sql_results = myDB.select(
|
||||||
['?'] * len(
|
"SELECT *, tv_shows.status as show_status FROM tv_episodes outer_eps, tv_shows WHERE season != 0 AND showid NOT IN (" + ','.join(
|
||||||
done_show_list)) + ") AND tv_shows.indexer_id = outer_eps.showid AND airdate = (SELECT airdate FROM tv_episodes inner_eps WHERE inner_eps.season != 0 AND inner_eps.showid = outer_eps.showid AND inner_eps.airdate >= ? ORDER BY inner_eps.airdate ASC LIMIT 1) AND outer_eps.status NOT IN (" + ','.join(
|
['?'] * len(
|
||||||
['?'] * len(Quality.DOWNLOADED + Quality.SNATCHED)) + ")",
|
done_show_list)) + ") AND tv_shows.indexer_id = outer_eps.showid AND airdate = (SELECT airdate FROM tv_episodes inner_eps WHERE inner_eps.season != 0 AND inner_eps.showid = outer_eps.showid AND inner_eps.airdate >= ? ORDER BY inner_eps.airdate ASC LIMIT 1) AND outer_eps.status NOT IN (" + ','.join(
|
||||||
done_show_list + [next_week] + Quality.DOWNLOADED + Quality.SNATCHED)
|
['?'] * len(Quality.DOWNLOADED + Quality.SNATCHED)) + ")",
|
||||||
sql_results += more_sql_results
|
done_show_list + [next_week] + Quality.DOWNLOADED + Quality.SNATCHED)
|
||||||
|
sql_results += more_sql_results
|
||||||
|
|
||||||
more_sql_results = myDB.select(
|
more_sql_results = myDB.select(
|
||||||
"SELECT *, tv_shows.status as show_status FROM tv_episodes, tv_shows WHERE season != 0 AND tv_shows.indexer_id = tv_episodes.showid AND airdate < ? AND airdate >= ? AND tv_episodes.status = ? AND tv_episodes.status NOT IN (" + ','.join(
|
"SELECT *, tv_shows.status as show_status FROM tv_episodes, tv_shows WHERE season != 0 AND tv_shows.indexer_id = tv_episodes.showid AND airdate <= ? AND airdate >= ? AND tv_episodes.status = ? AND tv_episodes.status NOT IN (" + ','.join(
|
||||||
['?'] * len(qualList)) + ")", [tommorrow, recently, WANTED] + qualList)
|
['?'] * len(qualList)) + ")", [tomorrow, recently, WANTED] + qualList)
|
||||||
sql_results += more_sql_results
|
sql_results += more_sql_results
|
||||||
|
|
||||||
sql_results = list(set(sql_results))
|
sql_results = list(set(sql_results))
|
||||||
|
|
||||||
# sort by localtime
|
# multi dimension sort
|
||||||
sorts = {
|
sorts = {
|
||||||
'date': (lambda x, y: cmp(x["localtime"], y["localtime"])),
|
'date': (lambda a, b: cmp(
|
||||||
'show': (lambda a, b: cmp((a["show_name"], a["localtime"]), (b["show_name"], b["localtime"]))),
|
(a['localtime'],
|
||||||
'network': (lambda a, b: cmp((a["network"], a["localtime"]), (b["network"], b["localtime"]))),
|
(a['show_name'], re.sub(r'(?i)^(The|A|An)\s', '', a['show_name']))[not sickbeard.SORT_ARTICLE],
|
||||||
|
a['season'], a['episode']),
|
||||||
|
(b['localtime'],
|
||||||
|
(b['show_name'], re.sub(r'(?i)^(The|A|An)\s', '', b['show_name']))[not sickbeard.SORT_ARTICLE],
|
||||||
|
b['season'], b['episode']))),
|
||||||
|
'show': (lambda a, b: cmp(
|
||||||
|
((a['show_name'], re.sub(r'(?i)^(The|A|An)\s', '', a['show_name']))[not sickbeard.SORT_ARTICLE],
|
||||||
|
a['localtime'], a['season'], a['episode']),
|
||||||
|
((b['show_name'], re.sub(r'(?i)^(The|A|An)\s', '', b['show_name']))[not sickbeard.SORT_ARTICLE],
|
||||||
|
b['localtime'], b['season'], b['episode']))),
|
||||||
|
'network': (lambda a, b: cmp(
|
||||||
|
(a['network'], a['localtime'],
|
||||||
|
(a['show_name'], re.sub(r'(?i)^(The|A|An)\s', '', a['show_name']))[not sickbeard.SORT_ARTICLE],
|
||||||
|
a['season'], a['episode']),
|
||||||
|
(b['network'], b['localtime'],
|
||||||
|
(b['show_name'], re.sub(r'(?i)^(The|A|An)\s', '', b['show_name']))[not sickbeard.SORT_ARTICLE],
|
||||||
|
b['season'], b['episode'])))
|
||||||
}
|
}
|
||||||
|
|
||||||
# make a dict out of the sql results
|
# make a dict out of the sql results
|
||||||
|
@ -421,8 +443,8 @@ class MainHandler(RequestHandler):
|
||||||
paused_item,
|
paused_item,
|
||||||
]
|
]
|
||||||
|
|
||||||
t.next_week = datetime.datetime.combine(next_week1, datetime.time(tzinfo=network_timezones.sb_timezone))
|
t.next_week = datetime.datetime.combine(next_week_dt, datetime.time(tzinfo=network_timezones.sb_timezone))
|
||||||
t.today = datetime.datetime.now().replace(tzinfo=network_timezones.sb_timezone)
|
t.today = datetime.datetime.now(network_timezones.sb_timezone)
|
||||||
t.sql_results = sql_results
|
t.sql_results = sql_results
|
||||||
|
|
||||||
# Allow local overriding of layout parameter
|
# Allow local overriding of layout parameter
|
||||||
|
|
Loading…
Reference in a new issue