-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
57 lines (42 loc) · 1.41 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#%% Imports
import os, sys
# Internal modules
# from . import cardarbiter
from cardgenerator import CardGenerator
from anki_api import reportCollection
#### RUNTIME CONSTANTS AND OTHER SETTINGS stored in globals.py
ROOT_PATH = os.path.abspath(__file__)
os.chdir(os.path.dirname(ROOT_PATH)) # cd to directory of main.py file
XML_PAGE_PATH = R"data\page_xml.xml"
XML_OUTL_PATH = R"data\outline_xml.xml"
HTML_PREVIEW_PATH = R"data\displayCards_output.html"
DEV = 1
if len(sys.argv) > 1: # If arguments are passed via CMD:
# Command line arguments come in list, 0 = name of script, 1 = 1rst argument passed, 2 = 2nd argument passed
DEV = False # If CMD arguments, will turn Dev false
if "html" in sys.argv:
HTML = True
else:
HTML = False
if "add" in sys.argv:
ADD = True
else:
ADD = False
if "replace" in sys.argv:
REPLACE = True
else:
REPLACE = False
if DEV: # Dev mode for running directly from Python
HTML = True # Display HTML output
ADD = True # Actually add cards to Anki
REPLACE = True
#%%
if __name__ == "__main__":
crawler = CardGenerator(XML_PAGE_PATH, XML_OUTL_PATH)
crawler.genNotes()
if HTML:
crawler.displayCards(HTML_PREVIEW_PATH)
if ADD:
crawler.addCards(replace=REPLACE)
if DEV: # Report deck information after adding cards
reportCollection()