Document expected ipcachewrite input and output, with optional latlong entries

gregdan3/master
Gregory Danielson 4 years ago
parent c49c0a5c0e
commit e98fbe9258
No known key found for this signature in database
GPG Key ID: 88D4EF22F6C14CA7

@ -116,12 +116,21 @@ def _ipcachewrite(ip_addr, location):
""" Write a retrieved ip+location into cache """ Write a retrieved ip+location into cache
Can stress some filesystems after long term use, see Can stress some filesystems after long term use, see
https://stackoverflow.com/questions/466521/how-many-files-can-i-put-in-a-directory 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, <lat>, <long>)`
Writes a cache entry of the form:
`country_code;country;region;city;<lat>;<long>`
The latitude and longitude are optional elements.
""" """
cachefile = os.path.join(IP2LCACHE, ip_addr) cachefile = os.path.join(IP2LCACHE, ip_addr)
if not os.path.exists(IP2LCACHE): if not os.path.exists(IP2LCACHE):
os.makedirs(IP2LCACHE) os.makedirs(IP2LCACHE)
with open(cachefile, 'w') as file: 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 # like ip2location format

Loading…
Cancel
Save