Skip to content

Instantly share code, notes, and snippets.

@RoyalScribblz
Created April 22, 2020 12:47
Show Gist options
  • Select an option

  • Save RoyalScribblz/47df811920a1b0cedb9f141ecbd15ae5 to your computer and use it in GitHub Desktop.

Select an option

Save RoyalScribblz/47df811920a1b0cedb9f141ecbd15ae5 to your computer and use it in GitHub Desktop.
Convert GuiShop shops.yml to Essentials worth.yml
import re
import csv
items = []
success = 0
with open("items.csv", "r") as itemscsv:
for line in itemscsv:
items.append(re.sub("\n", "", line))
worthyml = "worth:\n"
with open("shops.yml", "r") as shopsyml:
for line in shopsyml:
if line.startswith(" id:"):
item = re.sub("_", "", (" ".join(line.split(" id: ", 1)[1].split()).lower()))
elif line.startswith(" sell-price:"):
sellval = float(line.split(" sell-price: ", 1)[1])
if item in items:
worthyml += f" {item}: {sellval}\n"
success += 1
else:
print(f"{item} was unable to be added!")
worth = open("worth.yml", "w")
worth.write(worthyml)
worth.close()
print(f"\n{success} items added to worth.yml successfully!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment