def _parse_post(self, json_content): post = Post() content = json_content['postText'][0] post.content = content str_post_timestamp = json_content["postTimestamp"] post.created_at = str(str_post_timestamp) # post_timestamp = dateutil.parser.parse(str_post_timestamp) # str_post_date = date_to_str(post_timestamp) post_timestamp, str_post_date = self._get_str_and_date_formats( str_post_timestamp) post.date = post_timestamp post_media = json_content["postMedia"] if len(post_media) > 0: post.media_path = post_media[0] else: post.media_path = None post_id = json_content["id"] post.post_id = post_id post.author = post_id post_guid = compute_post_guid(self._social_network_url, post_id, str_post_date) post.guid = post_guid post.domain = self._domain post.author_guid = post_guid post.post_osn_guid = post_guid return post
def _generate_post(self, instagram_post): post = Post() post.author_guid = str(instagram_post['owner']['id']) post.date = datetime.datetime.fromtimestamp(instagram_post['taken_at_timestamp']) post.post_osn_id = instagram_post['id'] try: post.content = instagram_post['edge_media_to_caption']['edges'][0]['node']['text'] except: pass post.retweet_count = instagram_post['edge_media_to_comment']['count'] post.favorite_count = instagram_post['edge_media_preview_like']['count'] post.url = 'https://www.instagram.com/p/{}/'.format(instagram_post['shortcode']) image_names = [] # for url in instagram_post['urls']: # image_name_contaner = url.split('/')[-1] # end = image_name_contaner.index('?') # image_names.append(image_name_contaner[:end]) image_name = self._get_image_name_from_url(instagram_post['display_url']) post.media_path = str(instagram_post['display_url']) post.post_format = '{}'.format(image_name) post.domain = 'Instagram' post.post_type = 'post' post.post_id = str(post.post_osn_id) return post