def contracts(request, tokens): start_time = time.time() active_token, char_name, char_id = prepare_view(request, tokens) user_list = [] for token in tokens: user_list.append({ 'user_id': token.character_id, 'user_name': token.character_name }) logger('User {} requested page /contracts' .format(char_name), 'info', 'stats') # avail_contracts = get_corp_contracts(corporation_id) # print(wallet.data) logger('/contracts generated in: {}'.format(time.time() - start_time), 'info', 'stats') context = { 'atoken': active_token.valid_access_token(), 'name': char_name, 'char_id': char_id, 'tokens': user_list, 'page_link': 'contracts', 'page_name': 'Contracts' } return render(request, 'dashboard/contracts.html', context)
def index(request, tokens): start_time = time.time() active_token, char_name, char_id = prepare_view(request, tokens) logger('User {} requested page /index' .format(char_name), 'info', 'stats') # Get planet details. # TODO: Move this over to AJAX user_list = [] for token in tokens: user_list.append({ 'user_id': token.character_id, 'user_name': token.character_name }) print('User list: {}'.format(user_list)) planets = get_user_planets(active_token) logger('/contracts generated in: {}'.format(time.time() - start_time), 'info', 'stats') context = { 'name': char_name, 'char_id': char_id, 'planets': planets, 'tokens': user_list, 'page_link': 'index', 'page_name': 'Dashboard' } return render(request, 'dashboard/index.html', context)
def calendar(request, tokens): start_time = time.time() char_name = None event_list = None output_list = None # if the user is authed, get the wallet content ! active_token, char_name, char_id = prepare_view(request, tokens) user_list = [] for token in tokens: user_list.append({ 'user_id': token.character_id, 'user_name': token.character_name }) logger('User {} requested page /calendar' .format(char_name), 'info', 'stats') output_list = [] event_list = esi.client.Calendar.get_characters_character_id_calendar( character_id=char_id, token=active_token.valid_access_token() ).result() for event in event_list: print('——') print(event) res = esi.client.Calendar.get_characters_character_id_calendar_event_id( character_id=char_id, event_id=event['event_id'], token=active_token.valid_access_token() ).result() event_start = res['date'] event_end = event_start + timedelta(minutes=res['duration']) if res['importance'] == 0: color = '#0073b7' else: color = '#f56954' output_list.append({ 'title': res['title'], 'start': time.mktime(event_start.timetuple()), 'end': time.mktime(event_end.timetuple()), 'backgroundColor': color, 'borderColor': color }) logger('/calendar generated in: {}'.format(time.time() - start_time), 'info', 'stats') context = { 'name': char_name, 'char_id': char_id, 'event_list': output_list, 'tokens': user_list, 'page_link': 'calendar', 'page_name': 'Calendar' } return render(request, 'dashboard/calendar.html', context)
def ajax_remove_timer(request, tokens): start_time = time.time() active_token, char_name, char_id = prepare_view(request, tokens) logger('User {} is removing a timer.' .format(char_name), 'info', 'stats') data = json.loads(request.data) logger(str(data), 'info', 'stats') corporation_id = esi.client.Character.get_characters_character_id( character_id=char_id ).result()['corporation_id'] if str(corporation_id) in timer_boards_corp.keys(): corp_contracts = timer_boards_corp[str(corporation_id)] for i in range(len(corp_contracts)): try: if data['sName'] == corp_contracts[i]['name']: del corp_contracts[i] timer_boards_corp[str(corporation_id)] = corp_contracts with open('timer_boards_corp.json', 'w') as jsonfile: json.dump(timer_boards_corp, jsonfile, ensure_ascii=False, indent=4) return JsonResponse({'status': 'success'}) except Exception as e: logger('Failed parsing Structure name: {}'.format(data), 'error', 'error') logger(str(e), 'error', 'error') return JsonResponse({'status': 'error: sName'}) else: return JsonResponse({'status': 'not found'})
def ajax_get_walletbalance(request, tokens): start_time = time.time() active_token, char_name, char_id = prepare_view(request, tokens) result = esi.client.Wallet.get_characters_character_id_wallet( character_id=char_id, token=active_token.valid_access_token()).result() try: return HttpResponse('{:,.2f}'.format(result)) except Exception as e: logger('Error getting wallet balance:', 'error', 'error') logger('Error: {}, response: {}'.format(str(e), result), 'error', 'error') print('Error getting wallet balance: {}'.format(e)) return HttpResponse('0')
def ajax_remove_timer(request, tokens): active_token, char_name, char_id = prepare_view(request, tokens) logger('User {} is removing a timer.'.format(char_name), 'info', 'stats') data = json.loads(request.body) logger(str(data), 'info', 'stats') corporation_id = esi.client.Character.get_characters_character_id( character_id=char_id).result()['corporation_id'] timer = StructureTimer.objects.filter(timer_corp=corporation_id, tid=data['tid']).all() if timer is not None: timer.delete() return JsonResponse({'status': 'success'}) else: return JsonResponse({'status': 'not found'})
def market(request, tokens): start_time = time.time() active_token, char_name, char_id = prepare_view(request, tokens) user_list = [] for token in tokens: user_list.append({ 'user_id': token.character_id, 'user_name': token.character_name }) logger('User {} requested page /market'.format(char_name), 'info', 'stats') logger('/market generated in: {}'.format(time.time() - start_time), 'info', 'stats') context = { 'name': char_name, 'char_id': char_id, 'tokens': user_list, 'page_link': 'market', 'page_name': 'Market' } return render(request, 'dashboard/market.html', context)
def ajax_new_timer(request, tokens): start_time = time.time() active_token, char_name, char_id = prepare_view(request, tokens) logger('User {} added a new timer.' .format(char_name), 'info', 'stats') print('Data: {}'.format(json.loads(request.data))) data = json.loads(request.data) logger(str(data), 'info', 'stats') # return JsonResponse({'status': 'debug return'}) try: namesplit = data['inputDscan'].split('\t') loc, name = namesplit[1].split(' - ', 1) type = namesplit[2] type_id = namesplit[0] except Exception as e: logger('Failed parsing Dscan: {}'.format(data), 'error', 'error') logger(str(e), 'error', 'error') return JsonResponse({'status': 'error: Dscan'}) try: data['timer_type'] except Exception as e: logger('Failed parsing Timer type: {}'.format(data), 'error', 'error') logger(str(e), 'error', 'error') return JsonResponse({'status': 'error: timer_type'}) days = '0' try: if 'd' in data['inputTimeleft']: days, time = data['inputTimeleft'].split('d', 1) elif 'D' in data['inputTimeleft']: days, time = data['inputTimeleft'].split('D', 1) else: time = data['inputTimeleft'] except Exception as e: logger('Failed parsing Time left: {}'.format(data), 'error', 'error') logger(str(e), 'error', 'error') return JsonResponse({'status': 'error: inputTimeleft'}) try: timer_notes = data['inputNotes'] except Exception as e: logger('Failed parsing Timer notes: {}'.format(data), 'error', 'error') logger(str(e), 'error', 'error') return JsonResponse({'status': 'error: timer_notes'}) # print(timeparse(time)) time_left = timedelta(days=int(days), seconds=timeparse(time)) # return JsonResponse({'status': 'debug return'}) corporation_id = esi.client.Character.get_characters_character_id( character_id=char_id ).result()['corporation_id'] StructureTimer( tid=random.randint(10000000, 99999999), timer_corp=corporation_id, location=loc, timer_type=data['timer_type'], structure_type_id=type_id, structure_type_name=type, structure_name=name, structure_corp=0, time=(datetime.utcnow() + time_left).isoformat(), notes=timer_notes ).save() return JsonResponse({'status': 'success'})
def ajax_new_timer(request, tokens): active_token, char_name, char_id = prepare_view(request, tokens) logger('User {} added a new timer.'.format(char_name), 'info', 'stats') print('Data: {}'.format(request.body)) data = json.loads(request.body) logger(str(data), 'info', 'stats') namesplit = -1 loc = '' str_name = '' str_type_name = '' str_type_id = 0 owner_id = 0 if data['corpOwner'] is not None: owner_obj = Corporation.objects.filter( id=int(data['corpOwner'])).first() if owner_obj is not None: owner_id = owner_obj.id else: owner_id = 0 try: namesplit = data['inputDscan'].split('\t', 3) loc, str_name = namesplit[1].split(' - ', 1) str_type_name = namesplit[2] str_type_id = namesplit[0] except Exception as e: logger('Failed parsing Dscan: {}'.format(data), 'error', 'error') logger(str(e), 'error', 'error') namesplit = data['inputDscan'].split(' ') name_words = namesplit.copy() print('Words: {}'.format(namesplit)) for item in namesplit: print('Parsing word: {}'.format(item.capitalize())) system = EveSolarSystem.objects.filter( name=item.capitalize()).first() if system is not None: print('System: {}'.format(system)) loc = system.name name_words.remove(item) type = EveType.objects.filter(name=item.capitalize()).first() if type is not None: print('Type: {}'.format(type)) str_type_name = type.name str_type_id = type.id name_words.remove(item) str_name = ' '.join(name_words) try: data['timer_type'] except Exception as e: logger('Failed parsing Timer type: {}'.format(data), 'error', 'error') logger(str(e), 'error', 'error') return JsonResponse({'status': 'error: timer_type'}) days = '0' try: if 'd' in data['inputTimeleft']: days, time = data['inputTimeleft'].split('d', 1) elif 'D' in data['inputTimeleft']: days, time = data['inputTimeleft'].split('D', 1) else: time = data['inputTimeleft'] except Exception as e: logger('Failed parsing Time left: {}'.format(data), 'error', 'error') logger(str(e), 'error', 'error') return JsonResponse({'status': 'error: inputTimeleft'}) try: timer_notes = data['inputNotes'] except Exception as e: logger('Failed parsing Timer notes: {}'.format(data), 'error', 'error') logger(str(e), 'error', 'error') return JsonResponse({'status': 'error: timer_notes'}) # print(timeparse(time)) time_left = timedelta(days=int(days), seconds=timeparse(time)) # return JsonResponse({'status': 'debug return'}) corporation_id = esi.client.Character.get_characters_character_id( character_id=char_id).result()['corporation_id'] StructureTimer(tid=random.randint(10000000, 99999999), timer_corp=corporation_id, location=loc, timer_type=data['timer_type'], structure_type_id=str_type_id, structure_type_name=str_type_name, structure_name=str_name, structure_corp=owner_id, time=(datetime.utcnow() + time_left).replace(tzinfo=pytz.UTC).isoformat(), notes=timer_notes).save() return JsonResponse({'status': 'success'})