Compare commits
9 Commits
4f14040747
...
1e967674b6
Author | SHA1 | Date |
---|---|---|
The Magician | 1e967674b6 | |
The Magician | 52d9e9184f | |
The Magician | 34da4ae77b | |
The Magician | 178f92e63a | |
The Magician | c68acb53c8 | |
The Magician | 10b3e1e46f | |
The Magician | a18c9b2101 | |
The Magician | de8145e8b6 | |
The Magician | 978b18a867 |
|
@ -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()
|
|
@ -1,3 +1,4 @@
|
|||
cache/
|
||||
cmd/database/config.json
|
||||
config.development.json
|
||||
config.production.json
|
||||
sevenkeys.sql
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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",
|
||||
}
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
{
|
||||
"User": "root",
|
||||
"Passwd": "o7MS6CIn660jIApSP",
|
||||
"Net": "tcp",
|
||||
"Addr": "127.0.0.1:3306",
|
||||
"DBName": "sevenkeys",
|
||||
"AllowNativePasswords": true
|
||||
}
|
|
@ -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
|
||||
}
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
}
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue