示例#1
0
    def convert_to_socialpost(self, events, social_posts):
        for insta_post in events:
            social_post = SocialPost()
            social_post.text = insta_post['caption']['text']
            social_post.externalId = insta_post['id']

            social_post.image = insta_post['images']['standard_resolution'][
                'url']

            created_date = datetime.fromtimestamp(
                int(insta_post["created_time"]))

            social_post.created = Util.convert_date_to_UTC_time_stamp(
                created_date)

            social_post.validTo = Util.convert_date_to_UTC_time_stamp(
                created_date + timedelta(weeks=3))
            social_post.validFrom = Util.convert_date_to_UTC_time_stamp(
                created_date)
            social_post.source = "instagram"
            social_post.likes = insta_post['likes']['count']
            social_post.comments = insta_post['comments']['count']
            social_posts.append(social_post)

        return social_posts
def create_post_from_request(content):
    social_post = SocialPost()
    social_post.title = content['title']
    social_post.text = content['text']
    social_post.created = Util.convert_date_to_UTC_time_stamp(
        parser.isoparse(content["created"]))
    social_post.source = "custom post"
    social_post.validTo = Util.convert_date_to_UTC_time_stamp(
        parser.isoparse(content["end"]))
    social_post.validFrom = Util.convert_date_to_UTC_time_stamp(
        parser.isoparse(content["start"]) - timedelta(weeks=3))
    if 'image' in content is not None and len(content['image']) > 0:
        social_post.image = content['image']
    social_post.start = Util.convert_date_to_UTC_time_stamp(
        parser.isoparse(content["start"]))
    social_post.end = Util.convert_date_to_UTC_time_stamp(
        parser.isoparse(content["end"]))
    return social_post