-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild-json.py
More file actions
35 lines (27 loc) · 787 Bytes
/
build-json.py
File metadata and controls
35 lines (27 loc) · 787 Bytes
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 requests
import bs4
import sys
import json
vimtips_url = 'http://zzapper.co.uk/vimtips.html'
response = requests.get(vimtips_url)
soup = bs4.BeautifulSoup(response.text, 'lxml')
if type(soup.pre) != bs4.element.Tag:
print "Can't find pre Tag!"
sys.exit()
# pre_tags = soup.select('pre')
# text = pre_tags[0].get_text()
text = soup.pre.get_text()
raw_lines = text.split('\n')
lines = []
for i, line in enumerate(raw_lines):
items = line.split(' : ')
if '----------' in line:
lines.append({'line': '.' * 100})
lines.append({'line': '.' * 100})
else:
lines.append({'line': line})
#json_str = json.dumps(lines, indent=4, separators=(',', ': '))
json_str = json.dumps(lines)
f = open('vimtips.json', 'w')
f.write(json_str)
f.close()