306 字
2 分钟
Twitter 名称自动更新天气 emoji 的实现
启发
最近逛 Qiita 时看到这篇文章:
Twitterの名前を5分毎に東京の天気☼☂☃と連動させるサーバレスプログラムを書いたら色々知らないことが出てきた話 https://qiita.com/issei_y/items/ab641746be2704db98be
其通过 AWSLambda 来定期运行更新任务,我既有了 VPS 就不用 AWS 啦。因此用 python 写个 app 来跑。
App
天气
获取天气信息如文中选用 OpenWeatherMap 的 API。用 requests GET 得 json 后取得 icon 字段数据
json 样本
{ "coord": { "lon": 145.77, "lat": -16.92 }, "weather": [ { "id": 802, "main": "Clouds", "description": "scattered clouds", "icon": "03n" } ], "base": "stations", "main": { "temp": 300.15, "pressure": 1007, "humidity": 74, "temp_min": 300.15, "temp_max": 300.15 }, "visibility": 10000, "wind": { "speed": 3.6, "deg": 160 }, "clouds": { "all": 40 }, "dt": 1485790200, "sys": { "type": 1, "id": 8166, "message": 0.2064, "country": "AU", "sunrise": 1485720272, "sunset": 1485766550 }, "id": 2172797, "name": "Cairns", "cod": 200}emoji 转换
为 偷懒 简化程序,直接通过 icon 字段来转换 emoji。可见 Weather Conditions
python 没 switch/case,采用 dict 映射
Twitter 名更新
自动更新
采用 APScheduler 来定时更新。可以设定时间点、时间间隔。
成品
github
已 po 去 gay github twitterWeatherName
Docker
已 push 去 dockerhub docker
再开脑洞
联结 homeassistant 自动化,监测自宅温度更新 twitter。联结其他web服务等等。
Twitter 名称自动更新天气 emoji 的实现
https://blog.ckyol.moe/posts/tweetweaname/分享文章
生成精美分享图或复制链接,与更多人分享本文。
继续阅读
换条路线
从其他文章中稳定抽取
最后更新于 ,距今已过 3070 天
部分内容可能已过时
评论