async def post_clients(self, request): data = await request.json() with DB.atomic(): realm = Realm.select().where(Realm.name == data['realm']).first() if not realm: realm = Realm.create(name=data['realm']) try: instance = self.orchestrator.add_instance( realm=realm, instance_type=data['instance_type'], config_kwargs=data.get('config', {}), ) except asyncio.TimeoutError: return JsonResponse( data={'detail': 'Alcazar is busy performing another action. Try again later.'}, status=503, ) return JsonResponse(instance.get_info_dict())
def populate_realms_db(): """ If user executes script for the first time, populate db with realm names """ print("Populating database with realm names, might take a few minutes") url = "http://{region}.battle.net/api/wow/realm/status?locale={locale}" regions = { "eu": ['de_DE', 'en_GB', 'pt_BR', 'fr_FR', 'ru_RU', 'es_ES', 'it_IT'], "us": ["en_US", "es_MX", "pt_BR"], "kr": ["ko_KR"], "tw": ["zh_TW"], } for region in regions: locales = regions[region] for locale in locales: r = requests.get(url.format(region=region, locale=locale)) data = r.json() for realm in data["realms"]: if realm["locale"] == locale: english_name = get_eng_rlm_name(realm["slug"], region) # print(region, locale, realm["name"], english_name, realm["slug"]) rlm = Realm() rlm.name = english_name # Localised names in AH dump are without spaces rlm.name_localised = realm["name"].replace(" ", "") rlm.slug = realm["slug"] rlm.region = region rlm.locale = locale session.add(rlm) session.commit()
async def force_recheck(self, request): realm = Realm.select().where(Realm.name == request.match_info['realm_name']).first() if not realm: return JsonResponse({'detail': 'Realm does not exist. Create it by adding a client to it.'}, status=400) try: await self.orchestrator.force_recheck( realm=realm, info_hash=request.match_info['info_hash'] ) return JsonResponse({}) except TorrentNotFoundException: return JsonResponse({'detail': 'Torrent not found.'}, status=404) except asyncio.TimeoutError: return JsonResponse({'detail': 'Alcazar is busy performing another action. Try again later.'}, status=503)
async def post_torrents(self, request): data = await request.json() realm = Realm.select().where(Realm.name == request.match_info['realm_name']).first() if not realm: return JsonResponse({'detail': 'Realm does not exist. Create it by adding a client to it.'}, status=400) try: data = await self.orchestrator.add_torrent( realm=realm, torrent_file=base64.b64decode(data['torrent']), download_path=data['download_path'], name=data.get('name'), ) except (NotInitializedException, NoManagerForRealmException) as exc: return JsonResponse({'detail': str(exc)}, status=400) except TorrentAlreadyAddedException as exc: return JsonResponse({'detail': str(exc)}, status=409) except asyncio.TimeoutError: return JsonResponse({'detail': 'Alcazar is busy performing another action. Try again later.'}, status=503) return JsonResponse(data)