def extract_post(self, data, post_type): post = Post() if data['publish_date'] is None: publish_date_date = calendar.timegm(time.gmtime()) * 1000 else: publish_date_date = data['publish_date']['$date'] date_str = datetime.datetime.fromtimestamp( publish_date_date / 1000).strftime('%Y-%m-%d %H:%M:%S') post.post_id = compute_post_guid(data['url'], data['source'], date_str) post.guid = post.post_id post.author_guid = compute_author_guid_by_author_name(data['source']) post.author = str(data['source']) post.date = convert_str_to_unicode_datetime(date_str) post.title = str(data['title']) post.url = str(data['url']) post.source_url = str(data['source']) post.content = str(data['text']) post.tags = ','.join(data['keywords']) post.domain = self._domain post.post_type = post_type if 'description' not in data['meta_data']: post.description = "" else: post.description = str(data['meta_data']['description']) return post
def _add_post(self, post_id, content, url, _domain=u'Microblog'): post = Post() post.author = u'test_user' post.author_guid = u'test_user' post.content = content post.title = post_id post.domain = _domain post.post_id = post_id post.guid = post_id post.url = url post.source_url = url self._db.addPost(post) self._posts[post_id] = post