-
Notifications
You must be signed in to change notification settings - Fork 1
/
FFRKBattleDropParser.py
59 lines (47 loc) · 2.13 KB
/
FFRKBattleDropParser.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# FFRKBattleDropParser.py
# Author: Mark Cerqueira (www.mark.gg)
#
# Hosted at: https://github.com/markcerqueira/ff-record-keeper
# See sample JSON for parsing: https://github.com/markcerqueira/ff-record-keeper/blob/master/battle-data.json
#
# Save the JSON text response from the battle/get_battle_init_data API from FFRK
# and then run this program to print out a summary of items that will drop
#
# Usage: python FFRKItemDropParser.py JSON_FILE_NAME
#
# Example: python FFRKItemDropParser.py battle-data.json
# This example reads data from battle-data.json and ouputs drops that will occur
# at the end of each round (item type) and items that will drop when enemies are
# defeated (item_id)
#
# NOTE: Before sharing the output of this script with others, you should scrub out
# your user id using FFRKAnonymizer.py!
import sys
import json
from Utils import get_description_for_item_id
def get_drops_from_json(data):
# load data for all rounds
all_rounds_data = data['battle']['rounds']
result_string = ""
i = 1
for round_data in all_rounds_data:
# print the drop for the round (all enemies in round killed) if any
for round_item_drop in round_data['drop_item_list']:
result_string += "Round " + str(i) + " - round drop type = " + str(round_item_drop.get('type')) + "\n"
# print drops for each enemy
for enemy in round_data['enemy']:
for enemy_child in enemy['children']:
for enemy_child_drop in enemy_child['drop_item_list']:
if enemy_child_drop.get('item_id'):
result_string += "Round " + str(i) + " - enemy will drop " + get_description_for_item_id(enemy_child_drop.get('item_id')) + "\n"
elif enemy_child_drop.get('amount'):
result_string += "Round " + str(i) + " - enemy will drop GOLD amount = " + str(enemy_child_drop.get('amount')) + "\n"
i += 1
return result_string
def main():
with open(sys.argv[1]) as data_file:
# load the JSON file
data = json.load(data_file)
print get_drops_from_json(data)
if __name__ == "__main__":
main()