-
Notifications
You must be signed in to change notification settings - Fork 0
/
resources.py
76 lines (63 loc) · 2.09 KB
/
resources.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import glob
import collections
import os
from post import Post
class Resources(object):
""" resource
"""
def __init__(self, post_path="./_post/"):
self.post_path = post_path
self.post_pattern = "*markdown"
self.post_mapping = {}
self.categories_mapping = collections.defaultdict(list)
self.notes = None
self.about = None
def load_post(self):
""" load post
"""
for post_source in glob.glob(self.post_path + self.post_pattern):
post = Post()
post.load_from_file(post_source)
# self.posts.append(post)
self.post_mapping[post.link] = post
def load_note(self):
""" load note
"""
self.notes = Post()
self.notes.load_from_file(self.post_path + "kip/my_mind_map.markdown")
def load_about(self):
""" load note
"""
self.about = Post()
self.about.load_from_file(self.post_path + "about/about.markdown")
def make_categories(self):
for post in self.post_mapping.values():
for category in post.categories:
self.categories_mapping[category].append(post)
def init(self):
self.load_post()
self.load_note()
self.load_about()
self.make_categories()
def get_note(self):
return self.notes
def get_about(self):
return self.about
def get(self, link):
# TODO add debug conf, this should open when writing new article
self.init()
return self.post_mapping.get(link)
def posts(self):
return sorted(self.post_mapping.values(), key=lambda x: x.date, reverse=True)
def categories(self):
return [(k, v) for k, v in self.categories_mapping.items()]
def static_dump(self):
pass
if __name__ == "__main__":
resource = Resources()
resource.init()
for link in resource.post_mapping:
post = resource.post_mapping[link]
for category in resource.categories_mapping:
print (category, resource.categories_mapping[category])
# print post.title, post.date, link