我在 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 更改权限后,问题解决了。感谢您的时间和帮助,我真的很感激。
答案1
问题似乎出在 上~/.cache/weather.json
。我所做的就是更改其他应用程序对文件的读写权限。这可以通过在终端中输入以下命令来完成:
chmod o+w ~/.cache/weather.json