def index(): wallet = None # if the user is authed, get the wallet content ! if current_user.is_authenticated: # give the token data to esisecurity, it will check alone # if the access token need some update esisecurity.update_token(current_user.get_sso_data()) op = esiapp.op['get_characters_character_id_wallet']( character_id=current_user.character_id ) wallet = esiclient.request(op) op3 = esiapp.op['get_characters_character_id']( character_id=current_user.character_id ) char = esiclient.request(op3) print(char) op2 = esiapp.op['get_corporations_corporation_id_structures']( corporation_id=98656712 ) structures = esiclient.request(op2) #print (esiapp.op) #print(current_user) return render_template('base.html', **{ 'wallet': wallet, 'structures':structures, })
def index(): if current_user.is_authenticated: security.update_token(current_user.get_sso_data()) m = Markets(app, client) m.get_space_rich() return Response('done!') # mimetype='application/json')
def searchintel(): data = None if current_user.is_authenticated: esisecurity.update_token(current_user.get_sso_data()) return render_template('searchintel.html', **{ 'data': data, })
def getkillmails_nocache(char_id): if current_user.is_authenticated: esisecurity.update_token(current_user.get_sso_data()) token = current_user.access_token #op = esiapp.op['get_characters_character_id_killmails_recent']( # character_id=char_id, # datasource='tranquility', # token=token, #) #data = esiclient.request(op) #pprint(data.data) kms = [] systems = [] ships = [] data = getpubkms(char_id) for km in data: killmail_id = km['killmail_id'] killmail_hash = km['zkb']['hash'] killmail = None op = esiapp.op['get_killmails_killmail_id_killmail_hash']( killmail_id=killmail_id, killmail_hash=killmail_hash, ) kmdata = esiclient.request(op) #pprint(kmdata.data) try: victim = kmdata.data['victim'] is_victim = victim['character_id'] == char_id kmd = None if is_victim: kmd = kmdata.data['victim'] else: for attacker in kmdata.data['attackers']: #pprint(attacker) try: if attacker['character_id'] == char_id: kmd = attacker except KeyError: pass ship_id = kmd['ship_type_id'] ship_names = resolvenamesfromids([ship_id, kmdata.data['solar_system_id'], ]) ship_name = ship_names[0]['name'] solar_system = ship_names[1]['name'] #pprint(solar_system) ships.append(ship_name) systems.append(solar_system) except KeyError: pass return {'systems':systems, 'ships': ships} else: return []
def ingestkills(): kills = None if current_user.is_authenticated: esisecurity.update_token(current_user.get_sso_data()) op = esiapp.op['characters_character_id_killmails_recent']( character_id=current_user.character_id) kills = esiclient.request(op) return render_template('kills.html', **{ 'kills': kills, })
def wTransactions(): if current_user.is_authenticated: # Give the token data to esisecurity # it will check if the access token need some update security.update_token(current_user.get_sso_data()) f = Finance(app, client, id_char=current_user.character_id) data = f.get_data('wallet_transactions')[0] # f.write_mongo_data('wallet_transactions', data[0], update=False) # return jsonify(data) return Response(json.dumps(data), mimetype='application/json')
def index(): wallet = None # if the user is authed, get the wallet content ! if current_user.is_authenticated: # give the token data to esisecurity, it will check alone # if the access token need some update esisecurity.update_token(current_user.get_sso_data()) op = esiapp.op['get_characters_character_id_wallet']( character_id=current_user.character_id) wallet = esiclient.request(op) return render_template('base.html', **{ 'wallet': wallet, })
def gen_fit(): dict = request.get_json() if dict is None: return ('No data', 400) if not 'fit' in dict: return ('No fit', 400) if not 'evep_url' in dict: return ('No url', 400) if not 'cargo_size' in dict: return ('No size', 400) url = dict['evep_url'] if not url.endswith('.json'): url += '.json' fit = dict['fit'] try: size = float(dict['cargo_size']) except: out = {'msg': 'Invalid size "' + dict['cargo_size'] + '" supplied.'} return (json.dumps(out), 400) try: parsed_items = parse_evepraisal(url) except (MissingSchema, ConnectionError): out = {'msg': 'Invalid URL "' + dict['evep_url'] + '" supplied.'} return (json.dumps(out), 400) (optimal_items, size, val) = find_short_item_list(parsed_items, size, maxitems=255 - len(fit['items'])) expanded_fit = add_to_cargo(fit, optimal_items) expanded_fit = rename_fit(fit, dict['evep_url']) esisecurity.update_token(current_user.get_sso_data()) op = esiapp.op['post_characters_character_id_fittings']( character_id=current_user.character_id, fitting=expanded_fit) resp = esiclient.request(op) if resp.status != 201: print resp.status return render_template('error.html', **{'error_code': resp.status}) out = { 'msg': '"' + expanded_fit['name'] + '" created!', 'count': len(optimal_items), 'size': size, 'val': val } return (json.dumps(out), 201)
def update_token(current_user): sso_data = current_user.get_sso_data() esisecurity.update_token(sso_data) if sso_data['expires_in'] <= 10: try: tokens = esisecurity.refresh() except exceptions.SSLError: logging.error('ssl error refreshing token for: %s', current_user.get_id()) raise EsiError('ssl error refreshing token') except Exception as e: logging.error('error refreshing token for: %s', current_user.get_id()) logging.error('error is: %s', e) raise EsiError(e) current_user.update_token(tokens) return True
def debug(): if current_user.is_authenticated: # Give the token data to esisecurity # it will check if the access token need some update security.update_token(current_user.get_sso_data()) # else: # return redirect(url_for('/sso/login')) f = Finance(id_char=current_user.character_id, app=app, client=client) data = {'date': time.time(), 'total': f.get_data('wallet')} # f.write_mongo_data('wallet', [data], update=False) return render_template('base.html', **{ 'data': data['total'], })
def test(): if current_user.is_authenticated: security.update_token(current_user.get_sso_data()) f = Finance(current_user.character_id, app, client) data = { 'date': time.time(), 'wallet_total': f.get_data('wallet'), 'wallet_journal': f.get_data('wallet_journal'), 'wallet_transactions': f.get_data('wallet_transactions') } # f.write_mongo_data('wallet', [data], update=False) return render_template('base.html', **{ 'data': data, })
def transactions(): """ GET /characters/{character_id}/wallet/transactions/ Cached for 3600s """ transactions = None if current_user.is_authenticated: esisecurity.update_token(current_user.get_sso_data()) op = esiapp.op['get_characters_character_id_wallet_transactions']( character_id=current_user.character_id ) transactions = esiclient.request(op) pprint(transactions) return render_template('transactions.html', **{ 'transactions': transactions, })
def lookupresults(): data = None char_id = None char_info = None killmails = [] systems = None if current_user.is_authenticated: esisecurity.update_token(current_user.get_sso_data()) searchstr = request.args.get('string') if len(searchstr) > 0: data = searchapi(searchstr) if data.data is not None: char_id = data.data['character'][0] print("character id: %s" % (char_id,)) try: char_info = getcharinfo(char_id) try: killmails = getkillmails(char_id) except TypeError: pass except TypeError: pass names = resolvenamesfromids([char_info.corporation_id, char_info.alliance_id]) corp_name = names[1]['name'] alliance_name = names[0]['name'] return render_template('lookupresults.html', **{ 'data': data, 'char_id': char_id, 'char_info': char_info, 'systems': list(set(killmails['systems'])), 'ships': list(set(killmails['ships'])), 'corp_name': corp_name, 'alliance_name': alliance_name, })
def index(): wallet = None # if the user is authed, get the wallet content ! if current_user.is_authenticated: # give the token data to esisecurity, it will check alone # if the access token need some update esisecurity.update_token(current_user.get_sso_data()) op = esiapp.op['get_characters_character_id_fittings']( character_id=current_user.character_id) resp = esiclient.request(op) if resp.status != 200: print resp return render_template('error.html', **{'error_code': resp.status}) #Should return list of ships, each ship contains name & list of resp for that ship fits = process_resp(esiapp, esiclient, resp) return render_template('info.html', **{'fittings': fits}) # print json.dumps(resp.data, sort_keys=True, indent=4, separators=(',',': ')) return render_template('base.html')
def index(): num_of_kills = 0 current_char_location = None num_of_jumps = None hours = None character_id = None systems_with_kill = None if current_user.is_authenticated: # give the token data to esisecurity, it will check alone # if the access token need some update esisecurity.update_token(current_user.get_sso_data()) op = esiapp.op['get_characters_character_id_location']( character_id=current_user.character_id) char_location = esiclient.request(op).data char_system_info_req = esiapp.op['get_universe_systems_system_id']( system_id=char_location['solar_system_id']) char_system_info = esiclient.request(char_system_info_req).data character_id = current_user.character_id if request.method == 'POST': # Change settings if 'update_info' in request.form: num_of_jumps = request.form['num_of_jumps'] if num_of_jumps: session['num_of_jumps'] = num_of_jumps hours = request.form['hours'] if hours: session['hours'] = hours if 'num_of_jumps' not in session: session['num_of_jumps'] = '1' num_of_jumps = session['num_of_jumps'] if 'hours' not in session: session['hours'] = '1' hours = session['hours'] current_char_location = char_system_info['name'] if request.method == 'POST': if 'run_watchkeep' in request.form: char_location = char_system_info['system_id'] systems_with_kill = find_danger_systems( char_location=str(char_location), num_jumps=int(num_of_jumps), minutes=5) elif 'run_app' in request.form: char_location = char_system_info['system_id'] systems_with_kill = find_danger_systems( char_location=str(char_location), num_jumps=int(num_of_jumps), minutes=(float(hours) * 60)) if systems_with_kill: num_of_kills = systems_with_kill.__len__() return render_template( 'base.html', **{ 'char_location': current_char_location, 'char_avatar_url': 'https://image.eveonline.com/Character/' + str(character_id) + '_256.jpg', 'num_of_jumps': num_of_jumps, 'hours': hours, 'systems_with_kill': systems_with_kill, 'num_of_kills': num_of_kills })
def logout(): sso_data = current_user.get_sso_data() esisecurity.update_token(sso_data) esisecurity.revoke() logout_user() return redirect(url_for("main_pages.index"))
def index(): """ Fill this in later :return: """ wallet = None ganked_kills = None global cache_timer code = False list_of_all_attackers = [] npc_id = [] # if the user is authed, get the wallet content ! if current_user.is_authenticated: # give the token data to esisecurity, it will check alone # if the access token need some update esisecurity.update_token(current_user.get_sso_data()) op = esiapp.op['get_characters_character_id_wallet']( character_id=current_user.character_id ) # op2 = esiapp.op['get_characters_character_id_contacts'](character_id=current_user.character_id) wallet = esiclient.request(op) # contact_list = esiclient.request(op2) # if contact_list is not None: # for x in contact_list.data: # if x['contact_type'] not in ('corporation', 'alliance'): # op3 = esiapp.op['get_characters_names'](character_ids=str(x['contact_id'])) # character_name = esiclient.request(op3).data[0]['character_name'] # x['character_name'] = character_name ############################### ### Beging Killmail Parsing ### ############################### # Kill ID url: https://zkillboard.com/api/killID/69334556/ # Ganked Url: https://zkillboard.com/api/ganked/ ct = time.time() if (ct - cache_timer) > float(900): print(ct - cache_timer) ganked_kills = json.loads(requests.get('https://zkillboard.com/api/ganked/').content) km = Killmails() cc = Contact() cache_timer = time.time() for killmail in ganked_kills: try: km.query.filter_by(killmail_id=killmail['killmail_id']).one() except NoResultFound: km.attackers = str(killmail['attackers']) km.killmail_id = int(killmail['killmail_id']) km.killmail_time = str(killmail['killmail_time']) km.solar_system = int(killmail['solar_system_id']) km.victim = str(killmail['victim']) try: db.session.merge(km) db.session.commit() except: logger.exception("Cannot login the user - uid: %d" % km.killmail_id) db.session.rollback() for index in killmail['attackers']: if 'alliance_id' in index and 99002775 == index['alliance_id']: if code: pass else: code = True elif ('alliance_id' in index and 99002775 != index['alliance_id']) or ('alliance_id' not in index): try: npc_id.append(index['character_id']) except: print(Exception.message) if code: ## Add npc_id character ID's to contact list with -10 standings pass else: ## remove NPC id's and proceed to next killmail pass chk_contacts(npc_id, current_user) # for id in npc_id: # try: # Contact.query.filter_by(character_contact_id=id).one() # except NoResultFound: # cc.character_contact_id = id # cc.character_contact_standing = (-10) # try: # db.session.merge(cc) # db.session.commit() # except: # logger.exception('Cannot insert - {}'.format(cc.character_id)) # db.session.rollback() # for attacker in killmail['attackers']: # try: # list_of_all_attackers.append( # {'character_id': attacker['character_id'], # 'corporation_id': attacker['corporation_id'], # 'alliance_id': attacker['alliance_id'] # } # ) # except KeyError: # pass print(ct - cache_timer) # kms = Killmails.query.all() # t = 0 # ## CODE. Alliance ID: 99002775 # atk_list = [] # old_cid = [] # new_cids = [] # for x in range(len(kms)): # l = len(ast.literal_eval(ast.literal_eval(json.dumps(kms[x].attackers)))) # for a in range(l): # attks = ast.literal_eval(ast.literal_eval(json.dumps(kms[x].attackers)))[a] # try: # if attks['alliance_id'] == 99002775: # code = True # pass # except KeyError: # try: # old_cid.append(attks['character_id']) # except KeyError: # pass # if code: # for a in range(l): # cid = a['character_id'] # new_cids.append(cid) # # op5 = esiapp.op['post_characters_character_id_contacts_contact_ids'](character_id='{}'.format(cid)) # char = esiclient.request(op5) # # # # # pass # ast.literal_eval(ast.literal_eval(json.dumps(kms[x].attackers)))[x]['character_id'] # # pass # op5 = esiapp.op['get_characters_character_id_ok'](character_id='{}'.format(cid)) # try: # db.session.merge(km) # db.session.commit() # except: # logger.exception("Cannot login the user - uid: %d" % km.killmail_id) # db.session.rollback() return render_template('base.html', **{ 'wallet': wallet, })