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 _convert_row_to_post(self, row): post = Post() claim_id = unicode(row['claim_id']) title = unicode(row['title'], errors='replace') post.content = title description = unicode(row['description'], errors='replace') post.description = description url = unicode(row['url']) post.url = url publication_date = row['publication_date'] post.date = date(publication_date) post_guid = compute_post_guid(self._social_network_url, claim_id, publication_date) post.guid = post_guid post.post_id = post_guid post.domain = self._domain post.author = self._author_name author_guid = compute_author_guid_by_author_name(self._author_name) post.author_guid = author_guid post.post_osn_guid = post_guid keywords = unicode(row['keywords']) post.tags = keywords post_type = unicode(row['post_type']) post.post_type = post_type return post
def convert_claim_to_post(claim): from DB.schema_definition import Post post = Post() post.post_id = claim.claim_id post.content = claim.title post.description = claim.description post.url = claim.url post.date = claim.verdict_date post.domain = 'Claim' post.author = 'no author' post.author_guid = 'no author' post.guid = compute_post_guid(claim.url, post.author, date_to_str(post.date)) post.post_osn_guid = post.guid post.tags = claim.keywords post.post_type = claim.verdict return post