Skip to content

Instantly share code, notes, and snippets.

@Porter97
Last active December 4, 2020 20:41
Show Gist options
  • Save Porter97/5055c18648dfa0af422e0b45c32fe6c4 to your computer and use it in GitHub Desktop.
Save Porter97/5055c18648dfa0af422e0b45c32fe6c4 to your computer and use it in GitHub Desktop.
#...
import ast
class Content(db.Model):
#...
def to_json(self, video=True, iframe=True, audio=True)
json_content = {
'id': self.id,
'title': self.title,
'description': self.description,
'lang': self.lang,
'author': self.author,
'publisher': self.publisher,
'image': {'url': self.image_url,
'type': self.image_type,
'size': self.image_size,
'height': self.image_height,
'width': self.image_width,
'size_pretty': self.image_size_pretty},
'date': self.date,
'url': self.url,
'logo': {'url': self.logo_url,
'type': self.logo_type,
'size': self.logo_size,
'height': self.logo_height,
'width': self.logo_width,
'size_pretty': self.logo_size_pretty},
'audio': self.audio,
'video': self.video,
'iframe': self.iframe,
}
if audio:
json_content['audio'] = {'url': self.audio_url,
'type': self.audio_type,
'duration': self.audio_duration,
'size': self.audio_size,
'duration_pretty': self.audio_duration_pretty,
'size_pretty': self.audio_size_pretty,
} if self.audio else self.audio
if iframe:
json_content['iframe'] = {'html': self.iframe_html,
'scripts': ast.literal_eval(self.iframe_scripts) if self.iframe_scripts else []
} if self.iframe else self.iframe
if video:
json_content['video'] = {'url': self.video_url,
'type': self.video_type,
'duration': self.video_duration,
'size': self.video_size,
'height': self.video_height,
'width': self.video_width,
'duration_pretty': self.video_duration_pretty,
'size_pretty': self.video_size_pretty
} if self.video else self.video,
return json_content
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment