forked from AHAAAAAAA/PokemonGo-Map
-
Notifications
You must be signed in to change notification settings - Fork 2
/
runserver.py
83 lines (62 loc) · 2.37 KB
/
runserver.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/python
# -*- coding: utf-8 -*-
import os
import sys
import logging
import time
from threading import Thread
from flask_cors import CORS, cross_origin
from pogom import config
from pogom.app import Pogom
from pogom.utils import get_args, insert_mock_data, load_credentials
from pogom.search import search_loop
from pogom.models import create_tables, Pokemon, Pokestop, Gym
from pogom.pgoapi.utilities import get_pos_by_name
log = logging.getLogger(__name__)
search_thread = Thread()
def start_locator_thread(args):
search_thread = Thread(target=search_loop, args=(args,))
search_thread.daemon = True
search_thread.name = 'search_thread'
search_thread.start()
if __name__ == '__main__':
logging.basicConfig(level=logging.INFO, format='%(asctime)s [%(module)11s] [%(levelname)7s] %(message)s')
logging.getLogger("peewee").setLevel(logging.INFO)
logging.getLogger("requests").setLevel(logging.WARNING)
logging.getLogger("pogom.pgoapi.pgoapi").setLevel(logging.WARNING)
logging.getLogger("pogom.pgoapi.rpc_api").setLevel(logging.INFO)
logging.getLogger('werkzeug').setLevel(logging.ERROR)
args = get_args()
if args.debug:
logging.getLogger("requests").setLevel(logging.DEBUG)
logging.getLogger("pgoapi").setLevel(logging.DEBUG)
logging.getLogger("rpc_api").setLevel(logging.DEBUG)
create_tables()
position = get_pos_by_name(args.location)
if not any(position):
log.error('Could not get a position by name, aborting.')
sys.exit()
log.info('Parsed location is: {:.4f}/{:.4f}/{:.4f} (lat/lng/alt)'.
format(*position))
config['ORIGINAL_LATITUDE'] = position[0]
config['ORIGINAL_LONGITUDE'] = position[1]
config['LOCALE'] = args.locale
config['CHINA'] = args.china
if not args.mock:
start_locator_thread(args)
else:
insert_mock_data()
app = Pogom(__name__)
if args.cors:
CORS(app);
config['ROOT_PATH'] = app.root_path
if args.gmaps_key is not None:
config['GMAPS_KEY'] = args.gmaps_key
else:
config['GMAPS_KEY'] = load_credentials(os.path.dirname(os.path.realpath(__file__)))['gmaps_key']
if args.no_server:
while not search_thread.isAlive():
time.sleep(1)
search_thread.join()
else:
app.run(threaded=True, debug=args.debug, host=args.host, port=args.port)