def date_local_end(self): if getattr(self, "_date_local_end", None) is None: try: tz = get_timezone_for_gmt_offset(self.show.timezone) except Exception: tz = utc self._date_local_end = utc.localize(self.date_end).astimezone(tz) return self._date_local_end
def main(): tz = get_timezone_for_gmt_offset("GMT-5 -DST") date_str = "2011-01-31" date = datetime.datetime(*map(int, date_str.split("-"))) delta = datetime.timedelta(hours=21, minutes=0) date = date + delta date = tz.localize(date) today = datetime.datetime.now(utc) print date >= today
def main(): tz = get_timezone_for_gmt_offset("GMT-5 -DST") date_str = "2011-01-31" date = datetime.datetime(*map(int, date_str.split("-"))) delta = datetime.timedelta(hours=21, minutes=0) date = date + delta date = tz.localize(date) today = datetime.datetime.now(utc) print date >= today tvrage = TVRage() print tvrage.get_info(15614).active
def create_event_details(self, cal): vevent = cal.add('vevent') vevent.add('uid').value = "seriesly-episode-%s" % self.key() try: tz = get_timezone_for_gmt_offset(self.show.timezone) except Exception: tz = utc date = utc.localize(self.date).astimezone(tz) vevent.add('dtstart').value = date vevent.add('dtend').value = date + datetime.timedelta(minutes=self.show.runtime) vevent.add('summary').value = "%s - %s (%dx%d)" % (self.show.name, self.title, self.season_number, self.number) vevent.add('location').value = self.show.network return vevent
def get_info(self, show_id): """<Show> <name>Scrubs</name> <totalseasons>9</totalseasons> <showid>5118</showid> <showlink>http://tvrage.com/Scrubs</showlink> <started>Oct/02/2001</started> <ended></ended> <image>http://images.tvrage.com/shows/6/5118.jpg</image> <origin_country>US</origin_country> <status>Returning Series</status> <classification>Scripted</classification> <genres><genre>Comedy</genre></genres> <runtime>30</runtime> <network country="US">ABC</network> <airtime>21:00</airtime> <airday>Tuesday</airday> <timezone>GMT-5 -DST</timezone> <akas><aka country="LV">Dakterīši</aka><aka country="HU">Dokik</aka><aka country="SE">Första hjälpen</aka><aka country="NO">Helt sykt</aka><aka country="PL">Hoży doktorzy</aka><aka attr="Second Season" country="RU">Klinika</aka><aka attr="First Season" country="RU">Meditsinskaya akademiya</aka><aka country="DE">Scrubs: Die Anfänger</aka><aka country="RO">Stagiarii</aka><aka attr="French Title" country="BE">Toubib or not toubib</aka><aka country="FI">Tuho Osasto</aka><aka country="IL">סקרבס</aka></akas> <Episodelist> <Season no="1"> <episode><epnum>1</epnum><seasonnum>01</seasonnum> <prodnum>535G</prodnum> <airdate>2001-10-02</airdate> <link>http://www.tvrage.com/Scrubs/episodes/149685</link> <title>My First Day</title> <screencap>http://images.tvrage.com/screencaps/26/5118/149685.jpg</screencap></episode>""" logging.debug("Start downloading...") show_xml = http_get(self.show_info_url % show_id) logging.debug("Start parsing...") dom = parseString(show_xml) logging.debug("Start walking...") show_doc = dom.getElementsByTagName("Show")[0] seasons = show_doc.getElementsByTagName("Season") special = show_doc.getElementsByTagName("Special") seasons.extend(special) timezone = show_doc.getElementsByTagName("timezone")[0].firstChild.data tz = get_timezone_for_gmt_offset(timezone) last_show_date = None delta_params = show_doc.getElementsByTagName("airtime")[0].firstChild.data.split(":") delta = datetime.timedelta(hours=int(delta_params[0]), minutes=int(delta_params[1])) season_list = [] for season in seasons: try: season_nr = int(season.attributes["no"].value) except Exception: season_nr = False episode_list = [] for episode in season.getElementsByTagName("episode"): if season_nr is False: season_nr = int(episode.getElementsByTagName("season")[0].firstChild.data) try: title = unescape(episode.getElementsByTagName("title")[0].firstChild.data) except AttributeError: title = "" date_str = episode.getElementsByTagName("airdate")[0].firstChild.data try: date = datetime.datetime(*map(int, date_str.split("-"))) date = date + delta date = tz.localize(date) except ValueError: date = None if date is not None: if last_show_date is None or last_show_date < date: last_show_date = date try: epnum = int(episode.getElementsByTagName("seasonnum")[0].firstChild.data) except IndexError: epnum = 0 ep_info = TVEpisodeInfo(date=date, title=title, nr=epnum, season_nr=season_nr) episode_list.append(ep_info) season = TVSeasonInfo(season_nr=season_nr, episodes=episode_list) season_list.append(season) try: runtime = int(show_doc.getElementsByTagName("runtime")[0].firstChild.data) except IndexError: runtime = 30 name = unescape(show_doc.getElementsByTagName("name")[0].firstChild.data) country = show_doc.getElementsByTagName("origin_country")[0].firstChild.data network = unescape(show_doc.getElementsByTagName("network")[0].firstChild.data) genres = show_doc.getElementsByTagName("genre") genre_list = [] for genre in genres: if genre and genre.firstChild and genre.firstChild.data: genre_list.append(genre.firstChild.data) genre_str = "|".join(genre_list) active = show_doc.getElementsByTagName("ended")[0].firstChild if active is None or active.data == "0": active = True elif "/" in active.data: parts = active.data.split('/') if len(parts) == 3: try: month = monthsToNumber[parts[0]] day = int(parts[1]) year = int(parts[2]) if datetime.datetime.now() > datetime.datetime(year, month, day): active = False else: active = True except (ValueError, KeyError): active = True else: active = True else: active = False logging.debug("Return TVShowInfo...") return TVShowInfo(name=name, seasons=season_list, tvrage_id=show_id, country=country, runtime=runtime, network=network, timezone=timezone, active=active, genres=genre_str)
def get_info(self, show_id): """<Show> <name>Scrubs</name> <totalseasons>9</totalseasons> <showid>5118</showid> <showlink>http://tvrage.com/Scrubs</showlink> <started>Oct/02/2001</started> <ended></ended> <image>http://images.tvrage.com/shows/6/5118.jpg</image> <origin_country>US</origin_country> <status>Returning Series</status> <classification>Scripted</classification> <genres><genre>Comedy</genre></genres> <runtime>30</runtime> <network country="US">ABC</network> <airtime>21:00</airtime> <airday>Tuesday</airday> <timezone>GMT-5 -DST</timezone> <akas><aka country="LV">Dakterīši</aka><aka country="HU">Dokik</aka><aka country="SE">Första hjälpen</aka><aka country="NO">Helt sykt</aka><aka country="PL">Hoży doktorzy</aka><aka attr="Second Season" country="RU">Klinika</aka><aka attr="First Season" country="RU">Meditsinskaya akademiya</aka><aka country="DE">Scrubs: Die Anfänger</aka><aka country="RO">Stagiarii</aka><aka attr="French Title" country="BE">Toubib or not toubib</aka><aka country="FI">Tuho Osasto</aka><aka country="IL">סקרבס</aka></akas> <Episodelist> <Season no="1"> <episode><epnum>1</epnum><seasonnum>01</seasonnum> <prodnum>535G</prodnum> <airdate>2001-10-02</airdate> <link>http://www.tvrage.com/Scrubs/episodes/149685</link> <title>My First Day</title> <screencap>http://images.tvrage.com/screencaps/26/5118/149685.jpg</screencap></episode>""" logging.debug("Start downloading...") show_xml = http_get(self.show_info_url % show_id) logging.debug("Start parsing...") dom = parseString(show_xml) logging.debug("Start walking...") show_doc = dom.getElementsByTagName("Show")[0] seasons = show_doc.getElementsByTagName("Season") special = show_doc.getElementsByTagName("Special") seasons.extend(special) timezone = show_doc.getElementsByTagName("timezone")[0].firstChild.data tz = get_timezone_for_gmt_offset(timezone) last_show_date = None delta_params = show_doc.getElementsByTagName("airtime")[0].firstChild.data.split(":") delta = datetime.timedelta(hours=int(delta_params[0]), minutes=int(delta_params[1])) season_list = [] for season in seasons: try: season_nr = int(season.attributes["no"].value) except Exception: season_nr = False episode_list = [] for episode in season.getElementsByTagName("episode"): if season_nr is False: season_nr = int(episode.getElementsByTagName("season")[0].firstChild.data) try: title = unescape(episode.getElementsByTagName("title")[0].firstChild.data) except AttributeError: title = "" date_str = episode.getElementsByTagName("airdate")[0].firstChild.data try: date = datetime.datetime(*map(int, date_str.split("-"))) date = date + delta date = tz.localize(date) except ValueError, e: date = None if date is not None: if last_show_date is None or last_show_date < date: last_show_date = date try: epnum = int(episode.getElementsByTagName("seasonnum")[0].firstChild.data) except IndexError: epnum = 0 ep_info = TVEpisodeInfo(date=date, title=title, nr=epnum, season_nr=season_nr) episode_list.append(ep_info) season = TVSeasonInfo(season_nr=season_nr, episodes=episode_list) season_list.append(season)