示例#1
0
def get_network_timezone(network, return_name=False):
    if network is None:
        return sb_timezone

    timezone = None
    timezone_name = None

    try:
        if zoneinfo.ZONEFILENAME is not None:
            if not network_dict:
                load_network_dict()
            try:
                timezone_name = network_dupes.get(network) or network_dict.get(network.replace(' ', '').lower())
                timezone = tz.gettz(timezone_name, zoneinfo_priority=True)
            except (StandardError, Exception):
                pass

            if timezone is None:
                cc = re.search(r'\(([a-z]+)\)$', network, flags=re.I)
                try:
                    timezone_name = country_timezones.get(cc.group(1).upper())
                    timezone = tz.gettz(timezone_name, zoneinfo_priority=True)
                except (StandardError, Exception):
                    pass
    except (StandardError, Exception):
        pass

    if return_name:
        return timezone if isinstance(timezone, datetime.tzinfo) else sb_timezone, timezone_name
    return timezone if isinstance(timezone, datetime.tzinfo) else sb_timezone
示例#2
0
def get_network_timezone(network, return_name=False):
    if network is None:
        return sb_timezone

    timezone = None
    timezone_name = None

    try:
        if zoneinfo.ZONEFILENAME is not None:
            if not network_dict:
                load_network_dict()
            try:
                timezone_name = network_dupes.get(network) or network_dict.get(
                    network.replace(' ', '').lower())
                timezone = tz.gettz(timezone_name, zoneinfo_priority=True)
            except (StandardError, Exception):
                pass

            if timezone is None:
                cc = re.search(r'\(([a-z]+)\)$', network, flags=re.I)
                try:
                    timezone_name = country_timezones.get(cc.group(1).upper())
                    timezone = tz.gettz(timezone_name, zoneinfo_priority=True)
                except (StandardError, Exception):
                    pass
    except (StandardError, Exception):
        pass

    if return_name:
        return timezone if isinstance(
            timezone, datetime.tzinfo) else sb_timezone, timezone_name
    return timezone if isinstance(timezone, datetime.tzinfo) else sb_timezone
示例#3
0
def get_network_timezone(network):
    if network is None:
        return sb_timezone

    timezone = None

    try:
        if zoneinfo.ZONEFILENAME is not None:
            if not network_dict:
                load_network_dict()
            try:
                timezone = tz.gettz(
                    network_dupes.get(network)
                    or network_dict.get(network.replace(' ', '').lower()))
            except:
                pass

            if timezone is None:
                cc = re.search(r'\(([a-z]+)\)$', network, flags=re.I)
                try:
                    timezone = tz.gettz(
                        country_timezones.get(cc.group(1).upper()))
                except:
                    pass
    except:
        pass

    return timezone if isinstance(timezone, datetime.tzinfo) else sb_timezone
 def test_timezone(self):
     network_timezones.update_network_dict()
     network_timezones.sb_timezone = tz.gettz('CET', zoneinfo_priority=True)
     d = datetime.date(2018, 9, 2).toordinal()
     t = 'Monday 9:00 PM'
     network = 'NBC'
     r = network_timezones.parse_date_time(d, t, network)
     local_date = datetime.datetime(2018, 9, 3, 3, 0, 0).replace(tzinfo=tz.gettz('CET', zoneinfo_priority=True))
     self.assertEqual(r, local_date)
示例#5
0
 def test_timezone(self):
     network_timezones.update_network_dict()
     network_timezones.sb_timezone = tz.gettz('CET', zoneinfo_priority=True)
     d = datetime.date(2018, 9, 2).toordinal()
     t = 'Monday 9:00 PM'
     network = 'NBC'
     r = network_timezones.parse_date_time(d, t, network)
     local_date = datetime.datetime(
         2018, 9, 3, 3, 0,
         0).replace(tzinfo=tz.gettz('CET', zoneinfo_priority=True))
     self.assertEqual(r, local_date)
示例#6
0
def get_network_timezone(network, network_dict, sb_timezone):
    if network == None:
        return sb_timezone

    try:
        return tz.gettz(network_dict[network])
    except:
        return sb_timezone
示例#7
0
    def near(self, delta):
        near = []
        td = timedelta(days=delta)
        now = datetime.now(tz.gettz(self.timeZone))
        for current_task in self.tasks:
            if current_task.due - now < td:
                near.append(current_task)
        near.sort(key=lambda r: r.due)

        return near
示例#8
0
def get_tz():
    t = get_localzone()
    if isinstance(t, datetime.tzinfo) and hasattr(t, 'zone') and t.zone and hasattr(sickbeard, 'ZONEINFO_DIR'):
        try:
            t = tz_fallback(tz.gettz(t.zone, zoneinfo_priority=True))
        except:
            t = tz_fallback(t)
    else:
        t = tz_fallback(t)
    return t
def get_network_timezone(network, network_dict):
    if network is None:
        return sb_timezone

    try:
        if lib.dateutil.zoneinfo.ZONEINFOFILE is not None:
            return tz.gettz(network_dict[network])
        else:
            return sb_timezone
    except:
        return sb_timezone
def get_network_timezone(network, network_dict):
    if network is None:
        return sb_timezone

    try:
        if lib.dateutil.zoneinfo.ZONEINFOFILE is not None:
            return tz.gettz(network_dict[network])
        else:
            return sb_timezone
    except:
        return sb_timezone
示例#11
0
def get_network_timezone(network, return_name=False):
    # type: (AnyStr, bool) -> Optional[datetime.tzinfo, Tuple[datetime.tzinfo, AnyStr]]
    """
    get timezone of a network or return default timezone

    :param network: network name
    :param return_name: return name
    :return: timezone info or tuple of timezone info, timezone name
    """
    if None is network:
        return SG_TIMEZONE

    timezone = None
    timezone_name = None

    try:
        if None is not zoneinfo.ZONEFILENAME:
            if not network_dict:
                load_network_dict()
            try:
                timezone_name = network_dupes.get(network) or network_dict.get(network.replace(' ', '').lower())
                timezone = tz.gettz(timezone_name, zoneinfo_priority=True)
            except (BaseException, Exception):
                pass

            if None is timezone:
                cc = re.search(r'\(([a-z]+)\)$', network, flags=re.I)
                try:
                    timezone_name = country_timezones.get(cc.group(1).upper())
                    timezone = tz.gettz(timezone_name, zoneinfo_priority=True)
                except (BaseException, Exception):
                    pass
    except (BaseException, Exception):
        pass

    if not isinstance(timezone, datetime.tzinfo):
        timezone = SG_TIMEZONE
    if return_name:
        return timezone, timezone_name
    return timezone
示例#12
0
def get_utc():
    # type: (...) -> Optional[datetime.tzinfo]
    if hasattr(sickbeard, 'ZONEINFO_DIR'):
        utc = None
        try:
            utc = tz.gettz('GMT', zoneinfo_priority=True)
        except (BaseException, Exception):
            pass
        if isinstance(utc, datetime.tzinfo):
            return utc
    tz_utc_file = ek.ek(os.path.join, ek.ek(os.path.dirname, zoneinfo.__file__), 'Greenwich')
    if ek.ek(os.path.isfile, tz_utc_file):
        return tz.tzfile(tz_utc_file)
示例#13
0
def get_tz():
    t = None
    try:
        t = get_localzone()
    except (BaseException, Exception):
        pass
    if isinstance(t, datetime.tzinfo) and hasattr(t, 'zone') and t.zone and hasattr(sickbeard, 'ZONEINFO_DIR'):
        try:
            # noinspection PyUnresolvedReferences
            t = tz_fallback(tz.gettz(t.zone, zoneinfo_priority=True))
        except (BaseException, Exception):
            t = tz_fallback(t)
    else:
        t = tz_fallback(t)
    return t
示例#14
0
def get_network_timezone(network, network_dict):
    if network is None:
        return sb_timezone

    try:
        if zoneinfo._ZONEFILENAME is not None:
            try:
                n_t = tz.gettz(network_dict[network])
            except:
                return sb_timezone

            if n_t is not None:
                return n_t
            else:
                return sb_timezone
        else:
            return sb_timezone
    except:
        return sb_timezone
示例#15
0
def get_network_timezone(network, network_dict):
    if network is None:
        return sb_timezone

    try:
        if zoneinfo._ZONEFILENAME is not None:
            try:
                n_t = tz.gettz(network_dict[network])
            except:
                return sb_timezone

            if n_t is not None:
                return n_t
            else:
                return sb_timezone
        else:
            return sb_timezone
    except:
        return sb_timezone
示例#16
0
    def get_tasks(self):
        url = ''
        package = ''
        for project in self.projects:
            project_id = project.id
            try:
                url = 'https://todoist.com/API/getUncompletedItems?project_id=' + str(
                    project_id) + '&token=' + self.token
                package = Requests.get(url)
                project_tasks = package.json()
            except:
                print url
                print package.text
                continue

            for task_num in range(0, len(project_tasks)):
                task_id = int(project_tasks[task_num]['id'])
                # Correctly format and remove any extra characters that datetime can't handel

                if project_tasks[task_num]['due_date'] is None:
                    continue  # We don't care about tasks without due dates
                if int(project_tasks[task_num]['indent']) != 1:
                    # TODO Subtasks
                    continue  # Right now we can't handel Subtasks

                date_string = str(project_tasks[task_num]['due_date'].strip())
                if date_string == 'null':
                    continue
                if date_string.find('.') > -1:
                    date_string = date_string[0:date_string.find('.')]
                if date_string.find('+') > -1:
                    date_string = date_string[0:date_string.find('+')]

                try:
                    utc = datetime.strptime(date_string, '%a %d %b %Y %X')
                except ValueError:
                    try:
                        utc = datetime.strptime(date_string, '%a %d %b %Y %X ')
                    except ValueError:
                        try:
                            utc = datetime.strptime(date_string, '%a %b %d %Y %X %z')
                        except ValueError:
                            print 'input:', date_string, 'processed:', "Error"
                            continue  # Skip This Task, because it doesn't have a valid date and can't be sorted

                # Fix timezone, and set due date to local time zone
                utc = utc.replace(tzinfo=tz.gettz('UTC'))  # Default Todoist TZ is UTC
                local = tz.gettz(self.timeZone)  # set a fixed TimeZone, Which is set by the User in the Todoist App
                # local = tz.tzlocal()   # Use to auto-detect local TimeZone
                date_due = utc.astimezone(local)
                delta = date_due - datetime.now(tz=tz.gettz(self.timeZone))

                task_name = project_tasks[task_num]['content'].replace('*', '')
                task_priority = project_tasks[task_num]['priority']

                if self.todoist_premium_status:
                    package = ''
                    url = ''
                    task_notes = []
                    try:
                        url = 'https://todoist.com/API/getNotes?item_id=' + str(task_id) + '&token=' + self.token
                        package = Requests.get(url)
                        all_notes = package.json()
                        for note_number in range(0, len(all_notes)):
                            task_notes.append(all_notes[note_number]['content'])
                        task_notes = tuple(task_notes)

                    except:
                        task_notes = tuple()
                else:
                    task_notes = tuple()

                new_task = Task(task_name, project, date_due, delta, task_priority, task_notes)
                self.tasks.append(new_task)