mirror of
https://github.com/chubin/wttr.in
synced 2024-12-27 04:03:07 +00:00
globals.py clean up
This commit is contained in:
parent
ed52219acd
commit
eb8b1cc92d
1 changed files with 27 additions and 18 deletions
|
@ -1,29 +1,33 @@
|
||||||
|
"""
|
||||||
|
global configuration of the project
|
||||||
|
"""
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
|
||||||
MYDIR = os.path.abspath(os.path.dirname( os.path.dirname('__file__') ))
|
MYDIR = os.path.abspath(os.path.dirname(os.path.dirname('__file__')))
|
||||||
|
|
||||||
GEOLITE = os.path.join(MYDIR, 'data', "GeoLite2-City.mmdb")
|
GEOLITE = os.path.join(MYDIR, 'data', "GeoLite2-City.mmdb")
|
||||||
WEGO = "/home/igor/go/bin/we-lang"
|
WEGO = "/home/igor/go/bin/we-lang"
|
||||||
PYPHOON = "/home/igor/wttr.in/pyphoon/bin/pyphoon-lolcat"
|
PYPHOON = "/home/igor/wttr.in/pyphoon/bin/pyphoon-lolcat"
|
||||||
|
|
||||||
CACHEDIR = os.path.join( MYDIR, "cache" )
|
CACHEDIR = os.path.join(MYDIR, "cache")
|
||||||
IP2LCACHE = os.path.join( MYDIR, "cache/ip2l" )
|
IP2LCACHE = os.path.join(MYDIR, "cache/ip2l")
|
||||||
|
|
||||||
ALIASES = os.path.join( MYDIR, "share/aliases" )
|
ALIASES = os.path.join(MYDIR, "share/aliases")
|
||||||
ANSI2HTML = os.path.join( MYDIR, "share/ansi2html.sh" )
|
ANSI2HTML = os.path.join(MYDIR, "share/ansi2html.sh")
|
||||||
BLACKLIST = os.path.join( MYDIR, "share/blacklist" )
|
BLACKLIST = os.path.join(MYDIR, "share/blacklist")
|
||||||
|
|
||||||
HELP_FILE = os.path.join( MYDIR, 'share/help.txt' )
|
HELP_FILE = os.path.join(MYDIR, 'share/help.txt')
|
||||||
BASH_FUNCTION_FILE = os.path.join( MYDIR, 'share/bash-function.txt' )
|
BASH_FUNCTION_FILE = os.path.join(MYDIR, 'share/bash-function.txt')
|
||||||
TRANSLATION_FILE = os.path.join( MYDIR, 'share/translation.txt' )
|
TRANSLATION_FILE = os.path.join(MYDIR, 'share/translation.txt')
|
||||||
TEST_FILE = os.path.join( MYDIR, 'share/test-NAME.txt' )
|
TEST_FILE = os.path.join(MYDIR, 'share/test-NAME.txt')
|
||||||
|
|
||||||
IATA_CODES_FILE = os.path.join(MYDIR, 'share/list-of-iata-codes.txt')
|
IATA_CODES_FILE = os.path.join(MYDIR, 'share/list-of-iata-codes.txt')
|
||||||
|
|
||||||
LOG_FILE = os.path.join( MYDIR, 'log/main.log' )
|
LOG_FILE = os.path.join(MYDIR, 'log/main.log')
|
||||||
TEMPLATES = os.path.join( MYDIR, 'share/templates' )
|
TEMPLATES = os.path.join(MYDIR, 'share/templates')
|
||||||
STATIC = os.path.join( MYDIR, 'share/static' )
|
STATIC = os.path.join(MYDIR, 'share/static')
|
||||||
|
|
||||||
NOT_FOUND_LOCATION = "not found"
|
NOT_FOUND_LOCATION = "not found"
|
||||||
DEFAULT_LOCATION = "oymyakon"
|
DEFAULT_LOCATION = "oymyakon"
|
||||||
|
@ -33,6 +37,8 @@ MALFORMED_RESPONSE_HTML_PAGE = open(os.path.join(STATIC, 'malformed-response.htm
|
||||||
LISTEN_HOST = ""
|
LISTEN_HOST = ""
|
||||||
LISTEN_PORT = 8002
|
LISTEN_PORT = 8002
|
||||||
|
|
||||||
|
MY_EXTERNAL_IP = '5.9.243.187'
|
||||||
|
|
||||||
PLAIN_TEXT_AGENTS = [
|
PLAIN_TEXT_AGENTS = [
|
||||||
"curl",
|
"curl",
|
||||||
"httpie",
|
"httpie",
|
||||||
|
@ -46,21 +52,24 @@ PLAIN_TEXT_PAGES = [':help', ':bash.function', ':translation']
|
||||||
IP2LOCATION_KEY = ''
|
IP2LOCATION_KEY = ''
|
||||||
|
|
||||||
def error(text):
|
def error(text):
|
||||||
|
"log error `text` and raise a RuntimeError exception"
|
||||||
|
|
||||||
if not text.startswith('Too many queries'):
|
if not text.startswith('Too many queries'):
|
||||||
print text
|
print text
|
||||||
logging.error("ERROR "+text)
|
logging.error("ERROR %s", text)
|
||||||
raise RuntimeError(text)
|
raise RuntimeError(text)
|
||||||
|
|
||||||
def log(text):
|
def log(text):
|
||||||
|
"log error `text` and do not raise any exceptions"
|
||||||
|
|
||||||
if not text.startswith('Too many queries'):
|
if not text.startswith('Too many queries'):
|
||||||
print text
|
print text
|
||||||
logging.info(text)
|
logging.info(text)
|
||||||
|
|
||||||
def get_help_file(lang):
|
def get_help_file(lang):
|
||||||
|
"Return help file for `lang`"
|
||||||
|
|
||||||
help_file = os.path.join(MYDIR, 'share/translations/%s-help.txt' % lang)
|
help_file = os.path.join(MYDIR, 'share/translations/%s-help.txt' % lang)
|
||||||
print ">>>", help_file
|
|
||||||
if os.path.exists(help_file):
|
if os.path.exists(help_file):
|
||||||
return help_file
|
return help_file
|
||||||
else:
|
return HELP_FILE
|
||||||
return HELP_FILE
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue