Skip to content

Commit

Permalink
[AUTOMATE] : Added makefile automation
Browse files Browse the repository at this point in the history
  • Loading branch information
CooperGerman committed Oct 9, 2023
1 parent 5d4ad5d commit 3917369
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ cleaned
.vscode
__pycache__
tmp.csv
results
results
config/config.json
62 changes: 62 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# ██████╗ ██████╗ █████╗ ██████╗ ██████╗ ███╗ ██╗███████╗██╗ ██╗██╗███████╗██╗ ██████╗
# ██╔══██╗██╔══██╗██╔══██╗██╔════╝ ██╔═══██╗████╗ ██║██╔════╝██║ ██║██║██╔════╝██║ ██╔══██╗
# ██║ ██║██████╔╝███████║██║ ███╗██║ ██║██╔██╗ ██║███████╗███████║██║█████╗ ██║ ██║ ██║
# ██║ ██║██╔══██╗██╔══██║██║ ██║██║ ██║██║╚██╗██║╚════██║██╔══██║██║██╔══╝ ██║ ██║ ██║
# ██████╔╝██║ ██║██║ ██║╚██████╔╝╚██████╔╝██║ ╚████║███████║██║ ██║██║███████╗███████╗██████╔╝
# ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═══╝╚══════╝╚═╝ ╚═╝╚═╝╚══════╝╚══════╝╚═════╝

# ██╗ ██╗████████╗██╗██╗ ██╗████████╗██╗███████╗███████╗
# ██║ ██║╚══██╔══╝██║██║ ██║╚══██╔══╝██║██╔════╝██╔════╝
# ██║ ██║ ██║ ██║██║ ██║ ██║ ██║█████╗ ███████╗
# ██║ ██║ ██║ ██║██║ ██║ ██║ ██║██╔══╝ ╚════██║
# ╚██████╔╝ ██║ ██║███████╗██║ ██║ ██║███████╗███████║
# ╚═════╝ ╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝ ╚═╝╚══════╝╚══════╝

# This Makefile automate, exporteing the collection from DragonShield to Archidekt
.PHONY: all export_ds convert import

default: all

# create a function that uses a python oneliner to access a json field
fetch = python -c 'import json; print(json.load(open("$(1)"))["$(2)"])'

ATTEMPTS=3

DRAGON_USER = $(shell $(call fetch,./config/config.json,dragonshield_username))
DRAGON_PASSWD = $(shell $(call fetch,./config/config.json,dragonshield_password))

ARCH_PASSWD = $(shell $(call fetch,./config/config.json,archidekt_password))
ARCH_USER = $(shell $(call fetch,./config/config.json,archidekt_username))

DLFOLDER = $(shell $(call fetch,./config/config.json,dragonshield_download_folder))

all: clean export_ds convert import

export_ds:
@echo "Exporting DragonShield collection to CSVs"
python tools/dragonshield_scrapper.py \
-u=$(DRAGON_USER) \
-p=$(DRAGON_PASSWD) \
-a=$(ATTEMPTS)

convert: input
input:
mkdir -p input
cp $(DLFOLDER)/all-folder*.csv input/
@echo "Converting CSVs to Moxfield format"
python tools/DSConvert.py \
./input

import:
@echo "Importing CSVs to Archidekt"
python tools/archidekt_uploader.py \
./results/archidekt/ \
-u=$(ARCH_USER) \
-p=$(ARCH_PASSWD) \
-a=$(ATTEMPTS)

clean:
rm -rf $(DLFOLDER)/all-folder*.csv
rm -rf input
rm -rf results
rm -rf __pycache__
7 changes: 7 additions & 0 deletions config/config_template.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"dragonshield_username" : "",
"dragonshield_password" : "",
"archidekt_username" : "",
"archidekt_password" : "",
"download_folder" : ""
}
3 changes: 2 additions & 1 deletion tools/archidekt_uploader.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def run(args):

# click file import C:\Users\UBOE-yannicklp\Downloads\all-folders.csv
time.sleep(1)
file_path = os.path.join("C:\\", "Users", "UBOE-yannicklp", "Downloads", "all-folders_archidekt.csv")
file_path = os.path.join(args.input)
input = driver.find_element(by=By.CSS_SELECTOR, value=".style__StyledDropzone-sc-1ksfv9p-1 > input:nth-child(2)")
input.send_keys(file_path)

Expand All @@ -112,6 +112,7 @@ def run(args):

def main():
parser = argparse.ArgumentParser(description='Logs into the archidekt website to upload the csv files containing the entire collection of a user previously formatted with DSConvert.py.')
parser.add_argument('file', type=str, help='Input csv file', required=True)
parser.add_argument('-u', '--username', type=str, help='Username of the Dragonshield account', required=True)
parser.add_argument('-p', '--password', type=str, help='Password of the Dragonshield account', required=True)
parser.add_argument('-a', '--attempts', type=int, help='Number of attempts', required=False, default=3)
Expand Down

0 comments on commit 3917369

Please sign in to comment.