Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- import os
- import sys
- import logging
- import time
- from threading import Thread
- from flask import Flask, jsonify, render_template, request
- from flask_cors import CORS
- from pogom import config
- from pogom.app import Pogom
- from pogom.utils import get_args, insert_mock_data
- from pogom.search import search_loop, create_search_threads, fake_search_loop
- from pogom.models import init_database, create_tables, Pokemon, Pokestop, Gym
- from pogom.pgoapi.utilities import get_pos_by_name
- from pogom.pgoapi.auth_google import AuthGoogle
- from pogom.pgoapi.auth_ptc import AuthPtc
- logging.basicConfig(format='%(asctime)s [%(module)14s] [%(levelname)7s] %(message)s')
- log = logging.getLogger()
- app = Pogom(__name__)
- def initMap() :
- args = get_args()
- if args.debug:
- log.setLevel(logging.DEBUG);
- else:
- log.setLevel(logging.INFO);
- # These are very noisey, let's shush them up a bit
- 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)
- config['parse_pokemon'] = not args.no_pokemon
- config['parse_pokestops'] = not args.no_pokestops
- config['parse_gyms'] = not args.no_gyms
- # Turn these back up if debugging
- if args.debug:
- logging.getLogger("requests").setLevel(logging.DEBUG)
- logging.getLogger("pgoapi").setLevel(logging.DEBUG)
- logging.getLogger("rpc_api").setLevel(logging.DEBUG)
- db = init_database()
- create_tables(db)
- 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))
- if args.no_pokemon:
- log.info('Parsing of Pokemon disabled.')
- if args.no_pokestops:
- log.info('Parsing of Pokestops disabled.')
- if args.no_gyms:
- log.info('Parsing of Gyms disabled.')
- config['ORIGINAL_LATITUDE'] = position[0]
- config['ORIGINAL_LONGITUDE'] = position[1]
- config['LOCALE'] = args.locale
- config['CHINA'] = args.china
- if not args.only_server:
- # Gather the pokemons!
- if not args.mock:
- log.debug('Starting a real search thread and {} search runner thread(s)'.format(args.num_threads))
- create_search_threads(args.num_threads)
- search_thread = Thread(target=search_loop, args=(args,))
- else:
- log.debug('Starting a fake search thread')
- insert_mock_data()
- search_thread = Thread(target=fake_search_loop)
- search_thread.daemon = True
- search_thread.name = 'search_thread'
- search_thread.start()
- if args.cors:
- CORS(app);
- config['ROOT_PATH'] = app.root_path
- config['GMAPS_KEY'] = args.gmaps_key
- config['REQ_SLEEP'] = args.scan_delay
- @app.route('/ajaxTryStart', methods=['POST'])
- def ajaxTryStart() :
- username = request.form['username']
- password = request.form['password']
- location = request.form['location']
- gmapsKey = request.form['gmapsKey']
- steps = '5'
- scanDelay = '5'
- authType = 'ptc'
- authProvider = AuthPtc()
- if '@gmail' in username :
- authProvider = AuthGoogle()
- authType = 'google'
- if authProvider.login(username, password):
- mapConfig['authType'] = authType
- mapConfig['username'] = username
- mapConfig['password'] = password
- mapConfig['location'] = location
- mapConfig['gmapsKey'] = gmapsKey
- mapConfig['steps'] = steps
- mapConfig['scanDelay'] = scanDelay
- app.mapConfig = mapConfig
- initMap()
- #return jsonify(errors=False,success='Inloggning lyckades')
- else :
- return jsonify(errors='Fel inloggningsuppgifter',success=False)
- @app.route('/')
- def controlPanel() :
- return render_template('index.html')
- if __name__ == '__main__':
- app.run(threaded=True, use_reloader=False, debug=False, host='127.0.0.1', port='5000')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement