-
Notifications
You must be signed in to change notification settings - Fork 0
/
process.py
48 lines (32 loc) · 1.07 KB
/
process.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
"""
This is ugly becuase it was done quickly.
Requirments:
* BeautifulSoup: <http://www.crummy.com/software/BeautifulSoup/>
* python-slugify: <https://github.com/un33k/python-slugify>
TODO:
* Rewrite intrnal links to point to itself
* Filter out MediaWiki stuff
* Write to a Assemble like page syntax
"""
import os
import glob
from slugify import slugify
from bs4 import BeautifulSoup
def process_page(page):
with open(page, 'r') as f:
html_doc = f.read()
soup = BeautifulSoup(html_doc, 'html.parser')
body_content = soup.find(id='bodyContent')
file_name, file_ext = os.path.splitext(os.path.basename(page))
new_file_name = slugify(file_name) + file_ext
new_file_path = os.path.join('./legacy-pages-processed/', new_file_name)
with open(new_file_path, 'w') as f:
f.write(str(body_content))
def main():
wiki_pages = []
for wiki_page in glob.glob('./legacy-pages-raw/*.html'):
wiki_pages += [wiki_page,]
for page in wiki_pages:
process_page(page)
if __name__ == "__main__":
main()