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
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)