Commit 9185c88f authored by Alessandro CERIONI's avatar Alessandro CERIONI
Browse files

Adding relations to datasets, pages, posts (through tags).

parent 44ee6f9f
Pipeline #3229 passed with stage
in 41 seconds
......@@ -8,6 +8,36 @@ if __name__ != '__main__':
logger.setLevel(gunicorn_logger.level)
def find_relations( tags ):
relations = dict()
for tag in tags:
if tag['name'].startswith('#dataset-slug:'):
if 'datasets' not in relations.keys():
relations['datasets'] = dict()
if 'slugs' not in relations['datasets']:
relations['datasets']['slugs'] = []
relations['datasets']['slugs'].append( tag['name'].split(":")[1] )
if tag['name'].startswith('#post-slug'):
if 'posts' not in relations.keys():
relations['posts'] = dict()
if 'slugs' not in relations['posts']:
relations['posts']['slugs'] = []
relations['posts']['slugs'].append( tag['name'].split(":")[1] )
if tag['name'].startswith('#page-slug:'):
if 'pages' not in relations.keys():
relations['datasets'] = dict()
if 'slugs' not in relations['pages']:
relations['pages']['slugs'] = []
relations['pages']['slugs'].append( tag['name'].split(":")[1] )
return relations
return relations
def process_posts( posts ):
output_posts = []
......@@ -19,6 +49,7 @@ def process_posts( posts ):
output_post['content-fr'] = post
output_post['uuid'] = post['uuid']
output_post['type'] = 'post'
output_post['relations'] = find_relations( post['tags'] )
output_posts.append(output_post)
......@@ -37,6 +68,7 @@ def process_pages( pages ):
output_page['content-fr'] = page
output_page['uuid'] = page['uuid']
output_page['type'] = 'page'
output_post['relations'] = find_relations( post['tags'] )
output_pages.append(output_page)
......@@ -47,10 +79,10 @@ def process_pages( pages ):
if __name__ == '__main__':
import json
posts = [{u'og_image': None, u'codeinjection_foot': None, u'plaintext': u'Le contenu\n\nL\xe9gende\n--------------------------------------------------------------------------------\n\n/image \nhttps://highway-to-data.alpha.grandlyon.com/wp2-intothesky/2019/02/home-smartdata.jpg\n\nthis is another update', u'excerpt': u'Le contenu\n\nL\xe9gende\n--------------------------------------------------------------------------------\n\n/image \nhttps://highway-to-data.alpha.grandlyon.com/wp2-intothesky/2019/02/home-smartdata.jpg\n\nthis is another update', u'updated_at': u'2019-03-03T16:49:28.000Z', u'custom_template': None, u'published_at': u'2019-03-03T16:39:59.000Z', u'og_title': None, u'twitter_image': None, u'id': u'5c7906a70a48e60001b47cc4', u'twitter_description': None, u'meta_description': None, u'uuid': u'c9204cc3-da09-4759-abf9-36fab98c6e6e', u'title': u'Mon premier brouillon', u'twitter_title': None, u'html': u'<p>Le contenu</p><!--kg-card-begin: image--><figure class="kg-card kg-image-card kg-card-hascaption"><img src="https://ghost-intothesky.alpha.grandlyon.com/content/images/2019/03/Screenshot-from-2019-02-14-14-09-51.png" class="kg-image"><figcaption>L\xe9gende</figcaption></figure><!--kg-card-end: image--><!--kg-card-begin: hr--><hr><!--kg-card-end: hr--><!--kg-card-begin: markdown--><p>/image <a href="https://highway-to-data.alpha.grandlyon.com/wp2-intothesky/2019/02/home-smartdata.jpg">https://highway-to-data.alpha.grandlyon.com/wp2-intothesky/2019/02/home-smartdata.jpg</a></p>\n<!--kg-card-end: markdown--><p>this is another update</p>', u'primary_author': {u'website': None, u'bio': None, u'meta_title': None, u'name': u'Alessandro Cerioni', u'updated_at': u'2019-03-03T16:29:36.000Z', u'twitter': None, u'profile_image': None, u'accessibility': None, u'id': u'1', u'status': u'active', u'tour': u'["getting-started","featured-post"]', u'url': u'https://ghost-intothesky.alpha.grandlyon.com/author/alessandro/', u'facebook': None, u'location': None, u'cover_image': None, u'created_at': u'2019-03-01T08:26:45.000Z', u'meta_description': None, u'slug': u'alessandro', u'last_seen': u'2019-03-03T16:29:36.000Z'}, u'status': u'draft', u'primary_tag': {u'meta_description': None, u'meta_title': None, u'feature_image': None, u'name': u'test_tag', u'url': u'https://ghost-intothesky.alpha.grandlyon.com/404/', u'created_at': u'2019-03-03T16:45:44.000Z', u'updated_at': u'2019-03-03T16:45:44.000Z', u'visibility': u'public', u'id': u'5c7c04b8bf1a290001e7eb66', u'slug': u'test_tag', u'description': None}, u'meta_title': None, u'og_description': None, u'feature_image': None, u'tags': [{u'meta_description': None, u'meta_title': None, u'feature_image': None, u'name': u'test_tag', u'url': u'https://ghost-intothesky.alpha.grandlyon.com/404/', u'created_at': u'2019-03-03T16:45:44.000Z', u'updated_at': u'2019-03-03T16:45:44.000Z', u'visibility': u'public', u'id': u'5c7c04b8bf1a290001e7eb66', u'slug': u'test_tag', u'description': None}], u'comment_id': u'5c7906a70a48e60001b47cc4', u'custom_excerpt': None, u'authors': [{u'website': None, u'bio': None, u'meta_title': None, u'name': u'Alessandro Cerioni', u'updated_at': u'2019-03-03T16:29:36.000Z', u'twitter': None, u'profile_image': None, u'accessibility': None, u'id': u'1', u'status': u'active', u'tour': u'["getting-started","featured-post"]', u'url': u'https://ghost-intothesky.alpha.grandlyon.com/author/alessandro/', u'facebook': None, u'location': None, u'cover_image': None, u'created_at': u'2019-03-01T08:26:45.000Z', u'meta_description': None, u'slug': u'alessandro', u'last_seen': u'2019-03-03T16:29:36.000Z'}], u'slug': u'mon-premier-brouillon', u'url': u'https://ghost-intothesky.alpha.grandlyon.com/404/', u'created_at': u'2019-03-01T10:17:11.000Z', u'featured': True, u'codeinjection_head': None}]
output = process_posts(posts)
print(output)
print( json.dumps(output, indent=4) )
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment