Last active
March 16, 2019 23:06
-
-
Save arcan1s/ef91ac327072380cf1c9ecefee18723c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import datetime | |
import logging | |
import os | |
import requests | |
def extract_deathes(static, server, region, api_key, from_date = 0, to_date = None): | |
res = [] | |
end_date = int(to_date.timestamp() * 1000) if to_date else int(datetime.datetime.now().timestamp() * 1000) | |
parses = [ | |
parse | |
for parse in requests.get( | |
'https://www.fflogs.com/v1/reports/guild/' + os.path.join(static, server, region), | |
params={'api_key': api_key, 'start': int(from_date.timestamp() * 1000)}).json() | |
] | |
for parse in parses: | |
start_shift = parse['start'] | |
try: | |
fights = requests.get('https://www.fflogs.com/reports/fights-and-participants/' + os.path.join(parse['id'], '0')).json()['fights'] | |
except (ValueError, requests.exceptions.HTTPError): | |
logging.exception('could not get fights') | |
continue | |
for fight in fights: | |
try: | |
deaths = requests.get('https://www.fflogs.com/reports/deaths-menu/'+ os.path.join(parse['id'], str(fight['id']), str(fight['start_time']), str(fight['end_time']), '0', '0', '-1.0.-1', '0', 'Any')).json()['entries'] | |
except (ValueError, requests.exceptions.HTTPError): | |
logging.exception('could not get deaths') | |
continue | |
for death in deaths: | |
logging.info('found death for %s at %s' % (death['name'], death['timestamp'])) | |
res.append({ | |
'name': death['name'], | |
'timestamp': datetime.datetime.fromtimestamp((start_shift + death['timestamp']) / 1000), | |
'battle_time': '%i:%02i' % (death['timestamp'] / 1000 % 60, int(death['timestamp'] / 1000 / 60)) | |
}) | |
return res |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment