diff --git a/.gitignore b/.gitignore index 669685b..b472a6a 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ share/static/fonts/ data/ log/ .idea/ +*.swp diff --git a/README.md b/README.md index d70e171..b17d653 100644 --- a/README.md +++ b/README.md @@ -234,8 +234,8 @@ To install the application: 1. Install external dependencies 2. Install Python dependencies used by the service -3. Get a WorldWeatherOnline API Key -4. Configure wego +3. Configure IP2Location (optional) +4. Get a WorldWeatherOnline API and configure wego 5. Configure wttr.in 6. Configure the HTTP-frontend service @@ -278,14 +278,24 @@ If `virtualenv` is used: Also, you need to install the geoip2 database. You can use a free database GeoLite2 that can be downloaded from (http://dev.maxmind.com/geoip/geoip2/geolite2/). -### Get a WorldWeatherOnline key +### Configure IP2Location (optional) + +If you want to use the IP2location service for IP-addresses that are not covered by GeoLite2, +you have to obtain a API key of that service, and after that save into the `~/.ip2location.key` file: + +``` +$ echo 'YOUR_IP2LOCATION_KEY' > ~/.ip2location.key +``` + +If you don't have this file, the service will be silently skipped (it is not a big problem, +because the MaxMind database is pretty good). + +### Get a WorldWeatherOnline key and configure wego To get a WorldWeatherOnline API key, you must register here: https://developer.worldweatheronline.com/auth/register -### Configure wego - After you have a WorldWeatherOnline key, you can configure `wego`: $ cat ~/.wegorc diff --git a/lib/globals.py b/lib/globals.py index ecc0e41..83ee3a5 100644 --- a/lib/globals.py +++ b/lib/globals.py @@ -67,6 +67,7 @@ PLAIN_TEXT_AGENTS = [ PLAIN_TEXT_PAGES = [':help', ':bash.function', ':translation'] _IP2LOCATION_KEY_FILE = os.environ['HOME'] + '/.ip2location.key' +IP2LOCATION_KEY = None if os.path.exists(_IP2LOCATION_KEY_FILE): IP2LOCATION_KEY = open(_IP2LOCATION_KEY_FILE, 'r').read().strip() diff --git a/lib/location.py b/lib/location.py index a90aa43..80b8c82 100644 --- a/lib/location.py +++ b/lib/location.py @@ -95,15 +95,18 @@ def ip2location(ip_addr): if os.path.exists(cached): location = open(cached, 'r').read() else: - try: - ip2location_response = requests\ - .get('http://api.ip2location.com/?ip=%s&key=%s&package=WS3' \ - % (ip_addr, IP2LOCATION_KEY)).text - if ';' in ip2location_response: - open(cached, 'w').write(ip2location_response) - location = ip2location_response - except requests.exceptions.ConnectionError: - pass + # if IP2LOCATION_KEY is not set, do not the query, + # because the query wont be processed anyway + if IP2LOCATION_KEY: + try: + ip2location_response = requests\ + .get('http://api.ip2location.com/?ip=%s&key=%s&package=WS3' \ + % (ip_addr, IP2LOCATION_KEY)).text + if ';' in ip2location_response: + open(cached, 'w').write(ip2location_response) + location = ip2location_response + except requests.exceptions.ConnectionError: + pass if ';' in location: location = location.split(';')[3], location.split(';')[1] diff --git a/share/aliases b/share/aliases index acd2cb6..f370c52 100644 --- a/share/aliases +++ b/share/aliases @@ -46,3 +46,4 @@ Chicago : Chicago,IL Paris : Paris,France Giessen : Giessen, Germany Braga : Braga, Portugal +Kashan : ~Kashan,Iran diff --git a/share/scripts/clean-cache.sh b/share/scripts/clean-cache.sh index d04db7b..3ed9937 100755 --- a/share/scripts/clean-cache.sh +++ b/share/scripts/clean-cache.sh @@ -8,3 +8,8 @@ do mkdir "${CACHEDIR}/${dir}" rm -rf "${CACHEDIR}/${dir}.old" done + +cd /wttr.in/log +mv main.log main.log.1 +touch main.log +