Last active
September 1, 2021 23:59
-
-
Save EricSeastrand/ccca3f50ae139dab96042aef07d688fc to your computer and use it in GitHub Desktop.
Converts the TradeSkillMaster data that the addon downloads into a CSV file you can upload into a Google Sheet.
This file contains hidden or 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 re # Regex ... sadly... | |
import os | |
# Update your WoW path here.. | |
tsm_file = "E:/World of Warcraft/_retail_/Interface/AddOns/TradeSkillMaster_AppHelper/AppData.lua" | |
desktop_path = os.path.expandvars('%USERPROFILE%/Desktop/') | |
csv_destination = desktop_path + '/tsm_data.csv' | |
print(csv_destination) | |
realms = [ | |
'Alterac Mountains', | |
'Undermine' | |
# ... Other connected realms? | |
] | |
def find_between(s, start, end): | |
return (s.split(start))[1].split(end)[0] | |
def get_realm_data(): | |
file = open(tsm_file, "r") | |
for line in file: | |
# Find the line that has our realm-specific data | |
if ('AUCTIONDB_MARKET_DATA' in line) and any(realm in line for realm in realms): | |
return line | |
raise Exception("Scrape failed: Could not find data for the realm we care about.") | |
def extract_data(): | |
data_string = get_realm_data() | |
# Isolate the actual data ... trim off comments and such | |
data_string = find_between(data_string, ",fields=", ']]) --<AUCTIONDB_MARKET_DATA') | |
pattern = re.compile(r'\{([^\}\{]+)}') # Data lines are surrounded by curly-braces | |
lines = pattern.findall(data_string) | |
return lines | |
def save_data(lines): | |
print("Writing "+str(len(lines))+" of AH data to "+csv_destination) | |
destination = open(csv_destination, "w") | |
for line in lines: | |
destination.write(line + "\n") | |
destination.close() | |
print("Write Finished. Now go upload this file to the Google Sheet.") | |
our_data = extract_data() | |
save_data(our_data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment