From e98fbe92580ba5137be34d23b0ea7bf27a2759b9 Mon Sep 17 00:00:00 2001 From: Gregory Danielson Date: Thu, 26 Nov 2020 12:21:22 -0600 Subject: [PATCH] Document expected ipcachewrite input and output, with optional latlong entries --- lib/location.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/location.py b/lib/location.py index a7cd3ef..7eff718 100644 --- a/lib/location.py +++ b/lib/location.py @@ -116,12 +116,21 @@ def _ipcachewrite(ip_addr, location): """ Write a retrieved ip+location into cache Can stress some filesystems after long term use, see https://stackoverflow.com/questions/466521/how-many-files-can-i-put-in-a-directory + + Expects a location of the form: + `(city, region, country, country_code, , )` + Writes a cache entry of the form: + `country_code;country;region;city;;` + + The latitude and longitude are optional elements. """ cachefile = os.path.join(IP2LCACHE, ip_addr) if not os.path.exists(IP2LCACHE): os.makedirs(IP2LCACHE) with open(cachefile, 'w') as file: - file.write(location[3] + ';' + location[2] + ';' + location[1] + ';' + location[0] + ';' + location[4] + ';' + location[5]) + file.write(location[3] + ';' + location[2] + ';' + location[1] + ';' + location[0]) + if len(location) > 4: + file.write(';' + location[4] + ';' + location[5]) # like ip2location format