企業微信機械人 獲取當前天氣

2022-08-10 04:09:13 字數 1770 閱讀 2386

import requests

import json

import time

# address = input() # 輸入要查詢的位址

address = '湘潭市湖南科技大學'

# 獲取輸入位址的經緯度

map_url = '' + address + '&key=' + map_key

map_response = requests.get(map_url)

map_json = json.loads(map_response.text)

latitude = str(map_json['result']['location']['lat'])

longitude = str(map_json['result']['location']['lng'])

# print(address + longitude + latitude)

# 根據經緯度查詢天氣

api_key = '彩雲天氣api key' # api秘鑰

json_response = requests.get(json_url)

json_str = json.loads(json_response.text)

timestamp = json_str['server_time']

localtime = time.localtime(timestamp)

formattime = time.strftime("%y%m%d %h%m%s").format(y='年', m='月', d='日', c='點', mi='分', s='秒')

temperature = str(json_str['result']['temperature']) # 氣溫

humidity = json_str['result']['humidity'] # 濕度

skyconndition = str(json_str['result']['skycon']) # 天氣狀況

weatherdic =

skyconndition = weatherdic[skyconndition] # 匹配**與文字

aqi = str(json_str['result']['aqi']) # 空氣質素指數

if int(aqi) >= 200:

aqi = '200 \n霧霾天要少出去玩哦'

# pm25 = str(json_str['result']['pm25'])

real_humidity = str(humidity * 100)

current_weather = address + '\n北緯' + str(latitude) + ' 東經' + str(

print(current_weather)

def weather():

headers =

# 蘇寧介面獲取時間

# timeurl = ''

# timeresponse = requests.get(timeurl)

# timejson = json.loads(timeresponse.text)

# severtime = timejson['systime2'] # 2020-02-21 12:26:12

s = current_weather

data =

}r = requests.post(

headers=headers, json=data)

print(r.text)

weather()

微信機械人扯淡聊天

這裡我用了簡單的別人開發的機械人介面,也可以使用比較強大點的機械人,比如小黃雞機械人,也僅僅是簡單的文字訊息,後面會加上一些豐富的表情和 我使用了php curl擴充套件,當然用php自帶函式get file content和socket同樣可以 我將這個功能放到了 robot.php 如下 cur...

c 做微信機械人

本節主要說下hook的原理,其實hook分很多種,我們最說的hook就是 inline hook,是用的最廣泛的也是自由度最大的,相交於其他hook 比如有 apihook 訊息hook 等等hook,他們都有侷限性,apihook只能hook windows 的api 訊息,他們侷限性太大了,所以...

微信聊天機械人

import arrow import itchat import pydash import requests deflocal datetime 格式化的時間戳 return arrow.now format yyyy mm dd hh mm ss defget user info wx msg...