-
Notifications
You must be signed in to change notification settings - Fork 0
/
test3.py
52 lines (40 loc) · 1.54 KB
/
test3.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
import json
import os
import os
import aspose.words as aw
#create 5 differnt folders
#Split all files equally into the 5 folders with unqiue documents
#We need 1 excel sheet with the title of the document and the valid until date (end date)
#The title should be catagory, subject, and date
#Each excel sheet should have a field assignee that is the name of the person who is assigned to that document
mainpath = '/Users/rileyvenable/Documents/Development Projects/Peridot_Bank_Migration/000 copy/test3'
#create a basic function
def createWordDoc(path):
for filename in os.listdir(path):
filepath = path + '/' + filename
# Create the jsonpath
jsonpath = filepath[:-3] + '.json'
# Open the file
with open(filepath, 'r') as f:
filedata = f.read()
filedata = filedata[29:]
filedata = filedata[:-1]
with open(jsonpath, 'w') as k:
k.write(filedata)
k.close()
f.close()
with open(jsonpath, 'r') as j:
data = json.load(j)
p = data['p']
p = p.replace('\\', '')
p = '<html>' + p + '</html>'
#save to a html file
with open(filepath[:-3] + '.html', 'w') as h:
h.write(p)
htmlpath = filepath[:-3] + '.html'
doc = aw.Document(htmlpath)
doc.save(filepath[:-3] + '.docx')
h.close()
j.close()
os.remove(filepath)
createWordDoc(mainpath)