當前位置: 首頁>>代碼示例>>Python>>正文


Python tzlocal.get_localzone方法代碼示例

本文整理匯總了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) 
開發者ID:RIPE-NCC,項目名稱:ripe-atlas-tools,代碼行數:18,代碼來源:dns_compact.py

示例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 
開發者ID:fake-name,項目名稱:ReadableWebProxy,代碼行數:22,代碼來源:status_view.py

示例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) 
開發者ID:rsmusllp,項目名稱:king-phisher,代碼行數:27,代碼來源:ics.py

示例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]]]] 
開發者ID:jamalex,項目名稱:notion-py,代碼行數:25,代碼來源:collection.py

示例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 
開發者ID:bsc-s2,項目名稱:pykit,代碼行數:20,代碼來源:jobscheduler.py

示例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 + '"') 
開發者ID:snower,項目名稱:forsun,代碼行數:23,代碼來源:forsun.py

示例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 
開發者ID:jedy,項目名稱:alfred-tick,代碼行數:20,代碼來源:tick.py

示例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 
開發者ID:sorgerlab,項目名稱:indra,代碼行數:23,代碼來源:machine.py

示例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 
開發者ID:scrapinghub,項目名稱:dateparser,代碼行數:19,代碼來源:__init__.py

示例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 
開發者ID:ujnzxw,項目名稱:oh-my-earth,代碼行數:25,代碼來源:manage_earth.py

示例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)

    #--------------------------------------------------------------------------- 
開發者ID:ljanyst,項目名稱:scrapy-do,代碼行數:26,代碼來源:websocket.py

示例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
        ) 
開發者ID:RIPE-NCC,項目名稱:ripe-atlas-tools,代碼行數:12,代碼來源:ntp.py

示例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 
開發者ID:RIPE-NCC,項目名稱:ripe-atlas-tools,代碼行數:15,代碼來源:dns.py

示例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
        ) 
開發者ID:RIPE-NCC,項目名稱:ripe-atlas-tools,代碼行數:12,代碼來源:sslcert.py

示例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') 
開發者ID:snowflakedb,項目名稱:snowflake-connector-python,代碼行數:16,代碼來源:test_unit_arrow_chunk_iterator.py


注:本文中的tzlocal.get_localzone方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。