-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpost_list.py
More file actions
42 lines (37 loc) · 1.2 KB
/
Copy pathpost_list.py
File metadata and controls
42 lines (37 loc) · 1.2 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
import json
from post import Post
from datetime import datetime
from dateutil import parser
class PostList:
def __init__(self, posts):
self.posts = posts
def serialize(self):
return {
'posts' : self.get_json_posts(),
}
def get_json_posts(self):
post_lists = []
for post in self.posts:
post_lists.append(post.serialize())
return post_lists
def initialize_me(self):
post_list = PostList([])
with open('posts.json', 'r') as f:
data = json.load(f)
post_list = PostList(
posts = self.get_posts_from_json(data),
)
return post_list
def get_posts_from_json(self, data):
return_list = []
for post in data['posts']:
return_list.append(
Post(
description = post['description'],
image = post['image'],
post_date = parser.parse(post['post_date']),
has_been_posted = post['has_been_posted']
)
)
self.posts = return_list
return return_list