Python pytz.all_timezones_set() Examples

The following are 6 code examples of pytz.all_timezones_set(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module pytz , or try the search function .
Example #1
Source File: TradingBot.py    From TradingBot with MIT License 6 votes vote down vote up
def __init__(self, time_provider=None, config_filepath=None):
        # Time manager
        self.time_provider = time_provider if time_provider else TimeProvider()
        # Set timezone
        set(pytz.all_timezones_set)

        # Load configuration
        self.config = Configuration.from_filepath(config_filepath)

        # Setup the global logger
        self.setup_logging()

        # Init trade services and create the broker interface
        # The Factory is used to create the services from the configuration file
        self.broker = BrokerInterface(BrokerFactory(self.config))

        # Create strategy from the factory class
        self.strategy = StrategyFactory(
            self.config, self.broker
        ).make_from_configuration()

        # Create the market provider
        self.market_provider = MarketProvider(self.config, self.broker) 
Example #2
Source File: views.py    From janeway with GNU Affero General Public License v3.0 6 votes vote down vote up
def set_session_timezone(request):
    chosen_timezone = request.POST.get("chosen_timezone")
    response_data = {}
    if chosen_timezone in pytz.all_timezones_set:
        request.session["janeway_timezone"] = chosen_timezone
        status = 200
        response_data['message'] = 'OK'
        logger.debug("Timezone set to %s for this session" % chosen_timezone)
    else:
        status = 404
        response_data['message'] = 'Timezone not found: %s' % chosen_timezone
    response_data = {}

    return HttpResponse(
            content=json.dumps(response_data),
            content_type='application/json',
            status=200,
    ) 
Example #3
Source File: test_tzinfo.py    From sndlatr with Apache License 2.0 5 votes vote down vote up
def test_belfast(self):
        # Belfast uses London time.
        self.assertTrue('Europe/Belfast' in pytz.all_timezones_set)
        self.assertFalse('Europe/Belfast' in pytz.common_timezones)
        self.assertFalse('Europe/Belfast' in pytz.common_timezones_set) 
Example #4
Source File: darwin.py    From xbmc-addons-chinese with GNU General Public License v2.0 5 votes vote down vote up
def _get_localzone():
    pipe = subprocess.Popen(
        "systemsetup -gettimezone",
        shell=True,
        stderr=subprocess.PIPE,
        stdout=subprocess.PIPE
    )
    tzname = pipe.stdout.read().replace(b'Time Zone: ', b'').strip()

    if not tzname or tzname not in pytz.all_timezones_set:
        # link will be something like /usr/share/zoneinfo/America/Los_Angeles.
        link = os.readlink("/etc/localtime")
        tzname = link[link.rfind("zoneinfo/") + 9:]
    return pytz.timezone(tzname) 
Example #5
Source File: darwin.py    From komodo-wakatime with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def _get_localzone(_root='/'):
    with Popen(
        "systemsetup -gettimezone",
        shell=True,
        stderr=subprocess.PIPE,
        stdout=subprocess.PIPE
    ) as pipe:
        tzname = pipe.stdout.read().replace(b'Time Zone: ', b'').strip()

    if not tzname or tzname not in pytz.all_timezones_set:
        # link will be something like /usr/share/zoneinfo/America/Los_Angeles.
        link = os.readlink(os.path.join(_root, "etc/localtime"))
        tzname = link[link.rfind("zoneinfo/") + 9:]

    return pytz.timezone(tzname) 
Example #6
Source File: cisco_api.py    From resilient-community-apps with MIT License 5 votes vote down vote up
def generate_meeting_data(self):
        """Generates partial XML that is used to create a meeting"""
        meeting_password = self.opts.get("meeting_password")
        meeting_name = self.opts.get("meeting_name")
        meeting_agenda = self.opts.get("meeting_agenda")

        timezone_info = self.get_timezone_info()
        if type(timezone_info.get("id")) is int and timezone_info.get("id") is 0:
            raise FunctionError(timezone_info.get("reason", "unknown reason"))

        utc_offset = datetime.timedelta(hours=timezone_info["gmt_hour"], minutes=timezone_info["gmt_minute"])
        now = datetime.datetime.now(pytz.utc)

        timezones_with_offset = list({tz for tz in map(pytz.timezone, pytz.all_timezones_set)
                                      if now.astimezone(tz).utcoffset() == utc_offset})
        if self.meeting_start_time is None:
            time = datetime.datetime.now(tz=timezones_with_offset[0])
            duration = DEFAULT_MEETING_LENGTH
        else:
            time = datetime.datetime.fromtimestamp(self.meeting_start_time/1000, tz=timezones_with_offset[0])
            if self.meeting_end_time:
                duration = int((self.meeting_end_time/1000 - self.meeting_start_time/1000)/60)
            else:
                duration = DEFAULT_MEETING_LENGTH
        meeting_time = time.strftime("%m/%d/%Y %H:%M:%S")

        xml = """<accessControl>
        <meetingPassword>{}</meetingPassword>
        </accessControl>
        <metaData>
        <confName>{}</confName>
        <agenda>{}</agenda>
        </metaData>
        <schedule>
        <startDate>{}</startDate>
        <duration>{}</duration>
        <timeZoneID>{}</timeZoneID>
        </schedule>""".format(meeting_password, meeting_name, meeting_agenda, meeting_time, duration,
                              timezone_info.get("id"))

        return xml