def application_report(report): """ Report that use the api given during the application process """ # Creating EveTools object eve = EveTools(key_id=report['api']['key_id'], vcode=report['api']['vcode']) # Resetting report report['characters'] = [] report['errors'] = [] # Let's start by checking the api key try: eve.check_key() except Exception as e: app.logger.exception(e) report['errors'].append(e.message) # Get full character info for eve_character in eve.get_characters(): character = EveTools.auto_to_dict(eve_character) character['history'] = [] for eve_corporation in eve_character.employmentHistory: corporation = EveTools.auto_to_dict(eve.safe_request('corp/CorporationSheet', True, {'corporationID': eve_corporation.corporationID})) sleep(0.5) character['history'].append({ 'corporation_id': corporation['corporationID'], 'corporation_name': corporation['corporationName'], 'ticker': 'BR', 'alliance_id': corporation['allianceID'] if 'allianceID' in corporation else None, 'alliance_name': corporation['allianceName'] if 'allianceName' in corporation else None, 'start_date': datetime.datetime.utcfromtimestamp(eve_corporation.startDate) }) # Contact list character['contacts'] = [] contacts = eve.safe_request('char/ContactList', False, {'characterID': character['characterID']}).contactList for contact in contacts: if contact.contactID > 3020000: character['contacts'].append(EveTools.auto_to_dict(contact)) # Standings standings = eve.safe_request('char/Standings', False, {'characterID': character['characterID']}) character['standings'] = EveTools.auto_to_dict(standings.characterNPCStandings) # Wallet character['wallet'] = EveTools.auto_to_dict(eve.safe_request('char/WalletJournal', False, {'characterID': character['characterID'], 'rowCount': 2560}).transactions) # Assets time ! assets = eve.safe_request('char/AssetList', False, {'characterID': character['characterID']}).assets character['assets'] = EveTools.parse_assets(EveTools.auto_to_dict(assets)) report['characters'].append(character) return report
def get_characters(key_id, vcode): """ Return all the user's characters """ if len(vcode) != 64: return jsonify(error='Invalid vCode'), 400 eve = EveTools(key_id=key_id, vcode=vcode, cache=True) try: characters = eve.get_characters(public=True) except EveException as e: return jsonify(error=e.value), 500 except Exception as e: return jsonify(error=e.message), 400 return jsonify(characters=[ EveTools.element_to_dict(character) for character in characters ])
def get_characters(key_id, vcode): """ Return all the user's characters """ if len(vcode) != 64: return jsonify(error='Invalid vCode'), 400 eve = EveTools(key_id=key_id, vcode=vcode, cache=True) try: characters = eve.get_characters(public=True) except EveException as e: return jsonify(error=e.value), 500 except Exception as e: return jsonify(error=e.message), 400 return jsonify( characters=[EveTools.element_to_dict(character) for character in characters])
def new_application(): """ Create the new application """ form_data = request.get_json() application_form = ApplicationForm(MultiDict(form_data)) if not application_form.validate(): return jsonify(error='Validation error, ' 'we could not validate your application.'), 400 # Form is valid, let's check everything is valid eve = EveTools(key_id=application_form.key_id.data, vcode=application_form.vcode.data, cache=True) try: eve.check_key() characters = eve.get_characters(public=True) for character in characters: if character.characterID == application_form.character_id.data: character_sheet = character break else: raise Exception('Character not found with provided API Key') corporation = mongo.db.corporations.find_one( {'corporation_id': application_form.corporation_id.data}) if corporation is None or corporation['active'] is False: raise Exception('You cannot apply to this corporation') except EveException as e: return jsonify(error=e.value), 500 except Exception as e: app.logger.exception(e) return jsonify(error=e.message), 400 # Do we have a reddit key ? if all(['reddit_key' in form_data, 'reddit_username' in form_data]): r = redis.StrictRedis(host=app.config['REDIS']) reddit_username = r.get('hr2:reddit:{}'.format( form_data['reddit_key'])) if reddit_username != form_data['reddit_username']: return jsonify(error='Invalid Reddit token, ' 'maybe it has expired ?'), 403 # Well, everything looks alright, let's create the application ! user_id = application_form.character_name.data.replace(" ", "_").lower() application = { 'applicant': { 'user_id': user_id, 'character_id': application_form.character_id.data, 'character_name': application_form.character_name.data, 'email': application_form.email.data, 'key_id': application_form.key_id.data, 'vcode': application_form.vcode.data, 'reddit_username': form_data.get('reddit_username', None), 'corporation_id': character_sheet.corporationID, 'corporation_name': character_sheet.corporation, 'alliance_id': character_sheet.__dict__.get('allianceID', None), 'alliance_name': character_sheet.__dict__.get('alliance', None) }, 'corporation': { 'corporation_id': application_form.corporation_id.data, 'corporation_name': application_form.corporation_name.data }, 'motivation': application_form.motivation.data, 'status': Status.Pending.value, 'created_at': datetime.datetime.utcnow() } mongo.db.applications.insert(application) return jsonify(result='success'), 200
def new_application(): """ Create the new application """ form_data = request.get_json() application_form = ApplicationForm(MultiDict(form_data)) if not application_form.validate(): return jsonify(error='Validation error, ' 'we could not validate your application.'), 400 # Form is valid, let's check everything is valid eve = EveTools(key_id=application_form.key_id.data, vcode=application_form.vcode.data, cache=True) try: eve.check_key() characters = eve.get_characters(public=True) for character in characters: if character.characterID == application_form.character_id.data: character_sheet = character break else: raise Exception('Character not found with provided API Key') corporation = mongo.db.corporations.find_one({'corporation_id': application_form.corporation_id.data}) if corporation is None or corporation['active'] is False: raise Exception('You cannot apply to this corporation') except EveException as e: return jsonify(error=e.value), 500 except Exception as e: app.logger.exception(e) return jsonify(error=e.message), 400 # Do we have a reddit key ? if all(['reddit_key' in form_data, 'reddit_username' in form_data]): r = redis.StrictRedis(host=app.config['REDIS']) reddit_username = r.get('hr2:reddit:{}'.format(form_data['reddit_key'])) if reddit_username != form_data['reddit_username']: return jsonify(error='Invalid Reddit token, ' 'maybe it has expired ?'), 403 # Well, everything looks alright, let's create the application ! user_id = application_form.character_name.data.replace(" ", "_").lower() application = { 'applicant': { 'user_id': user_id, 'character_id': application_form.character_id.data, 'character_name': application_form.character_name.data, 'email': application_form.email.data, 'key_id': application_form.key_id.data, 'vcode': application_form.vcode.data, 'reddit_username': form_data.get('reddit_username', None), 'corporation_id': character_sheet.corporationID, 'corporation_name': character_sheet.corporation, 'alliance_id': character_sheet.__dict__.get('allianceID', None), 'alliance_name': character_sheet.__dict__.get('alliance', None) }, 'corporation': { 'corporation_id': application_form.corporation_id.data, 'corporation_name': application_form.corporation_name.data }, 'motivation': application_form.motivation.data, 'status': Status.Pending.value, 'created_at': datetime.datetime.utcnow() } mongo.db.applications.insert(application) return jsonify(result='success'), 200
def application_report(report): """ Report that use the api given during the application process """ # Creating EveTools object eve = EveTools(key_id=report['api']['key_id'], vcode=report['api']['vcode']) # Resetting report report['characters'] = [] report['errors'] = [] # Let's start by checking the api key try: eve.check_key() except Exception as e: app.logger.exception(e) report['errors'].append(e.message) # Get full character info for eve_character in eve.get_characters(): character = EveTools.auto_to_dict(eve_character) character['history'] = [] for eve_corporation in eve_character.employmentHistory: corporation = EveTools.auto_to_dict( eve.safe_request( 'corp/CorporationSheet', True, {'corporationID': eve_corporation.corporationID})) sleep(0.5) character['history'].append({ 'corporation_id': corporation['corporationID'], 'corporation_name': corporation['corporationName'], 'ticker': 'BR', 'alliance_id': corporation['allianceID'] if 'allianceID' in corporation else None, 'alliance_name': corporation['allianceName'] if 'allianceName' in corporation else None, 'start_date': datetime.datetime.utcfromtimestamp(eve_corporation.startDate) }) # Contact list character['contacts'] = [] contacts = eve.safe_request('char/ContactList', False, { 'characterID': character['characterID'] }).contactList for contact in contacts: if contact.contactID > 3020000: character['contacts'].append(EveTools.auto_to_dict(contact)) # Standings standings = eve.safe_request('char/Standings', False, {'characterID': character['characterID']}) character['standings'] = EveTools.auto_to_dict( standings.characterNPCStandings) # Wallet character['wallet'] = EveTools.auto_to_dict( eve.safe_request('char/WalletJournal', False, { 'characterID': character['characterID'], 'rowCount': 2560 }).transactions) # Assets time ! assets = eve.safe_request('char/AssetList', False, { 'characterID': character['characterID'] }).assets character['assets'] = EveTools.parse_assets( EveTools.auto_to_dict(assets)) report['characters'].append(character) return report