-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweekly_loot_input.py
154 lines (126 loc) · 6.22 KB
/
weekly_loot_input.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# If authentication error ocurs, delete the file located in:
# ~/.config/gspread_pandas/creds
import sys
import datetime
from functions import *
# Get user input to determine if in testing or production mode
is_test = True
mode = "BT"
# Set flags to determine sections that run
pull = {
'Druid': True,
'Hunter': True,
'Mage': True,
'Paladin': True,
'Priest': True,
'Rogue': True,
'Shaman': True,
'Warlock': True,
'Warrior': True
}
push = {
'Druid': True,
'Hunter': True,
'Mage': True,
'Paladin': True,
'Priest': True,
'Rogue': True,
'Shaman': True,
'Warlock': True,
'Warrior': True
}
if mode == 'BT':
folder = 'BT'
sleep_time = 60
bad_items = r'^Pattern:|Design:|Plans:'
if is_test:
spread = '1689SHfCWtyC_UK8wt261ITTOZCblqwNVHoop85Sgdug'
else:
spread = '1NqPhGFaCLmiAN71_80vSidM9ar22QMs1QS5-mBBL5Jc'
elif mode == 'T5':
folder = 'T5'
sleep_time = 90
# List of items not tracked by Loot List
bad_items = ['Staff of Disintegration', 'Warp Slicer', 'Cosmic Infuser',
'Phaseshift Bulwark', 'Devastation', 'Infinity Blade',
'Netherstrand Longbow', 'Nether Spike', 'Staff of Disintegration',
'Pit Lord\'s Satchel', 'Pattern: Belt of Deep Shadow',
'Pattern: Belt of the Black Eagle', 'Nether Vortex',
'Pattern: Boots of the Crimson Hawk']
if is_test:
spread = '1P8GQ7gf2hfSnH_C8Y2M_jf2AxjHvJG4Xxx5Si_liJQk'
else:
spread = '1QjBqgl7HWWhQv4p3thFiZOfmZaTK3FasPHoE7THBxPc'
# Import personal email from environment vars
email = os.environ.get('pers_email')
# List of items not tracked by Loot List
# bad_items = ['Staff of Disintegration', 'Warp Slicer', 'Cosmic Infuser',
# 'Phaseshift Bulwark', 'Devastation', 'Infinity Blade',
# 'Netherstrand Longbow', 'Nether Spike', 'Staff of Disintegration',
# 'Pit Lord\'s Satchel', 'Pattern: Belt of Deep Shadow',
# 'Pattern: Belt of the Black Eagle', 'Nether Vortex',
# 'Pattern: Boots of the Crimson Hawk', 'Pattern: Swiftheal Mantle',
# 'Pattern: Living Earth Bindings', 'Pattern: Shoulders of Lightning Reflexes',
# 'Pattern: Shoulderpads of Renewed Life', 'Plans: Swiftsteel Bracers',
# 'Pattern: Living Earth Shoulders', 'Plans: Dawnsteel Bracers',
# 'Plans: Swiftsteel Shoulders', 'Pattern: Mantle of Nimble Thought',
# 'Plans: Dawnsteel Shoulders', 'Pattern: Bracers of Renewed Life']
# Collect and organize loot data from previous raid
raid_date, raid_date_str = get_raid_date()
loot_file = get_loot_file(raid_date_str, folder = folder)
extracted_loot = extract_loot_info(loot_file)
cleaned_loot = clean_loot_df(extracted_loot, bad_items, mode)
# Set up gspread_pandas
client, spread = gspread_pandas_setup(user=email, spread=spread)
# Only pull sheets if flag is set to True
if any(pull):
# Import and filter sheets from Google
data = import_sheet(sheet='Data', index=None, header_rows=1, start_row=2, spread=spread).iloc[:,15:22]
data = data.loc[data['Rank'] != 'Inactive'][['Player', 'Item', 'NumPassed', 'Equity']]
data[['NumPassed', 'Equity']] = data[['NumPassed', 'Equity']].apply(pd.to_numeric)
roster = import_sheet(sheet='Roster', index=None, header_rows=1, start_row=1, spread=spread).iloc[:,6:10]
# Generate merged dfs
merged_data = data.merge(roster, how='left', left_on='Player', right_on='Name')[['Player', 'Class', 'Item', 'NumPassed', 'Equity']]
loot_received = cleaned_loot.merge(roster, how='left', left_on='player', right_on='Name')[['item', 'player', 'Class']]
# Convert item and player columns to lists and use list comprehension to generate list of players who passed on items
items = list(cleaned_loot['item'])
players = list(cleaned_loot['player'])
pass_players = [passers(item, player, merged_data) for item, player in zip(items, players)]
# Add pass players to loot_received | reorder/rename/combine columns
loot_received['pass_player'] = pass_players
loot_received.columns = ['item', 'player_received', 'received_class', 'players_passed']
loot_received['player_received'] = list(zip(loot_received['player_received'], loot_received['received_class']))
loot_received = loot_received[['item', 'player_received', 'players_passed']]
# Separate items with vs without passes
no_passes = loot_received.loc[loot_received['players_passed'].isna()].reset_index(drop=True)[['item', 'player_received']]
passes = loot_received.loc[~loot_received['players_passed'].isna()].reset_index(drop=True)
# Only pull class dicts if flag set to True
class_dfs = {'Druid': None, 'Hunter': None, 'Mage': None, 'Paladin': None, 'Priest': None, 'Rogue': None, 'Shaman': None, 'Warlock': None, 'Warrior': None}
for key in class_dfs.keys():
if pull[key]:
# Iterate over classes and run function to pull and store class sheets in dict
class_dfs[key] = pull_class_sheets_from_google(key, spread)
# Create a copy of dict and list of items/players passed
items = list(passes['item'])
pass_player_class = list(passes['players_passed'])
# Concatenate the item and player received columns from the passes df to the bottom of the no_passes df
loot_entry = pd.concat([no_passes, passes[['item', 'player_received']]], axis=0, ignore_index=True, join='outer')
# Apply proper formatting to loot_date
loot_date_format = raid_date.strftime('%-m/%-d/%y')
# Enter loot for all items and players
for item, entry in zip(loot_entry['item'], loot_entry['player_received']):
class_dfs = enter_loot(class_dfs, item, entry, loot_date_format)
# Enter passes for all items and players
for item, player in zip(items, pass_player_class):
class_dfs = enter_passes(class_dfs, item, player)
# Loop through class dfs and upload them to Google Sheet
for key in class_dfs.keys():
# Only push sheet to google if flag is set to True
if push[key]:
push_class_sheets_to_google(class_dfs, key, spread)
# Determine if any other sheets should be pushed
curr_index = list(push.keys()).index(key)
if any(list(push.values())[curr_index + 1:]):
next_iter = datetime.datetime.fromtimestamp(time.time() + sleep_time).strftime('%-I:%M:%S %p')
print(f'Next iteration begins at {next_iter}.')
time.sleep(sleep_time)