-
Notifications
You must be signed in to change notification settings - Fork 0
/
convert.py
35 lines (30 loc) · 1.26 KB
/
convert.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
import weasyprint
import os
def main():
# iterate over all files in the directory
for root, dirs, files in os.walk('.'):
for file in files:
if file.endswith('.htm'):
# convert the file to pdf
html = weasyprint.HTML(root + '/' + file)
html.write_pdf(root + '/' + file.replace('.htm', '.pdf'))
print(f'{file} converted to pdf')
# remove the html file
os.system(f'rm {root}/{file}')
elif file.endswith('.html'):
# convert the file to pdf
html = weasyprint.HTML(root + '/' + file)
html.write_pdf(root + '/' + file.replace('.html', '.pdf'))
print(f'{file} converted to pdf')
# remove the html file
os.system(f'rm {root}/{file}')
remove()
def remove():
# iterate over all files in the directory
for root, dirs, files in os.walk('.'):
for file in files:
if "html" in file or file.endswith('.jpg') or file.endswith('.png') or file.endswith('.jpeg') or file.endswith('.gif') or file.endswith('.GIF'):
# remove the html file
os.system(f'rm "{root}/{file}"')
if __name__ == '__main__':
main()