various png-related problems fixed (#311)

pull/326/head
Igor Chubin 6 years ago
parent 0df65139e3
commit 040b9ea7d7

@ -225,17 +225,10 @@ def location_processing(location, ip_addr):
query_source_location = get_location(ip_addr)
country = None
if location is None or location == 'MyLocation':
location, country = query_source_location
if not location or location == 'MyLocation':
location = ip_addr
# Let us try to use geolocation services for locations
# that were derived from IPs.
if location:
location = '~' + location
if country:
location += ", %s" % country
hide_full_address = not force_show_full_address
elif is_ip(location):
if is_ip(location):
location, country = get_location(location)
# here too

@ -196,21 +196,22 @@ def wttr(location, request):
orig_location = location
location, override_location_name, full_address, country, query_source_location = \
location_processing(location, ip_addr)
if not png_filename:
location, override_location_name, full_address, country, query_source_location = \
location_processing(location, ip_addr)
us_ip = query_source_location[1] == 'United States' and 'slack' not in user_agent
query = parse_query.metric_or_imperial(query, lang, us_ip=us_ip)
us_ip = query_source_location[1] == 'United States' and 'slack' not in user_agent
query = parse_query.metric_or_imperial(query, lang, us_ip=us_ip)
# logging query
orig_location_utf8 = (orig_location or "").encode('utf-8')
location_utf8 = location.encode('utf-8')
use_imperial = query.get('use_imperial', False)
log(" ".join(map(str,
[ip_addr, user_agent, orig_location_utf8, location_utf8, use_imperial, lang])))
# logging query
orig_location_utf8 = (orig_location or "").encode('utf-8')
location_utf8 = location.encode('utf-8')
use_imperial = query.get('use_imperial', False)
log(" ".join(map(str,
[ip_addr, user_agent, orig_location_utf8, location_utf8, use_imperial, lang])))
if country and location != NOT_FOUND_LOCATION:
location = "%s,%s" % (location, country)
if country and location != NOT_FOUND_LOCATION:
location = "%s,%s" % (location, country)
# We are ready to return the answer
try:
@ -219,7 +220,7 @@ def wttr(location, request):
if png_filename:
options = {
'lang': None,
'lang': lang,
'location': location}
options.update(query)

@ -288,13 +288,10 @@ def make_wttr_in_png(png_name, options=None):
"""
parsed = parse_wttrin_png_name(png_name)
print("------")
print(parsed)
print("------")
# if location is MyLocation it should be overriden
# with autodetected location (from options)
if parsed.get('location', 'MyLocation') == 'MyLocation':
if parsed.get('location', 'MyLocation') == 'MyLocation' or not parsed.get('location', ''):
del parsed['location']
if options is not None:

Loading…
Cancel
Save