コード例 #1
0
 def _add_post(self,
               title,
               content,
               date_str,
               domain='Microblog',
               post_type=None):
     post = Post()
     post.author = self._author.author_guid
     post.author_guid = self._author.author_guid
     post.content = content
     post.title = title
     post.domain = domain
     post.post_id = title
     post.guid = post.post_id
     post.date = convert_str_to_unicode_datetime(date_str)
     post.created_at = post.date
     post.post_type = post_type
     self._db.addPost(post)
     self._posts.append(post)
コード例 #2
0
 def convert_comment_to_post(self, comment, submission, domain=u"Reddit"):
     post = Post()
     post.post_osn_id = unicode(comment.id)
     post.created_at = datetime.fromtimestamp(comment.created)
     post.date = datetime.fromtimestamp(comment.created)
     if hasattr(comment, 'author') and comment.author:
         post.author = unicode(comment.author.name)
         self._redditors.append(comment.author)
     else:
         self._deleted_redditors.append(str(post.date))
         post.author = unicode('')
     post.author_guid = compute_author_guid_by_author_name(post.author)
     post.url = unicode('https://www.reddit.com' + '/'.join(getattr(comment, 'permalink', '').split('/')[3:7]))
     post.title = unicode(submission.title)
     post.content = unicode(getattr(comment, 'body', '').encode('utf-8').strip())
     post.guid = compute_post_guid(post.url, post.post_osn_id, date_to_str(post.created_at))
     post.domain = domain
     post.post_type = domain
     post.post_id = post.guid
     post.url = u'https://www.reddit.com{}'.format(comment.permalink)
     return post
    def _create_post(self, original_liar_dataset_id, speaker, targeted_label,
                     statement):
        post = Post()

        post.post_id = str(original_liar_dataset_id)

        post_guid = compute_post_guid(self._social_network_url,
                                      original_liar_dataset_id,
                                      '2007-01-01 00:00:00')
        post.guid = post_guid
        post.domain = self._domain
        post.author = speaker
        author_guid = compute_author_guid_by_author_name(speaker)
        post.author_guid = author_guid
        post.post_osn_guid = post_guid
        post.date = date('2007-01-01 00:00:00')
        post.post_type = targeted_label

        post.content = statement

        return post
    def create_dummy_post(self):
        post = Post()

        post.post_id = unicode(self.post_id)
        post.author = u"author"
        post.guid = unicode(generate_random_guid())
        post.title = u"title"
        post.url = u"http://google.com"
        post.date = str_to_date("2016-08-24 10:00:15")
        post.content = u"text"
        post.is_detailed = True
        post.is_LB = False
        post.is_valid = True
        post.domain = u"Google"
        post.author_guid = unicode(self.author_guid)
        post.post_osn_id = 123455678
        post.retweet_count = 11
        post.favorite_count = 10
        post.created_at = u"2016-08-24 10:00:15"

        return post
コード例 #5
0
    def _convert_tweet_dict_to_post(self, tweet_dict):
        post = Post()

        post_osn_id = tweet_dict['id_str']
        post.post_osn_id = post_osn_id

        author_osn_id = tweet_dict['author_osn_id']
        author = self._author_osn_id_author_dict[author_osn_id]
        author_screen_name = author.author_screen_name
        post.author = author_screen_name

        post.author_guid = compute_author_guid_by_author_name(
            author_screen_name)

        created_at = tweet_dict['created_at']
        post.created_at = created_at

        creation_date_str = extract_tweet_publiction_date(created_at)
        creation_date = str_to_date(creation_date_str)
        post.date = creation_date

        post.favorite_count = tweet_dict['favorite_count']
        post.retweet_count = tweet_dict['retweet_count']
        post.reply_count = tweet_dict['reply_count']
        post.content = str(tweet_dict['full_text'])
        post.domain = self._domain
        post.language = str(tweet_dict['lang'])

        post_url = "https://twitter.com/{0}/status/{1}".format(
            author_screen_name, post_osn_id)
        post.url = post_url

        post_guid = compute_post_guid(post_url, author_screen_name,
                                      creation_date_str)
        post.guid = post_guid
        post.post_id = post_guid

        return post
コード例 #6
0
 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