我对 conky 中的主题有问题,更具体地说,对 conky 小部件有问题。该主题名为“alsafi”并且工作正常,但天气小部件默认显示博洛尼亚(意大利)的天气。我更改了 中的 API 密钥和城市 ID ~/.config/conky/Alsafi/scripts/weather2.sh
,但即使在重新启动并重新启动 conky 后,它仍然显示博洛尼亚。问题可能是什么?
注意:主题从 conky manager 2 运行,因此位置是~/.conky
。
编辑后的文件:weather-v2.0.sh
# This script is to get weather data from openweathermap.com in the form of a json file
# so that conky will still display the weather when offline even though it doesn't up to date
# Variables
# get your city id at https://openweathermap.org/find and replace
city_id=256639 #<---modified to display my city
# replace with yours
api_key=c99cf91646e0ca8d6ff63957a1d20552 #<--- personal api key
# choose between metric for Celcius or imperial for fahrenheit
unit=metric
# i'm not sure it will support all languange,
lang=en
# Main command
url="api.openweathermap.org/data/2.5/weather?id=${city_id}&appid=${api_key}&cnt=5&units=${unit}&lang=${lang}"
curl ${url} -s -o ~/.cache/weather.json
exit
运行后grep -iRE 'Alsafi|weather.sh' ~/.conky ~/.config/conky
终端输出为:
/home/kr/.conky/Sirius/Changelog:- New Weather.sh
/home/kr/.conky/conky-startup.sh:cd "$HOME/.conky/Alsafi"
/home/kr/.conky/conky-startup.sh:conky -c "$HOME/.conky/Alsafi/Alsafi.conf" &
/home/kr/.conky/Alsafi/Changelog:Alsafi - Conky Theme
/home/kr/.conky/Alsafi/Alsafi.conf:-- ALSAFI
/home/kr/.conky/Alsafi/Alsafi.conf:${execi 600 ~/.config/conky/Alsafi/scripts/weather-v2.0.sh}\
/home/kr/.conky/Alsafi/Alsafi.conf:${offset 0}${voffset 10}${color}${font feather:size=20}${execi 15 ~/.config/conky/Alsafi/scripts/weather-text-icon}${goto 73}${font}
/home/kr/.conky/Alsafi/Alsafi.conf:${offset 0}${voffset 0}${color1}${font Barlow:bold:size=13}${exec ~/.config/conky/Alsafi/scripts/playerctl.sh}
/home/kr/.conky/Alsafi/Alsafi.conf:${offset 0}${voffset 0}${font Barlow:bold:size=10}Wi-Fi : ${execi 5 ~/.config/conky/Alsafi/scripts/ssid}
/home/kr/.conky/Alsafi/start.sh:conky -c $HOME/.config/conky/Alsafi/Alsafi.conf &> /dev/null &
/home/kr/.config/conky/Sirius/Changelog:- New Weather.sh
好的,重新启动 conky 后,缓存中就有了 Weather.json
➜ ~ cat ~/.cache/weather.json
{"coord":{"lon":11.4333,"lat":44.4667},"weather":[{"id":803,"main":"Clouds","description":"broken clouds","icon":"04n"}],"base":"stations","main":{"temp":11.95,"feels_like":11.66,"temp_min":10.77,"temp_max":13.14,"pressure":1016,"humidity":94},"visibility":7000,"wind":{"speed":3.09,"deg":40},"clouds":{"all":75},"dt":1709155681,"sys":{"type":2,"id":2004497,"country":"IT","sunrise":1709099691,"sunset":1709139562},"timezone":3600,"id":3181927,"name":"Bologna","cod":200}
所以最后经过更多的研究,问题解决了。原因是权限。weather.json 文件有权限从我这里写入和读取,但没有从其他应用程序读取的权限,所以它无法从 api 获取数据。使用 gui 更改权限后问题解决了。感谢您的时间和帮助,我真的很感激。