Skip to content

Instantly share code, notes, and snippets.

@RoyalScribblz
Last active April 16, 2020 17:29
Show Gist options
  • Select an option

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

Select an option

Save RoyalScribblz/ee5361837bb351bc6d02e7721341d515 to your computer and use it in GitHub Desktop.
#Content is from a csv file which is in the format ID,buy-price,sell-price for items and just the name for a category
import csv
counter = 0
completed = ""
categories = 0
items = 0
filename = input("Enter .csv filename: ") + ".csv"
with open(filename) as csvfile:
creader = csv.reader(csvfile)
for row in creader:
if len(row) == 1:
completed += f"{row[0].capitalize()}:\n"
categories += 1
counter = 0
else:
mcid = row[0].upper()
completed += (f" '{counter}':\n type: SHOP\n id: {mcid}\n buy-price: {float(row[1])}\n sell-price: {float(row[2])}\n")
counter += 1
items += 1
output = open("shops.yml", "w")
output.write(completed)
output.close()
print(f"[Done] {categories} categories created and {items} items added!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment