-
Notifications
You must be signed in to change notification settings - Fork 4
/
models.py
57 lines (45 loc) · 1.42 KB
/
models.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
53
54
55
56
57
#!/usr/bin/env python
from pyquery import PyQuery as pq
class Post:
def __init__(self):
self.title = ''
self.url = ''
self.date = ''
self.content = ''
self.imageurl = ''
self.extracss = ''
self.extrajs = ''
def spit_dict(self):
return {
'title':self.title,
'url':self.url,
'date':self.date,
'content':self.content,
'imageurl':self.imageurl,
'extracss':self.extracss,
'extrajs':self.extrajs
}
post_files = []
posts = []
with open('./blogxml/slugs.txt', 'r') as slugs_txt:
st = slugs_txt.read().split('\n')
for n in st:
post_files.append(n.split('|'))
for n in post_files:
with open('./blogxml/' + n[0], 'rb') as f:
d = pq(f.read())
g = Post()
g.url = n[1]
g.title = d.find('title').html()
g.date = n[2]
g.content = d.find('content').html()
g.imageurl = d.find('imageurl').html()
g.extracss = d.find('extracss').html()
g.extrajs = d.find('extrajs').html()
if g.extrajs == None:
g.extrajs = ''
if n[2] == '':
index = False
else:
index = True
posts.append({'data':g, 'index':index })