Пример #1
0
def test():
    if not request.is_json:
        return 'request is not json'
    params = request.get_json()
    jwt_data = get_jwt()
    
    return jsonify({'exp': expired(jwt_data['exp'])})
Пример #2
0
def fetch_capital_games_recos(recos=[]):

	if 'cg' in db and 'cg-expire' in db and not expired(db['cg-expire']):
		return db['cg']

	db['cg'] = convert_cg_recos_to_json(recos)
	db['cg-expire'] = datetime.now() + timeout
	return db['cg']
Пример #3
0
async def fetch_crouching_rancor_recos(recos=[]):

	if 'cr' in db and 'cr-expire' in db and not expired(db['cr-expire']):
		return db['cr']

	url = 'http://apps.crouchingrancor.com/mods/advisor.json'

	response, error = await http_get(url)
	if error:
		raise Exception('http_get(%s) failed: %s' % (url, error))

	data = response.json()

	units = BaseUnit.objects.all().values('name', 'base_id')
	chars = { x['name']: { 'base_id': x['base_id'] } for x in units }

	for reco in data['data']:

		info = reco['name'].strip("'")
		name = reco['cname']

		real_name = name
		if real_name in REAL_NAMES:
			real_name = REAL_NAMES[name]

		if real_name not in chars:
			raise Exception('Missing name `%s` from DB' % real_name)

		base_id = chars[real_name]['base_id']

		info_name = name
		if info_name in INFO_NAMES:
			info_name = INFO_NAMES[info_name]

		if info.startswith(name):
			info = info.replace(name, '').strip()

		elif info.startswith(info_name):
			info = info.replace(info_name, '').strip()

		elif info.startswith(info_name.strip("'")):
			info = info.replace(info_name.strip("'"), '').strip()

		else:
			raise Exception('Info does not start with char name for %s / %s / %s / %s' % (real_name, name, info_name, info))

		if info and info[0] != 'z':
			info = info[0].upper() + info[1:]

		set1 = TRANSLATE_STATS[ reco['set1'] ]
		set2 = TRANSLATE_STATS[ reco['set2'] ]
		set3 = TRANSLATE_STATS[ reco['set3'] ]

		if set1 and set2 and set1 > set2:
			set1, set2 = set2, set1

		if set2 and set3 and set2 > set3:
			set2, set3 = set3, set2

		square_list   = split_stats(reco['square'])
		arrow_list    = split_stats(reco['arrow'])
		diamond_list  = split_stats(reco['diamond'])
		triangle_list = split_stats(reco['triangle'])
		circle_list   = split_stats(reco['circle'])
		cross_list    = split_stats(reco['cross'])

		for square in square_list:
			for arrow in arrow_list:
				for diamond in diamond_list:
					for triangle in triangle_list:
						for circle in circle_list:
							for cross in cross_list:

								recos.append({
									'source': 'Crouching Rancor',
									'base_id': base_id,
									'set1': set1,
									'set2': set2,
									'set3': set3,
									'square': square,
									'arrow': arrow,
									'diamond': diamond,
									'triangle': triangle,
									'circle': circle,
									'cross': cross,
									'info': info,
								})

	db['cr'] = recos
	db['cr-expire'] = datetime.now() + timeout
	return recos
Пример #4
0
async def fetch_swgohgg_meta_recos(recos=[], rank=1):

	if rank not in [ 1, 10, 100 ]:
		rank = 1

	key = 'gg-%d' % rank
	expire = 'gg-expire-%d'

	if key in db and expire in db and not expired(db[expire]):
		return db[key]

	units = BaseUnit.objects.all().values('name', 'base_id')
	char_list = { x['name']: { 'base_id': x['base_id'] } for x in units }
	url = 'https://swgoh.gg/mod-meta-report/rank_%d/' % rank
	response, error = await http_get(url)
	if error:
		raise Exception('http_get(%s) failed: %s' % (url, error))

	soup = BeautifulSoup(response.text, 'lxml')
	trs = soup.select('li tr')

	for tr in trs:

		tds = tr.find_all('td')
		if not tds:
			continue

		char_name = tds[0].text.strip()
		base_id = char_list[char_name]['base_id']
		modsets = parse_modsets(tds[1])
		prim_ar = tds[2].text.strip().split('/')
		prim_tr = tds[3].text.strip().split('/')
		prim_ci = tds[4].text.strip().split('/')
		prim_cr = tds[5].text.strip().split('/')

		set1 = modsets[0]
		set2 = modsets[1]
		set3 = modsets[2]

		if set1 and set2 and set1 > set2:
			set1, set2 = set2, set1

		if set2 and set3 and set2 > set3:
			set2, set3 = set3, set2

		for _ar in prim_ar:
			for _tr in prim_tr:
				for _ci in prim_ci:
					for _cr in prim_cr:
						recos.append({
							'source': 'swgoh.gg',
							'base_id': base_id,
							'set1': modsets[0],
							'set2': modsets[1],
							'set3': modsets[2],
							'square': 'Offense',
							'arrow': _ar.strip(),
							'diamond': 'Defense',
							'triangle': _tr.strip(),
							'circle': _ci.strip(),
							'cross': _cr.strip(),
							'info': 'Meta Report',
						})

	db[key] = recos
	db[expire] = datetime.now() + timeout
	return recos