本文整理汇总了Python中tzlocal.get_localzone方法的典型用法代码示例。如果您正苦于以下问题:Python tzlocal.get_localzone方法的具体用法?Python tzlocal.get_localzone怎么用?Python tzlocal.get_localzone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tzlocal
的用法示例。
在下文中一共展示了tzlocal.get_localzone方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: on_result
# 需要导入模块: import tzlocal [as 别名]
# 或者: from tzlocal import get_localzone [as 别名]
def on_result(self, result):
created = result.created.astimezone(get_localzone())
probe_id = result.probe_id
r = []
if result.responses:
for response in result.responses:
r.append(self.get_formatted_response(probe_id,
created, response))
else:
r.append("{}{}\n".format(self.get_header(probe_id, created),
colourise("No response found", "red"),
))
return "".join(r)
示例2: get_scheduled_tasks
# 需要导入模块: import tzlocal [as 别名]
# 或者: from tzlocal import get_localzone [as 别名]
def get_scheduled_tasks(session):
scheduled = session.execute(text("""SELECT id, next_run_time, job_state FROM apscheduler_jobs;"""))
ret = list(scheduled)
now = datetime.datetime.now(get_localzone())
now_utc = datetime_to_utc_timestamp(now)
ret = [(name, ts-now_utc, pickle.loads(value)) for name, ts, value in ret]
for name, ts, value in ret:
then = value['next_run_time'].astimezone(tz=None)
# print((ts, now_utc, then, type(then)))
now = datetime.datetime.now(datetime.timezone.utc)
tgt = then - now
value['time_til_job'] = tgt
return ret
示例3: __init__
# 需要导入模块: import tzlocal [as 别名]
# 或者: from tzlocal import get_localzone [as 别名]
def __init__(self, tz_name=None):
"""
:param str tz_name: The timezone to represent, if not specified it
defaults to the local timezone.
"""
super(Timezone, self).__init__()
if tz_name is None:
tz_name = tzlocal.get_localzone().zone
self.add('tzid', tz_name)
tz_details = parse_tz_posix_env_var(get_tz_posix_env_var(tz_name))
timezone_standard = icalendar.TimezoneStandard()
timezone_standard.add('dtstart', datetime.datetime(1601, 1, 1, 2, 0, tzinfo=dateutil.tz.tzutc()))
timezone_standard.add('tzoffsetfrom', tz_details.offset + datetime.timedelta(0, SECONDS_IN_ONE_HOUR))
timezone_standard.add('tzoffsetto', tz_details.offset)
if tz_details.offset_dst:
timezone_standard.add('rrule', tz_details.dst_end)
timezone_daylight = icalendar.TimezoneDaylight()
timezone_daylight.add('dtstart', datetime.datetime(1601, 1, 1, 2, 0, tzinfo=dateutil.tz.tzutc()))
timezone_daylight.add('tzoffsetfrom', tz_details.offset)
timezone_daylight.add('tzoffsetto', tz_details.offset + datetime.timedelta(0, SECONDS_IN_ONE_HOUR))
timezone_daylight.add('rrule', tz_details.dst_start)
self.add_component(timezone_daylight)
self.add_component(timezone_standard)
示例4: to_notion
# 需要导入模块: import tzlocal [as 别名]
# 或者: from tzlocal import get_localzone [as 别名]
def to_notion(self):
if self.end:
self.start, self.end = sorted([self.start, self.end])
start_date, start_time = self._format_datetime(self.start)
end_date, end_time = self._format_datetime(self.end)
if not start_date:
return []
data = {"type": self.type(), "start_date": start_date}
if end_date:
data["end_date"] = end_date
if "time" in data["type"]:
data["time_zone"] = str(self.timezone or get_localzone())
data["start_time"] = start_time or "00:00"
if end_date:
data["end_time"] = end_time or "00:00"
return [["‣", [["d", data]]]]
示例5: get_time_info
# 需要导入模块: import tzlocal [as 别名]
# 或者: from tzlocal import get_localzone [as 别名]
def get_time_info(ts=None, tz=None):
if ts is None:
ts = time.time()
if tz is None:
tz = tzlocal.get_localzone()
if isinstance(tz, str):
tz = pytz.timezone(tz)
dt = datetime.datetime.fromtimestamp(ts, tz)
time_info = {
'ts': ts,
'string': str(dt),
}
return time_info
示例6: print_plan
# 需要导入模块: import tzlocal [as 别名]
# 或者: from tzlocal import get_localzone [as 别名]
def print_plan(plan):
times = []
if plan.is_time_out:
times.append("*" if plan.second == 0 else "*/%s/%s" % (plan.second, plan.count))
times.append("*" if plan.minute == 0 else "*/%s/%s" % (plan.minute, plan.count))
times.append("*" if plan.hour == 0 else "*/%s/%s" % (plan.hour, plan.count))
times.append("*" if plan.day == 0 else "*/%s/%s" % (plan.day, plan.count))
times.append("*" if plan.month == 0 else "*/%s/%s" % (plan.month, plan.count))
times.append("*" if plan.week == -1 else "*/%s/%s" % (plan.week, plan.count))
else:
times.append("*" if plan.second == -1 else str(plan.second))
times.append("*" if plan.minute == -1 else str(plan.minute))
times.append("*" if plan.hour == -1 else str(plan.hour))
times.append("*" if plan.day == -1 else str(plan.day))
times.append("*" if plan.month == -1 else str(plan.month))
times.append("*" if plan.week == -1 else str(plan.week))
params = ";".join(["%s=%s" % (key, ("'%s'" % value) if isinstance(value, string_type) else value) for key, value in plan.params.items()])
print(str(datetime.datetime.fromtimestamp(plan.next_time).replace(tzinfo=pytz.UTC).astimezone(tzlocal.get_localzone())),
plan.key, " ".join(times), plan.action, '"' + params + '"')
示例7: generate_item
# 需要导入模块: import tzlocal [as 别名]
# 或者: from tzlocal import get_localzone [as 别名]
def generate_item(query, pid):
item, _, state = parse(query)
n = datetime.datetime.now().utcnow()
item["modifiedTime"] = n.strftime("%Y-%m-%dT%H:%M:%S.%f")[:-3] + "+0000"
item["id"] = object_id()
item["status"] = 0
item["timeZone"] = tzlocal.get_localzone().zone
item["content"] = ""
item["sortOrder"] = 0
item["items"] = []
item["progress"] = 0
if state == S_NONE:
item["isAllDay"] = None
else:
item["isAllDay"] = (state & S_TIME == 0)
item["projectId"] = pid
return item
示例8: process_paper_aws
# 需要导入模块: import tzlocal [as 别名]
# 或者: from tzlocal import get_localzone [as 别名]
def process_paper_aws(pmid, start_time_local):
try:
metadata, content_type = get_full_text(pmid, metadata=True)
except Exception as e:
logger.error('Could not get content from S3: %s' % e)
return None, None
logger.info('Downloading %s output from AWS' % pmid)
reach_json_str = get_reader_json_str('reach', pmid)
if not reach_json_str:
logger.info('Could not get output.')
return None, content_type
rp = reach.process_json_str(reach_json_str)
current_time_local = datetime.datetime.now(tzlocal.get_localzone())
dt_script = current_time_local - start_time_local
last_mod_remote = metadata['LastModified']
dt = (current_time_local - last_mod_remote)
# If it was not modified since the script started
if dt > dt_script:
content_type = 'existing_json'
return rp, content_type
示例9: apply_timezone_from_settings
# 需要导入模块: import tzlocal [as 别名]
# 或者: from tzlocal import get_localzone [as 别名]
def apply_timezone_from_settings(date_obj, settings):
tz = get_localzone()
if settings is None:
return date_obj
if 'local' in settings.TIMEZONE.lower():
date_obj = tz.localize(date_obj)
else:
date_obj = localize_timezone(date_obj, settings.TIMEZONE)
if settings.TO_TIMEZONE:
date_obj = apply_timezone(date_obj, settings.TO_TIMEZONE)
if settings.RETURN_AS_TIMEZONE_AWARE is not True:
date_obj = date_obj.replace(tzinfo=None)
return date_obj
示例10: get_time_offset
# 需要导入模块: import tzlocal [as 别名]
# 或者: from tzlocal import get_localzone [as 别名]
def get_time_offset(self, latest_date):
'''
get time offset based on auto_offset or hour_offset
'''
if auto_offset is not None:
local_date = datetime.now(timezone(str(get_localzone())))
himawari_date = datetime.now(timezone('Asia/Shanghai'))
local_offset = local_date.strftime("%z")
himawari_offset = himawari_date.strftime("%z")
offset = int(local_offset) - int(himawari_offset)
offset /= 100
offset_tmp = datetime.fromtimestamp(mktime(latest_date))
offset_tmp += timedelta(hours=offset)
offset_time = offset_tmp.timetuple()
elif hour_offset > 0:
offset_tmp = datetime.fromtimestamp(mktime(latest_date))
offset_tmp -= timedelta(hours=hour_offset)
offset_time = offset_tmp.timetuple()
return offset_time
示例11: send_daemon_status
# 需要导入模块: import tzlocal [as 别名]
# 或者: from tzlocal import get_localzone [as 别名]
def send_daemon_status(self):
"""
Send the daemon status to the client.
"""
p = psutil.Process(os.getpid())
uptime = relativedelta(datetime.now(), self.controller.start_time)
uptime = pprint_relativedelta(uptime)
uptime = ' '.join(uptime.split()[:-1])
if not uptime:
uptime = '0m'
msg = {
'type': 'DAEMON_STATUS',
'memoryUsage': int(float(p.memory_info().rss) / 1024. / 1024.),
'cpuUsage': p.cpu_percent(),
'time': int(calendar.timegm(time.gmtime())),
'timezone': str(get_localzone()),
'hostname': socket.gethostname(),
'uptime': uptime,
'daemonVersion': __version__,
}
self.send_json(msg)
#---------------------------------------------------------------------------
示例12: on_result
# 需要导入模块: import tzlocal [as 别名]
# 或者: from tzlocal import get_localzone [as 别名]
def on_result(self, result):
created = result.created.astimezone(get_localzone())
r = self.get_formatted_response(result)
if not r:
r = colourise('No results\n', 'red')
return "\n{}\n{}\n\n{}".format(
colourise("Probe #{}".format(result.probe_id), "bold"),
colourise(created.strftime(self.TIME_FORMAT), "bold"),
r
)
示例13: on_result
# 需要导入模块: import tzlocal [as 别名]
# 或者: from tzlocal import get_localzone [as 别名]
def on_result(self, result):
created = result.created.astimezone(get_localzone())
probe_id = result.probe_id
r = "\n\nProbe #{0}\n{1}\n".format(probe_id, "=" * 79)
if result.responses:
for response in result.responses:
r += self.get_formatted_response(probe_id, created, response)
else:
r += "\n {}\n".format(colourise("No response found", "red"))
return r
示例14: on_result
# 需要导入模块: import tzlocal [as 别名]
# 或者: from tzlocal import get_localzone [as 别名]
def on_result(self, result):
r = ""
for certificate in result.certificates:
r += self.get_formatted_response(certificate)
created = result.created.astimezone(get_localzone())
return "\n{}\n{}\n{}\n".format(
colourise("Probe #{}".format(result.probe_id), "bold"),
colourise(created.strftime(self.TIME_FORMAT), "bold"),
r
)
示例15: get_timezone
# 需要导入模块: import tzlocal [as 别名]
# 或者: from tzlocal import get_localzone [as 别名]
def get_timezone(timezone=None):
"""Gets, or uses the session timezone or use the local computer's timezone."""
try:
tz = 'UTC' if not timezone else timezone
return pytz.timezone(tz)
except pytz.exceptions.UnknownTimeZoneError:
logger.warning('converting to tzinfo failed')
if tzlocal is not None:
return tzlocal.get_localzone()
else:
try:
return datetime.datetime.timezone.utc
except AttributeError:
return pytz.timezone('UTC')