TheMathemagicians/pricer.py

47 lines
1.1 KiB
Python
Raw Normal View History

2024-09-12 12:29:20 +00:00
#!/usr/bin/python3
import pandas as pd
import csv
csv.register_dialect('ManaBox', delimiter=",", quoting=csv.QUOTE_ALL, doublequote=True)
def calculate_buy_price(filename):
df = pd.read_csv(filename, dialect="ManaBox")
total = 0
for index, row in df.iterrows():
sellPrice = row["Purchase price"]
if sellPrice >= 1.00:
buyPrice = sellPrice * 0.7
elif sellPrice >= 0.50:
buyPrice = sellPrice * 0.5
elif sellPrice >= 0.10:
buyPrice = 0.05
elif sellPrice >= 0.05:
buyPrice = 0
total += buyPrice
return total
def output_price_list(filename):
df = pd.read_csv(filename, dialect="ManaBox")
for index, row in df.iterrows():
print(row["Name"] + ": £" + str(row["Purchase price"]))
def main():
filename = input("Filename: ")
mode = input("Mode: ")
if mode == "buy":
total = calculate_buy_price(filename)
elif mode == "sell":
output_price_list(filename)
else:
print("Unknown option: " + mode)
if __name__ == "__main__":
main()