コード例 #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
コード例 #2
0
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
コード例 #3
0
    def fetch_posts(self) -> List[SocialPost]:

        social_posts = []  # type: List[SocialPost]

        if self.client is None:
            return social_posts

        response, data = self.client.request(self.timeline_endpoint)

        twitter_posts = json.loads(data)

        for twitter_post in twitter_posts:

            if twitter_post == "errors":
                print(twitter_post)
                continue

            social_post = SocialPost()
            social_post.text = twitter_post["full_text"]
            social_post.externalId = twitter_post["id"]

            entities = twitter_post["entities"]
            if "media" in entities:
                media = entities["media"]
                media_urls = []
                if media is not None:
                    for medium in media:
                        media_urls.append(medium["media_url_https"])
                social_post.mediaURLs = media_urls

            created_date = datetime.strptime(twitter_post["created_at"],
                                             self.twitterDateFormat)

            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 = "twitter"
            social_posts.append(social_post)

        return social_posts
コード例 #4
0
    def convert_to_socialpost(self, events, social_posts):
        for wordpress_post in events:
            social_post = SocialPost()
            social_post.text = wordpress_post["title"]["rendered"]
            social_post.description = wordpress_post["content"]["rendered"]
            social_post.externalId = wordpress_post["id"]

            # Tue Sep 18 07:44:20 +0000 2018

            created_date = datetime.strptime(wordpress_post["date"],
                                             self.wordpressDateFormat)

            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=1))
            social_post.validFrom = Util.convert_date_to_UTC_time_stamp(
                created_date)
            social_post.source = "wordpress"
            social_posts.append(social_post)
コード例 #5
0
    def convert_to_socialpost(self, events, social_posts):
        if events is None:
            return []

        for event in events:
            try:
                social_post = SocialPost()
                social_post.text = event['summary']
                try:
                    social_post.created = Util.convert_date_to_UTC_time_stamp(
                        datetime.strptime(event['created'],
                                          self.googleDateFormat2))
                except Exception as ex:
                    print(ex)
                    social_post.created = int(datetime.utcnow().timestamp())

                if event['start'].get('dateTime') is not None:
                    social_post.start = parser.parse(
                        event['start']['dateTime']).timestamp()
                    social_post.validFrom = (
                        parser.parse(event['start']['dateTime']) -
                        timedelta(weeks=3)).timestamp()
                else:
                    social_post.start = parser.parse(
                        event['start']['date']).timestamp()
                    social_post.validFrom = (
                        parser.parse(event['start']['date']) -
                        timedelta(weeks=3)).timestamp()

                if event['end'].get('dateTime') is not None:
                    social_post.end = parser.parse(
                        event['end']['dateTime']).timestamp()
                    social_post.validTo = parser.parse(
                        event['end']['dateTime']).timestamp()
                else:
                    social_post.end = parser.parse(
                        event['end']['date']).timestamp()
                    social_post.validTo = parser.parse(
                        event['end']['date']).timestamp()

                social_post.externalId = event['id']

                if event.get('role') is not None:
                    social_post.role = event['role']

                location = event.get('location')

                if location is not None:
                    social_post.location = location
                else:
                    social_post.location = ''

                social_post.status = event['status']

                social_post.source = 'Google calendar'

                description = event.get('description')

                if description is not None:
                    social_post.description = description
                else:
                    social_post.location = ""

                social_posts.append(social_post)
            except Exception as ex:
                print('Exception in %s' % event)
                print(ex)