Python IDchat 微信介面發訊息1

2021-09-24 13:04:02 字數 4412 閱讀 2496

1號程式

import itchat

import datetime

import time

import requests

itchat.auto_login(hotreload = true)

users1 = itchat.search_friends(name=u'某人') #查詢好友名字

users2 = itchat.search_chatrooms(name=u'某群') #查詢好友名字

username1 = users1[0]['username'] #獲取名字

username2 = users2[0]['username'] #獲取名字

def get_news():

url = "" #天氣資訊** 101200401孝感

r = requests.get(url) #get函式

r.encoding = 'utf-8' #轉碼utf-8

#total = r.json()

#print(total)

city = r.json()['weatherinfo']['city']

# humidity = r.json()['data']['shidu']

# pm25 = r.json()['data']['pm25']

# airquality = r.json()['data']['quality']

# temperature = r.json()['data']['wendu']

hightem = r.json()['weatherinfo']['temp2']

lowtem = r.json()['weatherinfo']['temp1']

type = r.json()['weatherinfo']['weather']

#print(city,hightem, lowtem, type)

return city,hightem,lowtem,type

while 1:

now = datetime.datetime.now()

now_str = now.strftime('%y%m%d %h:%m')[11:] #時間前11位數

now_time = time.strftime('%y-%m-%d %h:%m:%s',time.localtime()) #讀取時間

#print(now)

print(now_str) #輸出計時

city = str(get_news()[0]) #城市

hightem = str(get_news()[1]) # 高溫

lowtem = str(get_news()[2]) # 低溫

#now_date = str(get_news()[3]) # 日期

#week = str(get_news()[4]) # 星期

#wind = str(get_news()[5]) # 風向

#windspeed = str(get_news()[6]) # 風速

type = str(get_news()[3]) # 天氣型別

#notice = str(get_news()[8]) # 小提示

if now_str in ['/19 22:59']: #判斷時間點

itchat.send(now_time+' 早上好!', tousername=username1)

itchat.send(city+' '+lowtem+'~'+hightem+' '+type, tousername=username1)

itchat.send(now_time+' 早上好!', tousername=username2)

itchat.send(city+' '+lowtem+'~'+hightem+' '+type, tousername=username2)

#itchat.send(content, tousername=username)

#itchat.send(editor, tousername=username)

#itchat.send(imag, tousername=username)

time.sleep(55)

if __name__ == '__main__':

itchat.auto_login()

itchat.run()

2號程式

import itchat

import datetime

import time

import requests

itchat.auto_login(hotreload = true)

users1 = itchat.search_friends(name=u'xx') #查詢好友名字

username1 = users1[0]['username'] #獲取名字

def get_news():

url = "" #天氣資訊**

r = requests.get(url) #get函式

# r.encoding = 'utf-8' #轉碼utf-8

total = r.json()

city = r.json()['cityinfo']['city']

# humidity = r.json()['data']['shidu']

# pm25 = r.json()['data']['pm25']

# airquality = r.json()['data']['quality']

# temperature = r.json()['data']['wendu']

hightem = r.json()['data']['forecast'][0]['high']

lowtem = r.json()['data']['forecast'][0]['low']

now_date = r.json()['data']['forecast'][0]['ymd']

week = r.json()['data']['forecast'][0]['week']

wind = r.json()['data']['forecast'][0]['fx']

windspeed = r.json()['data']['forecast'][0]['fl']

type = r.json()['data']['forecast'][0]['type']

notice = r.json()['data']['forecast'][0]['notice']

#print(city,hightem, lowtem, now_date, week, wind, windspeed, type, notice)

return city,hightem, lowtem, now_date, week, wind, windspeed, type, notice

while 1:

now = datetime.datetime.now()

now_str = now.strftime('%y%m%d %h:%m')[11:] #時間前11位數

now_time = time.strftime('%y-%m-%d %h:%m:%s',time.localtime()) #讀取時間

#print(now)

print(now_str) #輸出計時

city = str(get_news()[0]) #城市

hightem = str(get_news()[1]) # 高溫

lowtem = str(get_news()[2]) # 低溫

now_date = str(get_news()[3]) # 日期

week = str(get_news()[4]) # 星期

wind = str(get_news()[5]) # 風向

windspeed = str(get_news()[6]) # 風速

type = str(get_news()[7]) # 天氣型別

notice = str(get_news()[8]) # 小提示

if now_str in ['/19 07:00']: #判斷時間點

itchat.send(now_time+' '+week+' 早上好!', tousername=username1)

itchat.send(city+' '+hightem+' '+lowtem+'\n'+type+' '+wind+' '+windspeed+' '+notice, tousername=username1)

time.sleep(50)

if __name__ == '__main__':

itchat.auto_login()

itchat.run()

實時微信網域名稱監控通知 微信網域名稱檢測API介面分享

請求方式 http get post 返回格式 json 請求示例 http json返回示例 網域名稱正常 網域名稱已 php url params array url www.monkeyapi.com 需要查詢的 請求介面返回內容 param string url 請求的url位址 param...

微信支付app支付3 0介面開發

123 4567 步驟5 商戶後台接收支付通知。api參見 支付結果通知api 步驟6 商戶後台查詢支付結果。api參見 查詢訂單api 服務端要做的,就是步驟1235,客戶端做步驟4就行了,步驟6看自己的需求,我們沒有做.首先,生成商戶伺服器訂單,這個自不必說,只有生成訂單,才有訂單號,才能做後面...

微信公眾平台設定URL和Token接收介面事件推送

字典排序 string tmpstr string.join arrtmp tmpstr formsauthentication.hashpasswordforstoringinconfigfile tmpstr,sha1 tmpstr tmpstr.tolower if tmpstr signat...