diff --git a/sickbeard/webserve.py b/sickbeard/webserve.py index 540fb16e70e9703a51177bb1ea2052e5a2b92158..845b3a1f6faaa7fd8262f266a4f1dfe66408bcf3 100644 --- a/sickbeard/webserve.py +++ b/sickbeard/webserve.py @@ -3721,43 +3721,46 @@ class WebInterface: for episode in episode_list: - # Get local timezone and load network timezones - local_zone = tz.tzlocal() - try: - network_zone = network_timezones.get_network_timezone(show['network'], network_timezones.load_network_dict(), local_zone) - except: + # Get local timezone and load network timezones + local_zone = tz.tzlocal() + try: + network_zone = network_timezones.get_network_timezone(show['network'], network_timezones.load_network_dict(), local_zone) + except: # Dummy network_zone for exceptions - network_zone = None + network_zone = None # Get the air date and time - air_date = datetime.datetime.fromordinal(int(episode['airdate'])) - air_time = re.compile('([0-9]{1,2})\:([0-9]{2})(\ |)([AM|am|PM|pm]{2})').search(show["airs"]) + air_date = datetime.datetime.fromordinal(int(episode['airdate'])) + air_time = re.compile('([0-9]{1,2})\:([0-9]{2})(\ |)([AM|am|PM|pm]{2})').search(show["airs"]) # Parse out the air time - try: - if (air_time.group(4).lower() == 'pm' and int(air_time.group(1)) == 12): - t = datetime.time(12, int(air_time.group(2)), 0, tzinfo=network_zone) - elif (air_time.group(4).lower() == 'pm'): - t = datetime.time((int(air_time.group(1)) + 12), int(air_time.group(2)), 0, tzinfo=network_zone) - elif (air_time.group(4).lower() == 'am' and int(air_time.group(1)) == 12): - t = datetime.time(0, int(air_time.group(2)), 0, tzinfo=network_zone) - else: - t = datetime.time(int(air_time.group(1)), int(air_time.group(2)), 0, tzinfo=network_zone) - except: - # Dummy time for exceptions - t = datetime.time(22, 0, 0, tzinfo=network_zone) + try: + if (air_time.group(4).lower() == 'pm' and int(air_time.group(1)) == 12): + t = datetime.time(12, int(air_time.group(2)), 0, tzinfo=network_zone) + elif (air_time.group(4).lower() == 'pm'): + t = datetime.time((int(air_time.group(1)) + 12), int(air_time.group(2)), 0, tzinfo=network_zone) + elif (air_time.group(4).lower() == 'am' and int(air_time.group(1)) == 12): + t = datetime.time(0, int(air_time.group(2)), 0, tzinfo=network_zone) + else: + t = datetime.time(int(air_time.group(1)), int(air_time.group(2)), 0, tzinfo=network_zone) + except: + # Dummy time for exceptions + t = datetime.time(22, 0, 0, tzinfo=network_zone) # Combine air time and air date into one datetime object - air_date_time = datetime.datetime.combine(air_date, t).astimezone(local_zone) + air_date_time = datetime.datetime.combine(air_date, t).astimezone(local_zone) # Create event for episode - ical = ical + 'BEGIN:VEVENT\n' - ical = ical + 'DTSTART:' + str(air_date_time.date()).replace("-", "") + '\n' - ical = ical + 'SUMMARY:' + show['show_name'] + ': ' + episode['name'] + '\n' - ical = ical + 'UID:' + str(datetime.date.today().isoformat()) + '-' + str(random.randint(10000,99999)) + '@Sick-Beard\n' - ical = ical + 'DESCRIPTION:' + episode['description'] + '\n' - ical = ical + 'LOCATION:' + 'Episode ' + str(episode['episode']) + ' - Season ' + str(episode['season']) + '\n' - ical = ical + 'END:VEVENT\n' + ical = ical + 'BEGIN:VEVENT\n' + ical = ical + 'DTSTART:' + str(air_date_time.date()).replace("-", "") + '\n' + ical = ical + 'SUMMARY:' + show['show_name'] + ': ' + episode['name'] + '\n' + ical = ical + 'UID:' + str(datetime.date.today().isoformat()) + '-' + str(random.randint(10000,99999)) + '@Sick-Beard\n' + if (episode['description'] != ''): + ical = ical + 'DESCRIPTION:' + show['airs'] + ' on ' + show['network'] + '\\n\\n' + episode['description'] + '\n' + else: + ical = ical + 'DESCRIPTION:' + show['airs'] + ' on ' + show['network'] + '\n' + ical = ical + 'LOCATION:' + 'Episode ' + str(episode['episode']) + ' - Season ' + str(episode['season']) + '\n' + ical = ical + 'END:VEVENT\n' # Ending the iCal ical += 'END:VCALENDAR\n'