日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

pual_bot 天气插件编写

發布時間:2023/12/18 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 pual_bot 天气插件编写 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

最近在玩pual_bot,感覺很不錯,最近天氣插件失效了,就結合百度api重新寫了一個,也提交了。

https://github.com/coldnight/pual_bot

?

1 #!/usr/bin/env python 2 # -*- coding:utf-8 -*- 3 # 4 # Author : recall 5 # E-mail : tk86935367@vip.qq.com 6 # Date : 14/06/25 15:59:20 7 # Desc : 天氣 8 # 9 """ 替換原有的weather.py,并刪除weather.pyc 10 """ 11 12 import json 13 import urllib,requests 14 import sys 15 from plugins import BasePlugin 16 17 18 # 使用百度API獲取天氣預報 19 class BaiduWeather(): 20 """docstring for BaiduWeather""" 21 def __init__(self): 22 self.url = "http://api.map.baidu.com/telematics/v3/weather?output=json&ak=8a47b6b4cfee5e398e63df510980697e&location=" 23 24 def search(self,city,callback): 25 url = self.url + city.encode('utf-8') #urllib.quote(city.decode(sys.stdin.encoding).encode('utf-8','replace')) 26 res = requests.get(url) 27 html = res.text 28 json_data = json.loads(html) 29 error = json_data.get('error') 30 if error != 0: 31 body = u'不支持該城市' 32 else: 33 result = json_data.get('results',u'沒有結果') 34 weather = result[0] 35 c_city = weather.get('currentCity',None) 36 weather_data = weather.get('weather_data',None) 37 #print weather_data[0] 38 body = u'{0}\n今天:{1},{2},{3}\n明天:{4},{5},{6}'.format(c_city,weather_data[0].get('temperature'),weather_data[0].get('weather'),weather_data[0].get('wind'), \ 39 weather_data[1].get('temperature'),weather_data[1].get('weather'),weather_data[1].get('wind')) 40 callback(body) 41 42 43 44 class WeatherPlugin(BasePlugin): 45 bdweather = None 46 def is_match(self, from_uin, content, type): 47 if content.startswith("-w"): 48 self.city = content.split(" ")[1] 49 self._format = u"\n {0}" if type == "g" else u"{0}" 50 if self.bdweather is None: 51 self.bdweather = BaiduWeather() 52 return True 53 return False 54 55 56 def handle_message(self, callback): 57 self.bdweather.search(self.city, callback)

?

就是沒怎么弄異常,有時間誰添加吧。

轉載于:https://www.cnblogs.com/tk091/p/3808193.html

總結

以上是生活随笔為你收集整理的pual_bot 天气插件编写的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。