mirror of
https://github.com/FakeTV/pseudo-channel.git
synced 2025-12-21 02:33:30 +00:00
Added google calendar integration... Create a calendar event with a comma dilineated title like, 'Show, Seinfeld, false' where the third value is for strict-time.
This commit is contained in:
148
PseudoChannel.py
148
PseudoChannel.py
@@ -8,6 +8,7 @@ from src import Episode
|
||||
from src import Music
|
||||
from src import Video
|
||||
from src import PseudoDailyScheduleController
|
||||
from src import GoogleCalendar
|
||||
|
||||
from plexapi.server import PlexServer
|
||||
|
||||
@@ -32,6 +33,8 @@ class PseudoChannel():
|
||||
|
||||
PLEX = PlexServer(config.baseurl, config.token)
|
||||
MEDIA = []
|
||||
USING_GCALENDAR = config.useGoogleCalendar
|
||||
GKEY = config.gkey
|
||||
|
||||
def __init__(self):
|
||||
|
||||
@@ -179,6 +182,107 @@ class PseudoChannel():
|
||||
bar_length = 40
|
||||
)
|
||||
|
||||
def update_schedule_from_google_calendar(self):
|
||||
|
||||
self.gcal = GoogleCalendar(self.GKEY)
|
||||
|
||||
events = self.gcal.get_entries()
|
||||
|
||||
self.db.create_tables()
|
||||
|
||||
self.db.remove_all_scheduled_items()
|
||||
|
||||
scheduled_days_list = [
|
||||
"mondays",
|
||||
"tuesdays",
|
||||
"wednesdays",
|
||||
"thursdays",
|
||||
"fridays",
|
||||
"saturdays",
|
||||
"sundays",
|
||||
"weekdays",
|
||||
"weekends",
|
||||
"everyday"
|
||||
]
|
||||
|
||||
section_dict = {
|
||||
"TV Shows" : ["series", "shows", "tv", "episodes", "tv shows", "show"],
|
||||
"Movies" : ["movie", "movies", "films", "film"],
|
||||
"Videos" : ["video", "videos", "vid"],
|
||||
"Music" : ["music", "songs", "song", "tune", "tunes"]
|
||||
}
|
||||
|
||||
weekday_dict = {
|
||||
"0" : ["mondays", "weekdays", "everyday"],
|
||||
"1" : ["tuesdays", "weekdays", "everyday"],
|
||||
"2" : ["wednesdays", "weekdays", "everyday"],
|
||||
"3" : ["thursdays", "weekdays", "everyday"],
|
||||
"4" : ["fridays", "weekdays", "everyday"],
|
||||
"5" : ["saturdays", "weekends", "everyday"],
|
||||
"6" : ["sundays", "weekends", "everyday"],
|
||||
}
|
||||
|
||||
for event in events:
|
||||
|
||||
titlelist = [x.strip() for x in event['summary'].split(',')]
|
||||
|
||||
start = event['start'].get('dateTime', event['start'].get('date'))
|
||||
|
||||
s = datetime.datetime.strptime(start,"%Y-%m-%dT%H:%M:%S-07:00")
|
||||
|
||||
weekno = s.weekday()
|
||||
|
||||
for key, value in section_dict.items():
|
||||
|
||||
if str(titlelist[0]).lower() == key or str(titlelist[0]).lower() in value:
|
||||
|
||||
print "Adding {} to schedule.".format(titlelist[1])
|
||||
|
||||
title = titlelist[1]
|
||||
|
||||
# s.strftime('%I:%M'), event["summary"]
|
||||
natural_start_time = self.translate_time(s.strftime('%I:%M %p'))
|
||||
|
||||
natural_end_time = 0
|
||||
|
||||
section = key
|
||||
|
||||
for dnum, daylist in weekday_dict.items():
|
||||
|
||||
#print int(weekno), int(dnum)
|
||||
|
||||
if int(weekno) == int(dnum):
|
||||
|
||||
day_of_week = daylist[0]
|
||||
|
||||
strict_time = titlelist[2] if len(titlelist) > 2 else "true"
|
||||
|
||||
time_shift = "5"
|
||||
|
||||
overlap_max = ""
|
||||
|
||||
print natural_start_time
|
||||
|
||||
start_time_unix = datetime.datetime.strptime(
|
||||
self.translate_time(natural_start_time),
|
||||
'%I:%M %p').strftime('%Y-%m-%d %H:%M:%S')
|
||||
|
||||
#print "Adding: ", time.tag, section, time.text, time.attrib['title']
|
||||
|
||||
self.db.add_schedule_to_db(
|
||||
0, # mediaID
|
||||
title, # title
|
||||
0, # duration
|
||||
natural_start_time, # startTime
|
||||
natural_end_time, # endTime
|
||||
day_of_week, # dayOfWeek
|
||||
start_time_unix, # startTimeUnix
|
||||
section, # section
|
||||
strict_time, # strictTime
|
||||
time_shift, # timeShift
|
||||
overlap_max, # overlapMax
|
||||
)
|
||||
|
||||
def update_schedule(self):
|
||||
|
||||
self.db.create_tables()
|
||||
@@ -647,6 +751,37 @@ class PseudoChannel():
|
||||
|
||||
previous_episode = entry
|
||||
|
||||
def get_daily_schedule_as_media_object_list(self):
|
||||
|
||||
for i, item in enumerate(self.db.get_daily_schedule(), start=0):
|
||||
|
||||
if item[11] == "TV Shows":
|
||||
|
||||
"""episode = Episode(
|
||||
|
||||
)"""
|
||||
pass
|
||||
|
||||
elif item[11] == "Movies":
|
||||
|
||||
pass
|
||||
|
||||
elif item[11] == "Music":
|
||||
|
||||
pass
|
||||
|
||||
elif item[11] == "Commercials":
|
||||
|
||||
pass
|
||||
|
||||
elif item[11] == "Videos":
|
||||
|
||||
pass
|
||||
|
||||
else:
|
||||
|
||||
pass
|
||||
|
||||
def show_clients(self):
|
||||
|
||||
print "##### Connected Clients:"
|
||||
@@ -743,6 +878,15 @@ if __name__ == '__main__':
|
||||
action='store_true',
|
||||
help='Show scheduled media for today.')
|
||||
|
||||
'''
|
||||
*
|
||||
* Update Schedule based on Google Cal: "python PseudoChannel.py -gc"
|
||||
*
|
||||
'''
|
||||
parser.add_argument('-gc',
|
||||
action='store_true',
|
||||
help='Updates the schedule based on entries in the google calendar.')
|
||||
|
||||
globals().update(vars(parser.parse_args()))
|
||||
|
||||
args = parser.parse_args()
|
||||
@@ -757,6 +901,10 @@ if __name__ == '__main__':
|
||||
|
||||
pseudo_channel.update_schedule()
|
||||
|
||||
if args.gc:
|
||||
|
||||
pseudo_channel.update_schedule_from_google_calendar()
|
||||
|
||||
if args.g:
|
||||
|
||||
pseudo_channel.generate_daily_schedule()
|
||||
|
||||
Reference in New Issue
Block a user