Compare commits

...

9 Commits

14 changed files with 196 additions and 40 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()

View File

@ -1,3 +1,4 @@
cache/
cmd/database/config.json
config.development.json
config.production.json
sevenkeys.sql

View File

@ -5,3 +5,5 @@ 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

View File

@ -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.True,
Foil: logic.Either,
Promo: logic.Either,
Language: "en",
}

View File

@ -1,8 +0,0 @@
{
"User": "root",
"Passwd": "o7MS6CIn660jIApSP",
"Net": "tcp",
"Addr": "127.0.0.1:3306",
"DBName": "sevenkeys",
"AllowNativePasswords": true
}

View File

@ -0,0 +1,50 @@
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
}

View File

@ -2,6 +2,9 @@ package database
import "database/sql"
var StorageAreaTypeBinder string = "Binder"
var StorageAreaTypeBox string = "Box"
type StorageArea struct {
Id int
Name string
@ -46,3 +49,17 @@ 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
}

29
sevenkeys/logic/filter.go Normal file
View File

@ -0,0 +1,29 @@
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
}

View File

@ -34,10 +34,21 @@ 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,

View File

@ -4,7 +4,7 @@ import "testing"
func Test_GetBinderLocationDescription_ReturnsCorrectFormat_ForFrontSlots(t *testing.T) {
var position int = 24
var expected string = "on page 2 in front slot 6"
var expected string = " on page 2 in front slot 6"
description := GetBinderLocationDescription(position)
@ -15,7 +15,7 @@ func Test_GetBinderLocationDescription_ReturnsCorrectFormat_ForFrontSlots(t *tes
func Test_GetBinderLocationDescription_ReturnsCorrectFormat_ForBackSlots(t *testing.T) {
var position int = 17
var expected string = "on page 1 in back slot 8"
var expected string = " on page 1 in back slot 8"
description := GetBinderLocationDescription(position)

27
sevenkeys/logic/remove.go Normal file
View File

@ -0,0 +1,27 @@
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
}

View File

@ -29,32 +29,6 @@ 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)

View File

@ -1,13 +1,20 @@
package main
import (
"os"
"sevenkeys/cli"
"sevenkeys/database"
"sevenkeys/figlet"
)
func main() {
db := database.GetDatabaseFromConfig("config.json")
var profile string
if len(os.Args) < 2 {
profile = "production"
} else {
profile = os.Args[1]
}
db := database.GetDatabaseFromConfig("config." + profile + ".json")
figlet.ReadFigletFonts()
cli.ShowSplashScreen()