multilingual support for the oneline mode
This commit is contained in:
parent
c71caaadf9
commit
5901e711f6
3 changed files with 5 additions and 6 deletions
|
|
@ -6,12 +6,11 @@ import json
|
||||||
import requests
|
import requests
|
||||||
from globals import WWO_KEY
|
from globals import WWO_KEY
|
||||||
|
|
||||||
def get_weather_data(location):
|
def get_weather_data(location, lang):
|
||||||
"""
|
"""
|
||||||
Get weather data for `location`
|
Get weather data for `location`
|
||||||
"""
|
"""
|
||||||
key = WWO_KEY
|
key = WWO_KEY
|
||||||
lang = 'en'
|
|
||||||
url = ('/premium/v1/weather.ashx'
|
url = ('/premium/v1/weather.ashx'
|
||||||
'?key=%s&q=%s&format=json'
|
'?key=%s&q=%s&format=json'
|
||||||
'&num_of_days=3&tp=3&lang=%s') % (key, location, lang)
|
'&num_of_days=3&tp=3&lang=%s') % (key, location, lang)
|
||||||
|
|
|
||||||
|
|
@ -183,7 +183,7 @@ def format_weather_data(format_line, location, override_location, data, query):
|
||||||
output = render_line(format_line, current_condition, query)
|
output = render_line(format_line, current_condition, query)
|
||||||
return output
|
return output
|
||||||
|
|
||||||
def wttr_line(location, override_location_name, query):
|
def wttr_line(location, override_location_name, query, lang):
|
||||||
"""
|
"""
|
||||||
Return 1line weather information for `location`
|
Return 1line weather information for `location`
|
||||||
in format `line_format`
|
in format `line_format`
|
||||||
|
|
@ -194,7 +194,7 @@ def wttr_line(location, override_location_name, query):
|
||||||
if format_line in PRECONFIGURED_FORMAT:
|
if format_line in PRECONFIGURED_FORMAT:
|
||||||
format_line = PRECONFIGURED_FORMAT[format_line]
|
format_line = PRECONFIGURED_FORMAT[format_line]
|
||||||
|
|
||||||
weather_data = get_weather_data(location)
|
weather_data = get_weather_data(location, lang)
|
||||||
|
|
||||||
output = format_weather_data(format_line, location, override_location_name, weather_data, query)
|
output = format_weather_data(format_line, location, override_location_name, weather_data, query)
|
||||||
output = output.rstrip("\n")+"\n"
|
output = output.rstrip("\n")+"\n"
|
||||||
|
|
@ -210,7 +210,7 @@ def main():
|
||||||
'line': sys.argv[2],
|
'line': sys.argv[2],
|
||||||
}
|
}
|
||||||
|
|
||||||
sys.stdout.write(wttr_line(location, location, query))
|
sys.stdout.write(wttr_line(location, location, query, 'en'))
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|
|
||||||
|
|
@ -215,7 +215,7 @@ def wttr(location, request):
|
||||||
# We are ready to return the answer
|
# We are ready to return the answer
|
||||||
try:
|
try:
|
||||||
if 'format' in query:
|
if 'format' in query:
|
||||||
return _wrap_response(wttr_line(location, override_location_name, query), html_output)
|
return _wrap_response(wttr_line(location, override_location_name, query, lang), html_output)
|
||||||
|
|
||||||
if png_filename:
|
if png_filename:
|
||||||
options = {
|
options = {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue