Closed yifanshu02 closed 7 years ago
hi there,
it seems there is an issue with your chinese locale settings. the script and the api require a UTF-8 compatible locale setting.
i guess you are trying it out on your local desktop computer with windows, right?
since i'm not a windows user since years i can`t give you a detailed instruction to set up a new locale in windows... perhaps you can add a new user that have a "en_US.UTF-8"-like locale?
by the way... the api request in the script is configured for a german respond... if you are a beginner, that seems some damn good quests to solve for you. ;) read the api documentation for any details how to configure the request and the respond. the request-url is constructed in the Update.update_json()-function
feel free to contact me, if you need more help.
Oh... and please rename your folder to "WeatherPi_TFT"... don't know when you cloned the repo... i made some fixes with "sys.path[0]" for Folder-PATH in the last commits to solve variable folder names for that application... or just update the project via git or download again ;)
@LoveBootCaptain ,thanks for your reply Errors were excluded:
#locale.setlocale(locale.LC_ALL, locale.getdefaultlocale())
locale.setlocale(locale.LC_ALL, 'uk')
i find that the X in locale.setlocale(locale.LC_ALL, X) must be 2 byte. 'mai' and 'univ' do not work. i dont konw why
Then:
#config_data = open(PATH + 'config.json').read()
#config = json.loads(config_data)
#forecast_io_key = config['FORECAST_IO_KEY']
forecast_io_key = 'f582cd3707f536dda08250505bfeea0c'
it is OK that i give key code to forecast_io_key,directly. it is not OK that give it though json.loads i m confusing it.Maybe compatibility is poor?
you can use setlocale
to overwirte your default locale. but i think (at least in linux) you have to install this locale you want to use. that means when you want to use en_US
and UTF-8
it has to be installed.
in locale.setlocale(locale.LC_ALL, locale.getdefaultlocale())
you have to pass in a tuple with language (e.g. en_US
) and a encoding (e.g. UTF-8
) for locale.getdefaultlocale()
e.g.: locale.setlocale(locale.LC_ALL, ('en_US', 'UTF-8'))
i don't know what happen, if you uncomment this completely... i needed to use it to solve problems with strange characters like german umlauts (ä, ö, ü, ß), which come from the API (like in forecast-summary strings).
long story short: be shure you set the API request to use english as language AND your os should be set up to en_US
and UTF-8
too and it should work.
here is an API request you can use (weather is from New York): https://api.forecast.io/forecast/YOUR_API_KEY/40.7058253,-74.1180847?lang=en&units=si&exclude=flags
you don't have to use API key from the json file. just overwrite the hole request_url
-variable with the url above and insert your API key.
please do not share your secret keys ;) you can reset it in the account settings of https://darksky.net/dev/account thats the reason i used a json file for configuration... my config.json is excluded in my project so i do not commit my secret key here on github by accident ;) and i thought it is a good idea if i want to add more configuartion without changing the script... (like display brightness or intervals for the API-updates).
your first json error looks like you probably missed the double quotes for the key or the value. just replace the xxxx with your API-key but not the " " ;) . it has to look this (no comma at the end -> i have to change that in the example):
{
"FORECAST_IO_KEY": "xxxxxxxxxxxxxxxxxxxxxxxxx"
}
hope this helps ;) just tried it on a fresh and new installed jessie-raspbian... it runs out of the box on a raspberry pi with latest raspbian image with english locale.
Thanks for your suggestion!
About json error ,i have found the key.Yesterday my json is:
{
"FORECAST_IO_KEY": "xxxxxxxxxxxxxxxxxxxxxxxxx",
}
now i remove the last ',' .and the code is working...... what a boring ','! AND i suggest the geographic coordinate values, lang,units,exclude should be added to config.json
More options in config are already done, but not committed and pushed yet. I will update it later today. Great that it works now. That means you fixed the locale issue? If yes, How?
About the setlocale .in the locale.py
there is
'uk': 'uk_UA.KOI8-U',
In the project,the code 'locale.setlocale(locale.LC_ALL, 'uk_UA.KOI8-U')' is not working However, the code 'locale.setlocale(locale.LC_ALL, 'uk')' is working :(
ah great.
it has to be a tuple in XX locale.setlocale(locale.LC_ALL, XX)
. means it has to be locale.setlocale(locale.LC_ALL, ('uk_UA', 'KOI8-U'))
in your case.
'uk'
is returning this correctly. that's why it works ;)
In addition,when i use locale.setlocale(locale.LC_ALL, '')
or locale.setlocale(locale.LC_ALL, 'zh')
the UI do not show some character at the position of "week" and "month"
this could be cause the font don't has that special character... feel free to change the font to one which has that. it has to be in .ttf
-format. there are some other fonts in the folder which might work. you can also use one of your system fonts. see http://www.pygame.org/docs/ref/font.html for more details or just copy/paste a .ttf
file to the /font
folder
(i know this problems cause of the german umlauts (ä, ö, ü) too... hate those crazy umlauts like those commas i missed to remove in examples 😂 )
I use the locale.setlocale(locale.LC_ALL, 'uk')
.everything is OK.
I think when i use locale.setlocale(locale.LC_ALL, 'zh'),the UI should show Chinese.but the .ttf
in /font
have not Chinese
And locale.setlocale(locale.LC_ALL, ('uk_UA', 'KOI8-U'))
do not work.......:(
if you find a font which looks good on the device or a Roboto-Chinese-Font feel free to add it via pull request. the equivalent of Roboto-Font in android and chrome is Noto-Font (https://material.io/guidelines/style/typography.html#typography-typeface), here is a link to google fonts: https://fonts.google.com/specimen/Noto+Sans?selection.family=Noto+Sans.
perhaps the locale issue is related to os? who knows... in mac os and linux it works... on windows not... locale.setlocale(locale.LC_ALL, 'de')
is not working on my raspberry :joy: i need the long form for my system-locale
All right,I will try it .
locale.setlocale(locale.LC_ALL, 'de')
is working on window7.I will try it on my RPI2 and 2.2'TFT
Now i think accuracy of weather forecast of your code is higher than squix78's code
and accuracy of your code about moon change seem not higher than squix78's code
about the moon issue:
the moon-phase is provided via API (and the Temp-Data too) which might be the difference. squix78 is using another API (wonderground). i use darksky (forecast.io). darksky is providing moonphase in a value which is percentage.
today there is 0.97
provided via darksky for Berlin, Germany. Which means 1% of the moon should be visible. here is a link to a moonphase calender: http://www.kalender-365.eu/mond/aktueller-mondstand.html which tells is 1% is visible too...
my icons are 28 for 31 possible moonphases. i do a little math in moon_icon = int((float(moon_icon) * 100 / 3.57) + 0.25)
to map the percentage to 28 icons.
i guess for 1% visible moon it is ok... for squix78 and my code :joy: 1% is nearly unvisible. i can make some more small icons to make it more detailed... but the icons from the source are only 28 😈
AHAHAHAH,
1%MOON...............................
YOU WIN
Please share a picture with chinese font if you get it working. feel free to contact me again if you have any further issues or contribute your improvements. kind regards from Berlin (without snow, too)
let it snow let it snow let it snow
p.s.: you should change the hardcoded "Schnee" for "snow" with a language that fits you.
its PRECIPTYPE
in Update.get_precip_type()
Same for some other hardcoded german stuff 🇩🇪
AHAHAH,global warming in 10+ years made the weather abnormal,In winter some parts of China are suffering form haze:(
just pushed the updated config.json with more options... next push will include a linux service for buttons to restart weather app or reboot raspberry pi. regards
i have see the new config.json~ Chinese weatherPI_TFT:
font_small = pygame.font.SysFont('SimHei', 14)
font_big = pygame.font.SysFont('SimHei', 36)
font_small_bold = pygame.font.SysFont('SimHei', 14)
font_big_bold = pygame.font.SysFont('SimHei', 36)
and :
font_small = pygame.font.Font(FONT_PATH + 'msyh.ttf', 14)
font_big = pygame.font.Font(FONT_PATH + 'msyh.ttf', 30)
font_small_bold = pygame.font.Font(FONT_PATH + 'msyh.ttf', 14)
font_big_bold = pygame.font.Font(FONT_PATH + 'msyh.ttf', 30)
Sure that modify the API lang to zh:options = '?lang=zh&units=si&exclude=flags'
and locale.setlocale(locale.LC_ALL, 'zh')
looks crazy in chinese :rofl: great work font looks awesome too
a good translation of "Niederschlag" would be "rainfall" or "precipitation" http://en.bab.la/dictionary/english-chinese/rainfall
please don't modify your last post... i will use it as a link for troubleshooting
HI Guys, I have been trying to ge this running on a pi4 and a HDMI 4" TFT, but being so new to Pi I cant seam to get this running on boot up.
HI Guys, I have been trying to ge this running on a pi4 and a HDMI 4" TFT, but being so new to Pi I cant seam to get this running on boot up.
It just works as is! I assume you got API from https://www.weatherbit.io/. rest commands as straight forward. I am running on Pi 3 4 5 and both HDMI, DSI and hyperpixel LCDs.
By the way are you able to boot up to PI desktop?
Question to author / all
the precipitation pulled and displayed is for DAILY - issue is if morning there is some% rain evening as well it shows DAILY PRECEPTATION % and ICON. Better I change it to CURRENT. Not able to do so. Let me know which line of code needs to be changed.
HI Guys, I have been trying to ge this running on a pi4 and a HDMI 4" TFT, but being so new to Pi I cant seam to get this running on boot up.
It just works as is! I assume you got API from https://www.weatherbit.io/. rest commands as straight forward. I am running on Pi 3 4 5 and both HDMI, DSI and hyperpixel LCDs.
By the way are you able to boot up to PI desktop?
Hi I'm trying for 4 days now to get it work. i've follw the steps for installation. got myself a api.key. and able te see the desktop. no errors while booting up. still no weather scree on display. it stays on desktop. did i forgot something to edit or add? please help, i'm new at raspberry (zero). how to display the weather screen? many thanks for your help.
hi @LoveBootCaptain , i saw your project by twitter, and at the same i see this project here.i'm a beginner in python,too. So i try to build this project. And i encounter an error:
i dont know where is wrong.However,i annotate
return _setlocale(category, locale)
in "D:\Python35\lib\locale.py", line 594 and the error is gone But there is a new error:i have no idea about it...
PS: i can get defaultlocale by
locale.getdefaultlocale()
:Do you have a idea?