最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Python 京東云無線寶消息推送功能

 更新時間:2021年05月20日 14:30:22   作者:Alex_Mercer  
這篇文章主要介紹了Python 京東云無線寶消息推送功能,發(fā)送釘釘消息獲取可用積分,詳細配置文件通過實例代碼給大家講解的很詳細,代碼+注釋講解的很詳細,需要的朋友可以參考下

配置文件

注釋里面有寫,懶得用配置文件了

代碼

# 京東云無線路由寶推送
import requests
import json
import time
import hmac
import hashlib
import base64
import urllib.parse
from datetime import datetime
# 發(fā)送釘釘消息
def sendinfo_ding(token,secret,data):
    dic=get_timestamp_and_sign_by_secret(secret)
    timestamp=dic['timestamp']
    sign=dic['sign']
    url = 'https://oapi.dingtalk.com/robot/send?access_token=%s&timestamp=%s&sign=%s' %(token,timestamp,sign)  #你的機器人webhook地址
    headers = {'Content-Type': 'application/json'}
    f = requests.post(url, data=json.dumps(data), headers=headers)
# 獲取密簽
def get_timestamp_and_sign_by_secret(secret):
    timestamp = str(round(time.time() * 1000))
    secret_enc = secret.encode('utf-8')
    string_to_sign = '{}\n{}'.format(timestamp, secret)
    string_to_sign_enc = string_to_sign.encode('utf-8')
    hmac_code = hmac.new(secret_enc, string_to_sign_enc, digestmod=hashlib.sha256).digest()
    sign = urllib.parse.quote_plus(base64.b64encode(hmac_code))
    return {"timestamp":timestamp,"sign":sign}
# 獲取可用積分
def get_jd_total_avail_point(wskey):
    url='https://router-app-api.jdcloud.com/v1/regions/cn-north-1/pinTotalAvailPoint'
    headers = {'Content-Type': 'application/json','wskey':wskey}
    rsp=requests.get(url,headers=headers)
    data=(json.loads(rsp.text)['result']['totalAvailPoint'])
    return {'totalAvailPoint':data}
# 獲取積分詳情
def get_jd_detail(wskey):
    url='https://router-app-api.jdcloud.com/v1/regions/cn-north-1/todayPointDetail?sortField=today_point&sortDirection=DESC&pageSize=15&currentPage=1'
    headers = {'Content-Type': 'application/json','wskey':wskey}
    rsp=requests.get(url,headers=headers)
    data=(json.loads(rsp.text)['result'])
    items=data['pointInfos']
    total_today_point=0
    total_all_point=0
    dic={}
    dic['todayDate']=data['todayDate']
    dic['items']=[]
    for item in items:
        mac=item['mac']
        today_point=item['todayPointIncome']
        all_point=item['allPointIncome']
        total_today_point+=int(today_point)
        total_all_point+=int(all_point)
        dic['items'].append(item)
    dic['total_today_point']=total_today_point
    dic['total_all_point']=total_all_point
    return dic
# 發(fā)送京東路由寶日報
def send_jd_router(wskey):
    dic=get_jd_detail(wskey)
    msg='# 京東路由寶日報\n'
    msg+='## %s \n' %(dic['todayDate'])
    msg+=('> 今日獲取總積分為**%d**分,對應(yīng)金錢為 **%.2f**元\n' %(dic['total_today_point'],float(dic['total_today_point'])/100))
    for item in dic['items']:
        msg+=('>> 設(shè)備**%s** \n' %(item['mac']))
        msg+=('>>> 今日獲取積分為**%s**分,對應(yīng)金錢為 **%.2f**元 \n\n' %(item['todayPointIncome'],float(item['todayPointIncome'])/100))
    msg+=('> 累計總積分為 **%s** 分,對應(yīng)金錢 **%.2f** 元 \n\n' %(dic['total_all_point'],float(dic['total_all_point'])/100))
    dic=get_jd_total_avail_point(wskey)
    msg+=('> 目前可用積分為 **%s** 分,對應(yīng)金錢 **%.2f** 元' %(dic['totalAvailPoint'],float(dic['totalAvailPoint'])/100))

    # token=""
    # secret=""
    # data = {
    #     "msgtype": "markdown",
    #     "markdown": {
    #         "title":"京東云路由寶日報",
    #         "text": msg
    #         },
    # }
    # sendinfo_ding(token,secret,data)
    
    # 更改server醬發(fā)送
    server_send_wechat('京東路由寶日報',msg)

#Server醬發(fā)送微信
def server_send_wechat(text,desp=''):
    # Server醬 Key
    key=''
    url=('https://sc.ftqq.com/%s.send' %key)
    params={
        'text':text,
        'desp':desp
    }
    requests.get(url,params)

# 更改為配置文件獲取 todo
wskey=''
while True:
    now = datetime.now()
    print("任務(wù)執(zhí)行的時間為:"+datetime.strftime(now,"%Y-%m-%d:%H:%M:%S"))
    if now.hour==8 and now.minute==0:
        send_jd_router(wskey)
    time.sleep(60)

知識點擴展:Python編程之微信推送模板消息功能示例

本文實例講述了Python微信推送模板消息功能。分享給大家供大家參考,具體如下:

具體代碼如下:

#!/usr/bin/env python

#-*- coding: utf-8 -*-

import httplib

import json

import MySQLdb

#從數(shù)據(jù)庫中獲取access_token

access_token=""

try:

conn=MySQLdb.connect(host='192.168.1.1',user='root',passwd='root',db='db_weixin',port=3306)

cur=conn.cursor()

cur.execute('select access_token from weixin_public')

result=cur.fetchone()

#print result

#print result[0]

access_token=result[0]

cur.close()

conn.close()

except MySQLdb.Error,e:

print "Mysql Error %d: %s" % (e.args[0], e.args[1])

#根據(jù)接口推送消息

if not access_token is None:

conn = httplib.HTTPConnection("api.weixin.qq.com:80")#微信接口鏈接

headers = {"Content-type":"application/json"} #application/x-www-form-urlencoded

params = ({'touser' : "oEGZ4johnKOtayJbnEVeuaZr6zQ0",#用戶openid

'template_id' : 'AtFuydv8k_15UGZuFntaBzJRCsHCkjNm1dcWD3A-11Y',#模板消息ID

'url' : 'http://m.fzitv.net',#跳轉(zhuǎn)鏈接

"topcolor" : "#667F00",#顏色

"data" : {#模板內(nèi)容

"first" : {"value" : "尊敬的710.so : 您的網(wǎng)站http://m.fzitv.net (192.168.1.1) 有異常訪問", "color" : "#173177"},

"keyword1" : {"value" : "訪問時間 2015-04-05 15:30:59 訪問IP 192.168.1.2", "color" : "#173177"},

"keyword2" : {"value" : "訪問鏈接 http://m.fzitv.net", "color" : "#173177"},

"remark" : {"value" : "訪問頻率 10/s", "color" : "#173177"}

}

}

)

conn.request("POST", "/cgi-bin/message/template/send?access_token="+access_token, json.JSONEncoder().encode(params), headers)#推送消息請求

response = conn.getresponse()

data = response.read()#推送返回數(shù)據(jù)

if response.status == 200:

print 'success'

print data

else:

print 'fail'

conn.close()

希望本文所述對大家Python程序設(shè)計有所幫助。

以上就是Python 京東云無線寶消息推送的詳細內(nèi)容,更多關(guān)于Python 京東云無線寶推送的資料請關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • Python中切片操作的示例詳解

    Python中切片操作的示例詳解

    在剛學(xué)python時候,我們都知道字符串(String)、列表(list)和元組(tuple)序列化數(shù)據(jù)類型支持切片操作。本文我們將對熟悉的切片操作進行系統(tǒng)學(xué)習(xí),感興趣的可以了解一下
    2022-11-11
  • 用python自動生成日歷

    用python自動生成日歷

    這篇文章主要介紹了如何用python自動生成日歷,幫助大家更好的理解和學(xué)習(xí)使用python,感興趣的朋友可以了解下
    2021-04-04
  • Python計算當(dāng)前日期是一年中的第幾天的方法詳解

    Python計算當(dāng)前日期是一年中的第幾天的方法詳解

    在Python中,計算當(dāng)前日期是一年中的第幾天可以通過內(nèi)置的datetime模塊來實現(xiàn),本文將詳細介紹如何使用Python編寫代碼來完成這個任務(wù),需要的可以參考下
    2023-12-12
  • Python3利用scapy局域網(wǎng)實現(xiàn)自動多線程arp掃描功能

    Python3利用scapy局域網(wǎng)實現(xiàn)自動多線程arp掃描功能

    這篇文章主要介紹了Python3利用scapy局域網(wǎng)實現(xiàn)自動多線程arp掃描功能,本文給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2021-01-01
  • Python批量將csv文件編碼方式轉(zhuǎn)換為UTF-8的實戰(zhàn)記錄

    Python批量將csv文件編碼方式轉(zhuǎn)換為UTF-8的實戰(zhàn)記錄

    近日在處理數(shù)據(jù)的時候發(fā)現(xiàn)有的文件為csv文件,Xiam 這篇文章主要給大家介紹了關(guān)于利用Python批量將csv文件編碼方式轉(zhuǎn)換為UTF-8的相關(guān)資料,文中通過示例代碼介紹的非常詳細,需要的朋友可以參考下
    2022-07-07
  • pytorch 如何使用amp進行混合精度訓(xùn)練

    pytorch 如何使用amp進行混合精度訓(xùn)練

    這篇文章主要介紹了pytorch 使用amp進行混合精度訓(xùn)練的操作,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2021-05-05
  • python輸出帶有顏色字體的三種方法

    python輸出帶有顏色字體的三種方法

    在使用python運維與開發(fā)的過程中,經(jīng)常需要打印顯示各種信息,海量的信息堆砌在控制臺中,就會導(dǎo)致各種信息都顯示在一起,降低了重要信息的可讀性,這時候如果能給重要的信息加上差異的字體顏色,那么就會更加顯眼,所以本文給大家介紹了python輸出帶有顏色文字的三種方法
    2024-05-05
  • 解讀卷積神經(jīng)網(wǎng)絡(luò)的人臉識別

    解讀卷積神經(jīng)網(wǎng)絡(luò)的人臉識別

    這篇文章主要介紹了解讀卷積神經(jīng)網(wǎng)絡(luò)的人臉識別問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-11-11
  • python 基于Appium控制多設(shè)備并行執(zhí)行

    python 基于Appium控制多設(shè)備并行執(zhí)行

    這篇文章主要介紹了python 如何基于Appium控制多設(shè)備并行執(zhí)行,幫助大家更好的理解和學(xué)習(xí)使用python,感興趣的朋友可以了解下
    2021-03-03
  • python實現(xiàn)txt文件格式轉(zhuǎn)換為arff格式

    python實現(xiàn)txt文件格式轉(zhuǎn)換為arff格式

    這篇文章主要為大家詳細介紹了python實現(xiàn)txt文件格式轉(zhuǎn)換為arff格式的方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-05-05

最新評論

平塘县| 方城县| 扎鲁特旗| 桐柏县| 崇左市| 汝南县| 林州市| 闽清县| 环江| 莎车县| 东台市| 镇康县| 星子县| 哈巴河县| 哈巴河县| 北安市| 宣恩县| 陆良县| 尉犁县| 镇原县| 寿阳县| 交口县| 营口市| 肇州县| 张家口市| 都昌县| 利津县| 睢宁县| 交城县| 兴安盟| 靖江市| 唐海县| 鹤峰县| 库伦旗| 临武县| 西峡县| 涿鹿县| 资源县| 塘沽区| 桐乡市| 昌宁县|