-
Notifications
You must be signed in to change notification settings - Fork 41
/
test.py
33 lines (25 loc) · 831 Bytes
/
test.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import re
path = "/Users/limbo/github/stackoverflow_python/part1"
create_path = "/Users/limbo/github/stackoverflow_python/data"
def create_file(path, name, content):
with open('{}/{}'.format(path, name), 'w') as F:
F.write(content)
files= os.listdir(path)
for name in files:
with open(path + "/" + name, "r") as F:
pre_content = ""
content = ""
flag = 0
for line in F.readlines():
if line.startswith('***'):
flag = 1
if flag:
content += line
else:
pre_content += line
pid = re.search(r"http://stackoverflow.com/questions/(\d+)/", pre_content).group(1)
name = pid + ".md"
create_file(create_path, name, content)