Added a interval config var to set repositioning of shows to start at say, 15, 30, 45 minutes past the hour.

This commit is contained in:
Justin Emter
2017-07-16 00:28:46 -07:00
parent 100f1068d7
commit e0d78ad4ba
4 changed files with 73 additions and 12 deletions

3
.gitignore vendored
View File

@@ -1,3 +1,4 @@
pseudo_config.pyc
pseudo_config.*
pseudo_tv.db
pseudo_tv.db
pseudo-tv.db

View File

@@ -15,10 +15,17 @@ plex = PlexServer(baseurl, token)
conn = sqlite3.connect('pseudo-tv.db', timeout=10)
c = conn.cursor()
def create_table():
c.execute('DROP TABLE IF EXISTS schedule')
c.execute('CREATE TABLE IF NOT EXISTS schedule(id INTEGER PRIMARY KEY AUTOINCREMENT, unix INTEGER, mediaID INTEGER, title TEXT, duration INTEGER, startTime INTEGER, endTime INTEGER, dayOfWeek TEXT, startTimeUnix INTEGER)')
def add_schedule_to_db(mediaID, title, duration, startTime, endTime, dayOfWeek):
unix = int(time.time())
startTimeUnix = str(datetime.datetime.strptime(startTime, '%I:%M %p'))
try:
c.execute("INSERT OR REPLACE INTO schedule (unix, mediaID, title, duration, startTime, endTime, dayOfWeek, startTimeUnix) VALUES (?, ?, ?, ?, ?, ?, ?, ?)", (unix, mediaID, title, duration, startTime, endTime, dayOfWeek, startTimeUnix))
conn.commit()
c.close()

View File

@@ -20,6 +20,9 @@ import string
import argparse
import datetime
import calendar
import itertools
from pseudo_config import *
conn = sqlite3.connect('pseudo-tv.db')
@@ -105,29 +108,72 @@ def calculate_start_time_offset_from_prev_episode_endtime(prevEndTime, intendedS
* If time difference is negative, then we know there is overlap
*
'''
if timeDiff <= 0:
if timeDiff < 0:
print("There is overlap ")
'''
*
* If there is an overlap, then the overlapGap var in config will determine the next increment. If it is set to "15", then the show will will bump up to the next 15 minute interval past the hour.
*
'''
timeset=[datetime.time(h,m).strftime("%H:%M") for h,m in itertools.product(xrange(0,24),xrange(0,60,int(overlapGap)))]
print(timeset)
timeSetToUse = None
for time in timeset:
#print(time)
theTimeSetInterval = datetime.datetime.strptime(time, '%H:%M')
# print(theTimeSetInterval)
# print(prevEndTime)
if theTimeSetInterval >= prevEndTime:
print("Setting new time by interval... " + time)
print("made it!")
newStartTime = theTimeSetInterval
break
#newStartTime = newTimeObj + datetime.timedelta(minutes=abs(timeDiff + overlapGap))
elif (timeDiff >= 0) and (timeGap != -1):
'''
*
* If timeDiff is not more than 15 minutes, or 30 minutes just adjust by 15 or 30. If more than adjust by the exact difference
* If there this value is configured, then the timeGap var in config will determine the next increment. If it is set to "15", then the show will will bump up to the next 15 minute interval past the hour.
*
'''
newStartTime = newTimeObj + datetime.timedelta(minutes=abs(timeDiff + 5))
timeset=[datetime.time(h,m).strftime("%H:%M") for h,m in itertools.product(xrange(0,24),xrange(0,60,int(timeGap)))]
# print(timeset)
elif timeDiff <= 5:
timeSetToUse = None
print("timeDiff is less than or equal to 5 minutes")
for time in timeset:
elif timeDiff > 5:
#print(time)
theTimeSetInterval = datetime.datetime.strptime(time, '%H:%M')
print("Time gap is more than ten, let's start next media earlier than inended")
# print(theTimeSetInterval)
# if prevEpDuration < 10
# print(prevEndTime)
if theTimeSetInterval >= prevEndTime:
print("Setting new time by interval... " + time)
print("made it!")
newStartTime = theTimeSetInterval
break
newStartTime = newTimeObj - datetime.timedelta(minutes=timeDiff-5)
else:
@@ -339,7 +385,7 @@ def generate_daily_schedule():
prevEpisodeEndTime = endTime
prevEpDuration = first_episode[4]
prevEpDuration = next_episode[4]
print("prevEpisodeEndTime: " + str(prevEpisodeEndTime));
@@ -356,6 +402,8 @@ def generate_daily_schedule():
print("Not grabbing next episode for some reason")
except Exception as e:
#raise e
'''
*
* Let's assume that this error is always because we hit the end of the series and start over...
@@ -402,7 +450,7 @@ def generate_daily_schedule():
prevEpDuration = next_episode[4]
# raise e
generate_daily_schedule()

View File

@@ -5,6 +5,11 @@ python pseudo_channel.py -a "shows" -n "looney tunes" -t "6:30 AM" -d "weekdays"
python pseudo_channel.py -a "shows" -n "looney tunes" -t "7:00 AM" -d "weekdays"
python pseudo_channel.py -a "shows" -n "looney tunes" -t "7:30 AM" -d "weekdays"
# python pseudo_channel.py -a "shows" -n "daria" -t "6:00 AM" -d "weekdays"
# python pseudo_channel.py -a "shows" -n "daria" -t "6:30 AM" -d "weekdays"
# python pseudo_channel.py -a "shows" -n "looney tunes" -t "7:00 AM" -d "weekdays"
# python pseudo_channel.py -a "shows" -n "looney tunes" -t "7:30 AM" -d "weekdays"
python pseudo_channel.py -a "shows" -n "Garfield & Friends" -t "8:00 AM" -d "weekdays"
python pseudo_channel.py -a "shows" -n "Garfield & Friends" -t "8:30 AM" -d "weekdays"