displayed location names for implied locations fixes (fixes #265)
This commit is contained in:
parent
5a4c57ce96
commit
65855a6d6a
3 changed files with 14 additions and 11 deletions
|
|
@ -207,11 +207,11 @@ def location_processing(location, ip_addr):
|
||||||
if location == '~':
|
if location == '~':
|
||||||
location = None
|
location = None
|
||||||
|
|
||||||
if location and location.lstrip('~').startswith('@'):
|
if location and location.lstrip('~ ').startswith('@'):
|
||||||
try:
|
try:
|
||||||
location, country = get_location(
|
location, country = get_location(
|
||||||
socket.gethostbyname(
|
socket.gethostbyname(
|
||||||
location.lstrip('~')[1:]))
|
location.lstrip('~ ')[1:]))
|
||||||
location = '~' + location
|
location = '~' + location
|
||||||
if country:
|
if country:
|
||||||
location += ", %s" % country
|
location += ", %s" % country
|
||||||
|
|
@ -243,13 +243,16 @@ def location_processing(location, ip_addr):
|
||||||
hide_full_address = not force_show_full_address
|
hide_full_address = not force_show_full_address
|
||||||
|
|
||||||
if location and not location.startswith('~'):
|
if location and not location.startswith('~'):
|
||||||
location = location_canonical_name(location)
|
tmp_location = location_canonical_name(location)
|
||||||
|
if tmp_location != location:
|
||||||
|
override_location_name = location
|
||||||
|
locaiton = tmp_location
|
||||||
|
|
||||||
# up to this point it is possible that the name
|
# up to this point it is possible that the name
|
||||||
# contains some unicode symbols
|
# contains some unicode symbols
|
||||||
# here we resolve them
|
# here we resolve them
|
||||||
if location is not None and not ascii_only(location):
|
if location is not None and not ascii_only(location):
|
||||||
location = "~" + location.lstrip('~')
|
location = "~" + location.lstrip('~ ')
|
||||||
|
|
||||||
if location is not None and location.upper() in IATA_CODES:
|
if location is not None and location.upper() in IATA_CODES:
|
||||||
location = '~%s' % location
|
location = '~%s' % location
|
||||||
|
|
|
||||||
|
|
@ -93,7 +93,7 @@ def render_location(data, query):
|
||||||
location (l)
|
location (l)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
return data['location'].title()
|
return (data['override_location'] or data['location']) # .title()
|
||||||
|
|
||||||
def render_moonphase(_, query):
|
def render_moonphase(_, query):
|
||||||
"""
|
"""
|
||||||
|
|
@ -155,7 +155,7 @@ def render_line(line, data, query):
|
||||||
|
|
||||||
return re.sub(r'%[^%]*[a-zA-Z]', render_symbol, line)
|
return re.sub(r'%[^%]*[a-zA-Z]', render_symbol, line)
|
||||||
|
|
||||||
def format_weather_data(format_line, location, data, query):
|
def format_weather_data(format_line, location, override_location, data, query):
|
||||||
"""
|
"""
|
||||||
Format information about current weather `data` for `location`
|
Format information about current weather `data` for `location`
|
||||||
with specified in `format_line` format
|
with specified in `format_line` format
|
||||||
|
|
@ -163,10 +163,11 @@ def format_weather_data(format_line, location, data, query):
|
||||||
|
|
||||||
current_condition = data['data']['current_condition'][0]
|
current_condition = data['data']['current_condition'][0]
|
||||||
current_condition['location'] = location
|
current_condition['location'] = location
|
||||||
|
current_condition['override_location'] = override_location
|
||||||
output = render_line(format_line, current_condition, query)
|
output = render_line(format_line, current_condition, query)
|
||||||
return output
|
return output
|
||||||
|
|
||||||
def wttr_line(location, query):
|
def wttr_line(location, override_location_name, query):
|
||||||
"""
|
"""
|
||||||
Return 1line weather information for `location`
|
Return 1line weather information for `location`
|
||||||
in format `line_format`
|
in format `line_format`
|
||||||
|
|
@ -179,7 +180,7 @@ def wttr_line(location, query):
|
||||||
|
|
||||||
weather_data = get_weather_data(location)
|
weather_data = get_weather_data(location)
|
||||||
|
|
||||||
output = format_weather_data(format_line, location, 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"
|
||||||
return output
|
return output
|
||||||
|
|
||||||
|
|
@ -193,7 +194,7 @@ def main():
|
||||||
'line': sys.argv[2],
|
'line': sys.argv[2],
|
||||||
}
|
}
|
||||||
|
|
||||||
sys.stdout.write(wttr_line(location, query))
|
sys.stdout.write(wttr_line(location, location, query))
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|
|
||||||
|
|
@ -208,8 +208,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:
|
||||||
location = (orig_location or location).lstrip('~')
|
return wttr_line(location, override_location_name, query)
|
||||||
return wttr_line(location, query)
|
|
||||||
|
|
||||||
if png_filename:
|
if png_filename:
|
||||||
options = {
|
options = {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue