-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreader.py
More file actions
77 lines (67 loc) · 1.65 KB
/
reader.py
File metadata and controls
77 lines (67 loc) · 1.65 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
"""
Wilson's Config Reader
Built for www.wilsonmcda.de
Author: Wilson McDade / wilsonmcdade@github
"""
def reader(filename):
posts = []
file = open(filename)
for lines in file:
syntax = lines[:2]
if syntax == "%e":
file.close()
return posts
elif syntax == "%P":
posts.append(parser(lines,file,posts))
else:
pass
file.close()
return posts
def parser(lines,file,posts):
url = str
title = str
blurb = str
picsrc = str
github = None
text = []
post = {
'url' : url,
'github' : github,
'title' : title,
'blurb' : blurb,
'picsrc' : picsrc,
'text' : text
}
for line in file:
if len(line) > 2:
synt = line[:2]
rest = line[2:].strip()
else:
print("No attribute. Skipping line.")
print(line)
continue
syntax = {
"%u":"url",
"%T":"title",
"%b":"blurb",
"%s":"picsrc",
"%c":"code",
"%g":"github",
"%t":None,
"%P":None
}
if synt in syntax:
if synt == "%t":
text.append(rest)
elif synt == "%c":
text.append("</p><pre><code>"+rest+"</code></pre></p>")
elif synt == "%P":
posts.append(parser(lines,file,posts))
else:
cmd = syntax[synt]
post[cmd] = rest
else:
print("synt not in syntax")
print(synt,line,syntax)
pass
return post