Exemplo n.º 1
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)
    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)