Compare commits
No commits in common. "1e967674b68e34fa06cd1b2fe924f4db9076c152" and "4f14040747f3833e0129b5705b971802e1562e72" have entirely different histories.
1e967674b6
...
4f14040747
46
pricer.py
46
pricer.py
|
@ -1,46 +0,0 @@
|
|||
#!/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()
|
|
@ -1,4 +1,3 @@
|
|||
cache/
|
||||
config.development.json
|
||||
config.production.json
|
||||
cmd/database/config.json
|
||||
sevenkeys.sql
|
||||
|
|
|
@ -5,5 +5,3 @@ removedb:
|
|||
mysql --user=root --password=$(shell pass show sevenkeys/mysql) <database/sql/removedb.sql
|
||||
connect:
|
||||
mysql --user=root --password=$(shell pass show sevenkeys/mysql)
|
||||
dump:
|
||||
mysqldump --user=root --password=$(shell pass show sevenkeys/mysql) sevenkeys >sevenkeys.sql
|
||||
|
|
|
@ -29,7 +29,7 @@ func MainCliLoop(db *sql.DB) {
|
|||
// TODO: Make these do something and add the ability to modify them
|
||||
var locateSearchCriteria logic.SearchCriteria = logic.SearchCriteria{
|
||||
SetCode: "",
|
||||
Foil: logic.Either,
|
||||
Foil: logic.True,
|
||||
Promo: logic.Either,
|
||||
Language: "en",
|
||||
}
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"User": "root",
|
||||
"Passwd": "o7MS6CIn660jIApSP",
|
||||
"Net": "tcp",
|
||||
"Addr": "127.0.0.1:3306",
|
||||
"DBName": "sevenkeys",
|
||||
"AllowNativePasswords": true
|
||||
}
|
|
@ -1,50 +0,0 @@
|
|||
package database
|
||||
|
||||
import "database/sql"
|
||||
|
||||
func RemoveFromBinder(db *sql.DB, location CardLocation) error {
|
||||
query := `UPDATE CardStorageLocation SET CardPrintingId = NULL WHERE Id = ?;`
|
||||
|
||||
update, err := db.Prepare(query)
|
||||
defer update.Close()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = update.Exec(location.Id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func RemoveFromBox(db *sql.DB, location CardLocation) error {
|
||||
deleteQuery := `DELETE FROM CardStorageLocation WHERE Id = ?;`
|
||||
|
||||
del, err := db.Prepare(deleteQuery)
|
||||
defer del.Close()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = del.Exec(location.Id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
updateQuery := `UPDATE CardStorageLocation SET Position = Position - 1 WHERE Position > 5;`
|
||||
|
||||
update, err := db.Prepare(updateQuery)
|
||||
defer update.Close()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = update.Exec(location.Id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
|
@ -2,9 +2,6 @@ package database
|
|||
|
||||
import "database/sql"
|
||||
|
||||
var StorageAreaTypeBinder string = "Binder"
|
||||
var StorageAreaTypeBox string = "Box"
|
||||
|
||||
type StorageArea struct {
|
||||
Id int
|
||||
Name string
|
||||
|
@ -49,17 +46,3 @@ func InsertStorageArea(db *sql.DB, storageArea StorageArea) error {
|
|||
|
||||
return nil
|
||||
}
|
||||
|
||||
func GetStorageAreaTypeById(db *sql.DB, storageAreaId int) (string, error) {
|
||||
var storageType string
|
||||
|
||||
query := `SELECT StorageType FROM StorageArea WHERE Id = ?;`
|
||||
row := db.QueryRow(query, storageAreaId)
|
||||
|
||||
err := row.Scan(&storageType)
|
||||
if err != nil {
|
||||
return storageType, err
|
||||
}
|
||||
|
||||
return storageType, nil
|
||||
}
|
||||
|
|
|
@ -1,29 +0,0 @@
|
|||
package logic
|
||||
|
||||
import "sevenkeys/database"
|
||||
|
||||
func filterPrinting(printing database.CardPrinting, searchCriteria SearchCriteria) bool {
|
||||
if searchCriteria.SetCode != "" && printing.SetCode != searchCriteria.SetCode {
|
||||
return true
|
||||
}
|
||||
|
||||
if searchCriteria.Foil == False && printing.IsFoil {
|
||||
return true
|
||||
}
|
||||
if searchCriteria.Foil == True && !printing.IsFoil {
|
||||
return true
|
||||
}
|
||||
|
||||
if searchCriteria.Promo == False && printing.IsPromo {
|
||||
return true
|
||||
}
|
||||
if searchCriteria.Promo == True && !printing.IsPromo {
|
||||
return true
|
||||
}
|
||||
|
||||
if searchCriteria.Language != "" && printing.Language != searchCriteria.Language {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
|
@ -34,21 +34,10 @@ func LocateCards(db *sql.DB, cardNames []string, criteria SearchCriteria) ([]str
|
|||
if err != nil {
|
||||
return locations, err
|
||||
}
|
||||
// TODO: Filter by search criteria
|
||||
|
||||
var location string
|
||||
for _, result := range results {
|
||||
printing := database.CardPrinting{
|
||||
SetCode: result.SetCode,
|
||||
IsFoil: result.IsFoil,
|
||||
IsPromo: result.IsPromo,
|
||||
Language: result.Language,
|
||||
}
|
||||
|
||||
filter := filterPrinting(printing, criteria)
|
||||
if filter {
|
||||
continue
|
||||
}
|
||||
|
||||
location = fmt.Sprintf("%s (%s %s) [%s]",
|
||||
result.CardName,
|
||||
result.SetCode,
|
||||
|
|
|
@ -1,27 +0,0 @@
|
|||
package logic
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"errors"
|
||||
|
||||
"sevenkeys/database"
|
||||
)
|
||||
|
||||
var UnrecognizedStorageAreaTypeError error = errors.New("Unrecognized storage area type.")
|
||||
|
||||
func RemoveFromStorage(db *sql.DB, location database.CardLocation) error {
|
||||
locationType, err := database.GetStorageAreaTypeById(db, location.Id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if locationType == database.StorageAreaTypeBinder {
|
||||
database.RemoveFromBinder(db, location)
|
||||
} else if locationType == database.StorageAreaTypeBox {
|
||||
database.RemoveFromBox(db, location)
|
||||
} else {
|
||||
return UnrecognizedStorageAreaTypeError
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
|
@ -29,6 +29,32 @@ type SearchCriteria struct {
|
|||
// fzf) to `string` values (which represent a primary key in the CardPrintings table)
|
||||
type InsertSearchOptions map[string]string
|
||||
|
||||
func filterPrinting(printing database.CardPrinting, searchCriteria SearchCriteria) bool {
|
||||
if searchCriteria.SetCode != "" && printing.SetCode != searchCriteria.SetCode {
|
||||
return true
|
||||
}
|
||||
|
||||
if searchCriteria.Foil == False && printing.IsFoil {
|
||||
return true
|
||||
}
|
||||
if searchCriteria.Foil == True && !printing.IsFoil {
|
||||
return true
|
||||
}
|
||||
|
||||
if searchCriteria.Promo == False && printing.IsPromo {
|
||||
return true
|
||||
}
|
||||
if searchCriteria.Promo == True && !printing.IsPromo {
|
||||
return true
|
||||
}
|
||||
|
||||
if searchCriteria.Language != "" && printing.Language != searchCriteria.Language {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func GetAllSearchOptions(db *sql.DB, searchCriteria SearchCriteria) (InsertSearchOptions, error) {
|
||||
var searchOptions InsertSearchOptions = make(map[string]string)
|
||||
|
||||
|
|
|
@ -1,20 +1,13 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"sevenkeys/cli"
|
||||
"sevenkeys/database"
|
||||
"sevenkeys/figlet"
|
||||
)
|
||||
|
||||
func main() {
|
||||
var profile string
|
||||
if len(os.Args) < 2 {
|
||||
profile = "production"
|
||||
} else {
|
||||
profile = os.Args[1]
|
||||
}
|
||||
db := database.GetDatabaseFromConfig("config." + profile + ".json")
|
||||
db := database.GetDatabaseFromConfig("config.json")
|
||||
|
||||
figlet.ReadFigletFonts()
|
||||
cli.ShowSplashScreen()
|
||||
|
|
Loading…
Reference in New Issue