diff options
author | James Taylor <user234683@users.noreply.github.com> | 2018-07-13 15:51:04 -0700 |
---|---|---|
committer | James Taylor <user234683@users.noreply.github.com> | 2018-07-13 15:51:04 -0700 |
commit | 12382d5205fa3ba38f0dad8df8e4fc266ba01f29 (patch) | |
tree | f38bb259cafa4d248e63d81f3b01eeb0d0268530 | |
parent | c3b9f8c4582882cd1f768b0727eca75475bb4f94 (diff) | |
download | yt-local-12382d5205fa3ba38f0dad8df8e4fc266ba01f29.tar.lz yt-local-12382d5205fa3ba38f0dad8df8e4fc266ba01f29.tar.xz yt-local-12382d5205fa3ba38f0dad8df8e4fc266ba01f29.zip |
move settings to file, fix error if no banned_addresses.txt
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | server.py | 22 | ||||
-rw-r--r-- | settings.py | 11 |
3 files changed, 24 insertions, 10 deletions
@@ -4,3 +4,4 @@ __pycache__/ debug/ data/ banned_addresses.txt +settings.txt @@ -10,13 +10,15 @@ import socks import subprocess import re -ROUTE_TOR = True -PORT_NUMBER=80 -ALLOW_FOREIGN_ADDRESSES=False +import settings + BAN_FILE = "banned_addresses.txt" -with open(BAN_FILE, 'r') as f: - banned_addresses = f.read().splitlines() +try: + with open(BAN_FILE, 'r') as f: + banned_addresses = f.read().splitlines() +except FileNotFoundError: + banned_addresses = () def ban_address(address): banned_addresses.append(address) @@ -127,15 +129,15 @@ def site_dispatch(env, start_response): -if ROUTE_TOR: +if settings.route_tor: #subprocess.Popen(TOR_PATH) socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, '127.0.0.1', 9150) socket.socket = socks.socksocket gevent.socket.socket = socks.socksocket -if ALLOW_FOREIGN_ADDRESSES: - server = WSGIServer(('0.0.0.0', PORT_NUMBER), site_dispatch) +if settings.allow_foreign_addresses: + server = WSGIServer(('0.0.0.0', settings.port_number), site_dispatch) else: - server = WSGIServer(('127.0.0.1', PORT_NUMBER), site_dispatch) -print('Started httpserver on port ' , PORT_NUMBER) + server = WSGIServer(('127.0.0.1', settings.port_number), site_dispatch) +print('Started httpserver on port ' , settings.port_number) server.serve_forever() diff --git a/settings.py b/settings.py new file mode 100644 index 0000000..499b32b --- /dev/null +++ b/settings.py @@ -0,0 +1,11 @@ +default_settings = '''route_tor = False +port_number = 80 +allow_foreign_addresses = False +''' +exec(default_settings) +try: + with open('settings.txt', 'r', encoding='utf-8') as file: + exec(file.read()) +except FileNotFoundError: + with open('settings.txt', 'a', encoding='utf-8') as file: + file.write(default_settings)
\ No newline at end of file |