Add pricer.py script

This commit is contained in:
The Magician 2024-09-12 13:29:20 +01:00
parent 978b18a867
commit de8145e8b6
1 changed files with 46 additions and 0 deletions

46
pricer.py Executable file
View File

@ -0,0 +1,46 @@
#!/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()