本文整理汇总了Python中pytz.utc方法的典型用法代码示例。如果您正苦于以下问题:Python pytz.utc方法的具体用法?Python pytz.utc怎么用?Python pytz.utc使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pytz
的用法示例。
在下文中一共展示了pytz.utc方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: extract_context
# 需要导入模块: import pytz [as 别名]
# 或者: from pytz import utc [as 别名]
def extract_context(html, url):
soup = BeautifulSoup(html)
# Insert into Content (under this domain)
texts = soup.findAll(text=True)
try:
Content.objects.create(
url=url,
title=soup.title.string,
summary=helpers.strip_tags(" \n".join(filter(visible, texts)))[:4000],
last_crawled_at=datetime.datetime.utcnow().replace(tzinfo=pytz.utc)
)
except IntegrityError:
println('%s - already existed in Content' % url)
soup.prettify()
return [str(anchor['href'])
for anchor in soup.findAll('a', attrs={'href': re.compile("^http://")}) if anchor['href']]
示例2: get_timestamp_from_date_string
# 需要导入模块: import pytz [as 别名]
# 或者: from pytz import utc [as 别名]
def get_timestamp_from_date_string(date_string):
""" parse a date string into unix epoch (ms) """
if 'strip_tz' in agent_config_vars and agent_config_vars['strip_tz']:
date_string = ''.join(PCT_z_FMT.split(date_string))
if 'timestamp_format' in agent_config_vars:
if agent_config_vars['timestamp_format'] == 'epoch':
timestamp_datetime = get_datetime_from_unix_epoch(date_string)
else:
timestamp_datetime = datetime.strptime(date_string, agent_config_vars['timestamp_format'])
else:
try:
timestamp_datetime = dateutil.parse.parse(date_string)
except e:
timestamp_datetime = get_datetime_from_unix_epoch(date_string)
agent_config_vars['timestamp_format'] = 'epoch'
timestamp_localize = cli_config_vars['time_zone'].localize(timestamp_datetime)
epoch = long((timestamp_localize - datetime(1970, 1, 1, tzinfo=pytz.utc)).total_seconds()) * 1000
return epoch
示例3: get_timestamp_from_date_string
# 需要导入模块: import pytz [as 别名]
# 或者: from pytz import utc [as 别名]
def get_timestamp_from_date_string(date_string):
""" parse a date string into unix epoch (ms) """
if 'strip_tz' in agent_config_vars and agent_config_vars['strip_tz']:
date_string = ''.join(agent_config_vars['strip_tz_fmt'].split(date_string))
if 'timestamp_format' in agent_config_vars:
if agent_config_vars['timestamp_format'] == 'epoch':
timestamp_datetime = get_datetime_from_unix_epoch(date_string)
else:
timestamp_datetime = datetime.strptime(date_string, agent_config_vars['timestamp_format'])
else:
try:
timestamp_datetime = dateutil.parse.parse(date_string)
except:
timestamp_datetime = get_datetime_from_unix_epoch(date_string)
agent_config_vars['timestamp_format'] = 'epoch'
timestamp_localize = cli_config_vars['time_zone'].localize(timestamp_datetime)
epoch = long((timestamp_localize - datetime(1970, 1, 1, tzinfo=pytz.utc)).total_seconds()) * 1000
return epoch
示例4: get_timestamp_from_date_string
# 需要导入模块: import pytz [as 别名]
# 或者: from pytz import utc [as 别名]
def get_timestamp_from_date_string(date_string):
""" parse a date string into unix epoch (ms) """
if 'strip_tz' in agent_config_vars and agent_config_vars['strip_tz']:
date_string = ''.join(agent_config_vars['strip_tz_fmt'].split(date_string))
if 'timestamp_format' in agent_config_vars:
if agent_config_vars['timestamp_format'] == 'epoch':
timestamp_datetime = get_datetime_from_unix_epoch(date_string)
else:
timestamp_datetime = datetime.strptime(date_string, agent_config_vars['timestamp_format'])
else:
try:
timestamp_datetime = dateutil.parse.parse(date_string)
except e:
timestamp_datetime = get_datetime_from_unix_epoch(date_string)
agent_config_vars['timestamp_format'] = 'epoch'
timestamp_localize = cli_config_vars['time_zone'].localize(timestamp_datetime)
epoch = long((timestamp_localize - datetime(1970, 1, 1, tzinfo=pytz.utc)).total_seconds()) * 1000
return epoch
示例5: get_timestamp_from_date_string
# 需要导入模块: import pytz [as 别名]
# 或者: from pytz import utc [as 别名]
def get_timestamp_from_date_string(date_string):
""" parse a date string into unix epoch (ms) """
if 'timestamp_format' in agent_config_vars:
if agent_config_vars['timestamp_format'] == 'epoch':
timestamp_datetime = get_datetime_from_unix_epoch(date_string)
else:
timestamp_datetime = datetime.strptime(date_string, agent_config_vars['timestamp_format'])
else:
try:
timestamp_datetime = dateutil.parse.parse(date_string)
except e:
timestamp_datetime = get_datetime_from_unix_epoch(date_string)
agent_config_vars['timestamp_format'] = 'epoch'
timestamp_localize = cli_config_vars['time_zone'].localize(timestamp_datetime)
epoch = long((timestamp_localize - datetime(1970, 1, 1, tzinfo=pytz.utc)).total_seconds()) * 1000
return epoch
示例6: get_timestamp_from_date_string
# 需要导入模块: import pytz [as 别名]
# 或者: from pytz import utc [as 别名]
def get_timestamp_from_date_string(date_string):
""" parse a date string into unix epoch (ms) """
if 'strip_tz' in agent_config_vars and agent_config_vars['strip_tz']:
date_string = ''.join(agent_config_vars['strip_tz_fmt'].split(date_string))
if 'timestamp_format' in agent_config_vars:
if agent_config_vars['timestamp_format'] == 'epoch':
timestamp_datetime = get_datetime_from_unix_epoch(date_string)
else:
timestamp_datetime = datetime.strptime(date_string, agent_config_vars['timestamp_format'])
else:
try:
timestamp_datetime = dateutil.parse.parse(date_string)
except:
timestamp_datetime = get_datetime_from_unix_epoch(date_string)
agent_config_vars['timestamp_format'] = 'epoch'
timestamp_localize = cli_config_vars['time_zone'].localize(timestamp_datetime)
epoch = long((timestamp_localize - datetime(1970, 1, 1, tzinfo=pytz.utc)).total_seconds()) * 1000
return epoch
示例7: parseATTime
# 需要导入模块: import pytz [as 别名]
# 或者: from pytz import utc [as 别名]
def parseATTime(s, tzinfo=None):
if tzinfo is None:
tzinfo = pytz.utc
s = s.strip().lower().replace('_', '').replace(',', '').replace(' ', '')
if s.isdigit():
if len(s) == 8 and int(s[:4]) > 1900 and int(
s[4:6]) < 13 and int(s[6:]) < 32:
pass # Fall back because its not a timestamp, its YYYYMMDD form
else:
return datetime.fromtimestamp(int(s), tzinfo)
elif ':' in s and len(s) == 13:
return tzinfo.localize(datetime.strptime(s, '%H:%M%Y%m%d'), daylight)
if '+' in s:
ref, offset = s.split('+', 1)
offset = '+' + offset
elif '-' in s:
ref, offset = s.split('-', 1)
offset = '-' + offset
else:
ref, offset = s, ''
return (
parseTimeReference(ref) +
parseTimeOffset(offset)).astimezone(tzinfo)
示例8: form_valid
# 需要导入模块: import pytz [as 别名]
# 或者: from pytz import utc [as 别名]
def form_valid(self, form):
user = self.user
user.backend = 'django.contrib.auth.backends.ModelBackend'
user.is_email_verified = True
user.is_active = True
user.save()
email_token = self.email_token
email_token.verified_from_ip = get_client_ip(self.request)
email_token.verified_at = datetime.datetime.utcnow().replace(tzinfo=pytz.utc)
email_token.save()
login(self.request, user)
messages.add_message(
message=_('Thank you for verifying your Email address, you are now logged in.'),
request=self.request,
level=messages.SUCCESS
)
return redirect(self.get_success_url())
示例9: union
# 需要导入模块: import pytz [as 别名]
# 或者: from pytz import utc [as 别名]
def union(p, q):
for url in p:
parsed = urlparse(str(url))
if parsed.netloc and parsed.netloc != 'www.webhostingtalk.com':
url = 'http://%s/' % parsed.netloc
if parsed.netloc and url not in q:
print url
if parsed.netloc != 'www.webhostingtalk.com':
# Insert into Site
try:
Website.objects.create(
url=url,
name=parsed.netloc,
last_crawled_at=datetime.datetime.utcnow().replace(tzinfo=pytz.utc)
)
except IntegrityError:
println('%s - already existed in Site' % url)
else:
# We want to deep crawl webhosting talk
q.append(url)
示例10: check_validity
# 需要导入模块: import pytz [as 别名]
# 或者: from pytz import utc [as 别名]
def check_validity(not_before, not_after, expire_early):
"""
Check validity dates.
If not_before is in the past, and not_after is in the future,
return True, otherwise raise an Exception explaining the problem.
If expire_early is passed, an exception will be raised if the
not_after date is too soon in the future.
"""
now = datetime.utcnow().replace(tzinfo=pytz.utc)
if not_before > not_after:
raise BadCertificate(f"not_before ({not_before}) after not_after ({not_after})")
if now < not_before:
raise CertificateNotYetValid(not_before)
if now > not_after:
raise CertificateExpired(not_after)
if expire_early:
if now + expire_early > not_after:
raise CertificateExpiringSoon(expire_early)
return True
示例11: _pre_TIMESTAMP_LTZ_to_python
# 需要导入模块: import pytz [as 别名]
# 或者: from pytz import utc [as 别名]
def _pre_TIMESTAMP_LTZ_to_python(self, value, ctx) -> datetime:
"""Converts TIMESTAMP LTZ to datetime.
This takes consideration of the session parameter TIMEZONE if available. If not, tzlocal is used.
"""
microseconds, fraction_of_nanoseconds = _extract_timestamp(value, ctx)
tzinfo_value = self._get_session_tz()
try:
t0 = ZERO_EPOCH + timedelta(seconds=microseconds)
t = pytz.utc.localize(t0, is_dst=False).astimezone(tzinfo_value)
return t, fraction_of_nanoseconds
except OverflowError:
logger.debug(
"OverflowError in converting from epoch time to "
"timestamp_ltz: %s(ms). Falling back to use struct_time."
)
return time.localtime(microseconds), fraction_of_nanoseconds
示例12: get_timestamp_for_zone
# 需要导入模块: import pytz [as 别名]
# 或者: from pytz import utc [as 别名]
def get_timestamp_for_zone(date_string, time_zone, datetime_format):
dtexif = datetime.strptime(date_string, datetime_format)
tz = pytz.timezone(time_zone)
tztime = tz.localize(dtexif)
epoch = long((tztime - datetime(1970, 1, 1, tzinfo=pytz.utc)).total_seconds()) * 1000
return epoch
示例13: get_timestamp_from_datetime
# 需要导入模块: import pytz [as 别名]
# 或者: from pytz import utc [as 别名]
def get_timestamp_from_datetime(timestamp_datetime):
timestamp_localize = cli_config_vars['time_zone'].localize(timestamp_datetime)
epoch = long((timestamp_localize - datetime(1970, 1, 1, tzinfo=pytz.utc)).total_seconds()) * 1000
return epoch
示例14: get_timestamp_from_datetime
# 需要导入模块: import pytz [as 别名]
# 或者: from pytz import utc [as 别名]
def get_timestamp_from_datetime(timestamp_datetime):
timestamp_localize = agent_config_vars['timezone'].localize(timestamp_datetime)
epoch = long((timestamp_localize - datetime(1970, 1, 1, tzinfo=pytz.utc)).total_seconds()) * 1000
return epoch
示例15: get_gmt_timestamp
# 需要导入模块: import pytz [as 别名]
# 或者: from pytz import utc [as 别名]
def get_gmt_timestamp(date_string, datetime_format):
if datetime_format == Constant.NONE:
return long(date_string)
struct_time = datetime.strptime(date_string, datetime_format)
time_by_zone = pytz.timezone(Constant.GMT).localize(struct_time)
epoch = long((time_by_zone - datetime(1970, 1, 1, tzinfo=pytz.utc)).total_seconds()) * 1000
return epoch