Support Classic wow token
This commit is contained in:
parent
90530904cc
commit
5032d2b974
@ -73,6 +73,8 @@ tables = {
|
|||||||
'timestream': 'wow-token-classic-price-history'
|
'timestream': 'wow-token-classic-price-history'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def historical_data(time, region, version):
|
def historical_data(time, region, version):
|
||||||
# This shim is to permanently change the URL of 30d to 720h for local caching,
|
# This shim is to permanently change the URL of 30d to 720h for local caching,
|
||||||
# There seems to be at least 1 person using 30d (strangely with no .json) which was deprecated
|
# There seems to be at least 1 person using 30d (strangely with no .json) which was deprecated
|
||||||
@ -155,13 +157,17 @@ def dynamo_data(time, region, version):
|
|||||||
Key('region').eq(region) &
|
Key('region').eq(region) &
|
||||||
Key('timestamp').gte(int(start_time_utc.timestamp()))))
|
Key('timestamp').gte(int(start_time_utc.timestamp()))))
|
||||||
data = []
|
data = []
|
||||||
|
last_price = 0
|
||||||
for item in response['Items']:
|
for item in response['Items']:
|
||||||
|
price = int(int(item['price']) / 10000)
|
||||||
|
if last_price != price:
|
||||||
item_time = datetime.datetime.utcfromtimestamp(int(item['timestamp'])).replace(
|
item_time = datetime.datetime.utcfromtimestamp(int(item['timestamp'])).replace(
|
||||||
tzinfo=datetime.timezone.utc).isoformat()
|
tzinfo=datetime.timezone.utc).isoformat()
|
||||||
data.append({
|
data.append({
|
||||||
'time': item_time,
|
'time': item_time,
|
||||||
'value': int(int(item['price']) / 10000)
|
'value': price
|
||||||
})
|
})
|
||||||
|
last_price = price
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
@ -319,7 +325,13 @@ def validate_path(split_uri: list) -> bool:
|
|||||||
if not split_uri[-1].endswith('json'):
|
if not split_uri[-1].endswith('json'):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
return validate_region(split_uri[-2]) and validate_time(split_uri[-1].split('.')[0])
|
if not validate_region(split_uri[-2]):
|
||||||
|
return False
|
||||||
|
|
||||||
|
if not validate_time(split_uri[-1].split('.')[0]):
|
||||||
|
return False
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
def validate_time(time: str) -> bool:
|
def validate_time(time: str) -> bool:
|
||||||
|
@ -34,14 +34,18 @@ def lambda_handler(event, context):
|
|||||||
|
|
||||||
|
|
||||||
def flavor_handler(flavor: str, regions: list, timestamp: int) -> None:
|
def flavor_handler(flavor: str, regions: list, timestamp: int) -> None:
|
||||||
live_prices = get_combined_live_price(flavor)
|
|
||||||
print(f"Current {flavor} prices:\t{live_prices}")
|
|
||||||
for region in regions:
|
for region in regions:
|
||||||
|
if flavor == 'retail':
|
||||||
|
namespace = 'dynamic'
|
||||||
|
else:
|
||||||
|
namespace = 'dynamic-classic'
|
||||||
|
live_price = get_token_price_from_blizzard(region, namespace)
|
||||||
|
print(f"{flavor} {region} live price {live_price}")
|
||||||
print(f'Updating {region.upper()}...')
|
print(f'Updating {region.upper()}...')
|
||||||
update_token_price(flavor, region, timestamp, live_prices[region])
|
update_token_price(flavor, region, timestamp, live_price)
|
||||||
|
|
||||||
|
|
||||||
def update_token_price(flavor: str, region: str, current_time_epoch: int, live_price: int):
|
def update_token_price(flavor: str, region: str, current_time_epoch: int, live_price: int) -> None:
|
||||||
stored_price = get_stored_price(flavor, region)
|
stored_price = get_stored_price(flavor, region)
|
||||||
regional_item = get_regional_update_item(flavor, region)
|
regional_item = get_regional_update_item(flavor, region)
|
||||||
print(f'Current live price {live_price}')
|
print(f'Current live price {live_price}')
|
||||||
@ -113,7 +117,7 @@ def update_regional_price(flavor: str, region: str, price: int, current_time_epo
|
|||||||
print(f'Updated regional {flavor} {region.upper()} price to {price}')
|
print(f'Updated regional {flavor} {region.upper()} price to {price}')
|
||||||
|
|
||||||
|
|
||||||
def create_regional_item(flavor: str, region: str):
|
def create_regional_item(flavor: str, region: str) -> None:
|
||||||
print(f"Creating default regional item in {flavor} {region}")
|
print(f"Creating default regional item in {flavor} {region}")
|
||||||
if flavor == 'retail':
|
if flavor == 'retail':
|
||||||
key = region
|
key = region
|
||||||
@ -242,15 +246,16 @@ def get_combined_live_price(game_flavor: str) -> dict:
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def get_token_price_from_blizzard(region: str, namespace: str):
|
def get_token_price_from_blizzard(region: str, namespace: str) -> int:
|
||||||
api_endpoint = f'https://{region}.api.blizzard.com/data/wow/token/index'
|
api_endpoint = f'https://{region}.api.blizzard.com/data/wow/token/index'
|
||||||
params = {'namespace': f'{namespace}-{region}'}
|
params = {'namespace': f'{namespace}-{region}'}
|
||||||
headers = {'Authorization': f'Bearer {get_oauth_token()}'}
|
headers = {'Authorization': f'Bearer {get_oauth_token()}'}
|
||||||
response = requests.get(api_endpoint, params=params, headers=headers)
|
response = requests.get(api_endpoint, params=params, headers=headers)
|
||||||
|
response.raise_for_status()
|
||||||
return int(response.json()['price'])
|
return int(response.json()['price'])
|
||||||
|
|
||||||
|
|
||||||
def get_oauth_token():
|
def get_oauth_token() -> str:
|
||||||
url = 'https://us.battle.net/oauth/token'
|
url = 'https://us.battle.net/oauth/token'
|
||||||
payload = {
|
payload = {
|
||||||
'grant_type': 'client_credentials',
|
'grant_type': 'client_credentials',
|
||||||
@ -258,6 +263,7 @@ def get_oauth_token():
|
|||||||
'client_secret': os.environ.get('BLIZZARD_CLIENT_SECRET')
|
'client_secret': os.environ.get('BLIZZARD_CLIENT_SECRET')
|
||||||
}
|
}
|
||||||
response = requests.post(url, data=payload)
|
response = requests.post(url, data=payload)
|
||||||
|
response.raise_for_status()
|
||||||
return json.loads(response.text)['access_token']
|
return json.loads(response.text)['access_token']
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user