本文整理汇总了Python中pytz.all_timezones_set方法的典型用法代码示例。如果您正苦于以下问题:Python pytz.all_timezones_set方法的具体用法?Python pytz.all_timezones_set怎么用?Python pytz.all_timezones_set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pytz
的用法示例。
在下文中一共展示了pytz.all_timezones_set方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import pytz [as 别名]
# 或者: from pytz import all_timezones_set [as 别名]
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)
示例2: set_session_timezone
# 需要导入模块: import pytz [as 别名]
# 或者: from pytz import all_timezones_set [as 别名]
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,
)
示例3: test_belfast
# 需要导入模块: import pytz [as 别名]
# 或者: from pytz import all_timezones_set [as 别名]
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)
示例4: _get_localzone
# 需要导入模块: import pytz [as 别名]
# 或者: from pytz import all_timezones_set [as 别名]
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)
示例5: _get_localzone
# 需要导入模块: import pytz [as 别名]
# 或者: from pytz import all_timezones_set [as 别名]
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)
示例6: generate_meeting_data
# 需要导入模块: import pytz [as 别名]
# 或者: from pytz import all_timezones_set [as 别名]
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