-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
65 lines (43 loc) · 1.34 KB
/
main.py
File metadata and controls
65 lines (43 loc) · 1.34 KB
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
56
57
58
59
60
61
62
63
64
65
import sys, os, json, argparse
from docx import Document
from docx.shared import Inches
from interpreters import interHeader as iH
from interpreters import interBody as iB
from src.args import _args
from src.settings import _settings
from utils import debugtools as dbg
doc = Document()
#Get the selected pynote file
if ".txt" in (ifile := _args.input):
import txtdocx.main #transfer the control flow
elif ".pynote" in ifile:
pass
else:
exit("Error: Input file must have .pynote or .txt extension")
with open(_args.input, "r") as fin:
tokens = fin.readlines()
#Read Header
iH.init()
dbg.c_config() #DEBUGTOOLS
for ind, line in enumerate(tokens):
if iH.headerMode == False and iH.foundHeader == True: break
iH.checkForHeader(ind, line[:-1]) #removes the endl
dbg.c_settings() #DEBUGTOOLS
# Crop list so that i removes the header declarations
tokens = tokens[ind:]
#Check to make sure there's more than a header
if tokens[0] == '\end':
exit("Error: No body present")
#Interpret the body
iB.init(doc)
for ind, line in enumerate(tokens):
iB.parseLine(ind, line)
#SAVING AND WRITING THE DOCUMENT
dbg.c_void() #DEBUGTOOLS
if (ofile := _args.output) is None:
doc.save(f'./{ofile[:-6]}docx')
else:
if ".docx" in ofile:
doc.save(f'{ofile}')
else:
exit("Error: Output file must have .docx extension")