2018-10-05 18:37:16 +00:00
|
|
|
"""
|
|
|
|
global configuration of the project
|
|
|
|
"""
|
|
|
|
|
2017-03-31 18:38:35 +00:00
|
|
|
import logging
|
|
|
|
import os
|
|
|
|
|
2018-10-05 18:37:16 +00:00
|
|
|
MYDIR = os.path.abspath(os.path.dirname(os.path.dirname('__file__')))
|
2017-03-31 18:38:35 +00:00
|
|
|
|
2018-10-05 18:19:27 +00:00
|
|
|
GEOLITE = os.path.join(MYDIR, 'data', "GeoLite2-City.mmdb")
|
2017-03-31 18:38:35 +00:00
|
|
|
WEGO = "/home/igor/go/bin/we-lang"
|
2018-10-23 16:53:34 +00:00
|
|
|
PYPHOON = "/home/igor/pyphoon/bin/pyphoon-lolcat"
|
2017-03-31 18:38:35 +00:00
|
|
|
|
2018-10-26 22:17:16 +00:00
|
|
|
_DATADIR = "/wttr.in"
|
|
|
|
_LOGDIR = "/wttr.in/log"
|
|
|
|
|
|
|
|
CACHEDIR = os.path.join(_DATADIR, "cache/wego/")
|
|
|
|
IP2LCACHE = os.path.join(_DATADIR, "cache/ip2l/")
|
|
|
|
PNG_CACHE = os.path.join(_DATADIR, "cache/png")
|
|
|
|
|
|
|
|
LOG_FILE = os.path.join(_LOGDIR, 'main.log')
|
2017-03-31 18:38:35 +00:00
|
|
|
|
2018-10-05 18:37:16 +00:00
|
|
|
ALIASES = os.path.join(MYDIR, "share/aliases")
|
|
|
|
ANSI2HTML = os.path.join(MYDIR, "share/ansi2html.sh")
|
|
|
|
BLACKLIST = os.path.join(MYDIR, "share/blacklist")
|
2017-03-31 18:38:35 +00:00
|
|
|
|
2018-10-05 18:37:16 +00:00
|
|
|
HELP_FILE = os.path.join(MYDIR, 'share/help.txt')
|
|
|
|
BASH_FUNCTION_FILE = os.path.join(MYDIR, 'share/bash-function.txt')
|
|
|
|
TRANSLATION_FILE = os.path.join(MYDIR, 'share/translation.txt')
|
|
|
|
TEST_FILE = os.path.join(MYDIR, 'share/test-NAME.txt')
|
2018-10-03 16:59:17 +00:00
|
|
|
|
|
|
|
IATA_CODES_FILE = os.path.join(MYDIR, 'share/list-of-iata-codes.txt')
|
2017-03-31 18:38:35 +00:00
|
|
|
|
2018-10-05 18:37:16 +00:00
|
|
|
TEMPLATES = os.path.join(MYDIR, 'share/templates')
|
|
|
|
STATIC = os.path.join(MYDIR, 'share/static')
|
2017-03-31 18:38:35 +00:00
|
|
|
|
|
|
|
NOT_FOUND_LOCATION = "not found"
|
|
|
|
DEFAULT_LOCATION = "oymyakon"
|
|
|
|
|
|
|
|
MALFORMED_RESPONSE_HTML_PAGE = open(os.path.join(STATIC, 'malformed-response.html')).read()
|
|
|
|
|
2018-10-07 10:11:59 +00:00
|
|
|
GEOLOCATOR_SERVICE = 'http://localhost:8004'
|
|
|
|
|
2018-10-03 20:46:23 +00:00
|
|
|
LISTEN_HOST = ""
|
|
|
|
LISTEN_PORT = 8002
|
|
|
|
|
2018-10-23 18:04:42 +00:00
|
|
|
PROXY_HOST = "127.0.0.1"
|
|
|
|
PROXY_PORT = 5001
|
2018-10-26 22:17:16 +00:00
|
|
|
PROXY_CACHEDIR = os.path.join(_DATADIR, "cache/proxy-wwo/")
|
2018-10-23 18:04:42 +00:00
|
|
|
|
2018-10-05 18:37:16 +00:00
|
|
|
MY_EXTERNAL_IP = '5.9.243.187'
|
|
|
|
|
2018-10-05 18:19:27 +00:00
|
|
|
PLAIN_TEXT_AGENTS = [
|
|
|
|
"curl",
|
|
|
|
"httpie",
|
|
|
|
"lwp-request",
|
|
|
|
"wget",
|
|
|
|
"python-requests"
|
|
|
|
]
|
|
|
|
|
|
|
|
PLAIN_TEXT_PAGES = [':help', ':bash.function', ':translation']
|
|
|
|
|
2018-10-26 17:35:13 +00:00
|
|
|
_IP2LOCATION_KEY_FILE = os.environ['HOME'] + '/.ip2location.key'
|
|
|
|
if os.path.exists(_IP2LOCATION_KEY_FILE):
|
|
|
|
IP2LOCATION_KEY = open(_IP2LOCATION_KEY_FILE, 'r').read().strip()
|
2018-10-23 18:04:42 +00:00
|
|
|
|
2018-10-27 21:54:37 +00:00
|
|
|
_WWO_KEY_FILE = os.environ['HOME'] + '/.wwo.key'
|
|
|
|
if os.path.exists(_WWO_KEY_FILE):
|
|
|
|
WWO_KEY = open(_WWO_KEY_FILE, 'r').read().strip()
|
|
|
|
|
2017-03-31 18:38:35 +00:00
|
|
|
def error(text):
|
2018-10-05 18:37:16 +00:00
|
|
|
"log error `text` and raise a RuntimeError exception"
|
|
|
|
|
2017-03-31 18:38:35 +00:00
|
|
|
if not text.startswith('Too many queries'):
|
|
|
|
print text
|
2018-10-05 18:37:16 +00:00
|
|
|
logging.error("ERROR %s", text)
|
2017-03-31 18:38:35 +00:00
|
|
|
raise RuntimeError(text)
|
|
|
|
|
|
|
|
def log(text):
|
2018-10-05 18:37:16 +00:00
|
|
|
"log error `text` and do not raise any exceptions"
|
|
|
|
|
2017-03-31 18:38:35 +00:00
|
|
|
if not text.startswith('Too many queries'):
|
|
|
|
print text
|
|
|
|
logging.info(text)
|
|
|
|
|
2018-10-03 16:59:17 +00:00
|
|
|
def get_help_file(lang):
|
2018-10-05 18:37:16 +00:00
|
|
|
"Return help file for `lang`"
|
|
|
|
|
2018-10-03 16:59:17 +00:00
|
|
|
help_file = os.path.join(MYDIR, 'share/translations/%s-help.txt' % lang)
|
|
|
|
if os.path.exists(help_file):
|
|
|
|
return help_file
|
2018-10-05 18:37:16 +00:00
|
|
|
return HELP_FILE
|