git ssb

0+

Grey the earthling / scuttleblog



Commit f5f8b2da2b1033c3b4868abfef39dbd8c6947227

Run sbot and hugo automatically

Greg K Nicholson committed on 10/15/2017, 1:16:58 AM
Parent: c12c00615ebc62ecf11607d4aef9cadefefd5030

Files changed

scuttleblog.pychanged
scuttleblog.pyView
@@ -24,16 +24,27 @@
2424 import datetime
2525 import json
2626 import os
2727 import re
28 +import time
2829 import subprocess
2930
3031 import conf
3132
33 +def run_sbot():
34 + for attempt in range(100):
35 + try:
36 + subprocess.check_output(['sbot', 'status'])
37 + except:
38 + pid = subprocess.Popen(['sbot', 'server']).pid
39 + time.sleep(1)
40 + else:
41 + break
42 +
3243 def get_user_posts(userid):
3344 user_posts_args = ['sbot', 'createUserStream', '--id', userid]
3445 json_posts_args = ['json', '--group', '-c', 'this.value.content.type == "post"', '-c', 'this.value.content.root == null']
35- user_posts_stream = subprocess.Popen(user_posts_args, stdout=subprocess.PIPE)
46 + user_posts_stream = subprocess.Popen(user_posts_args, stdout = subprocess.PIPE)
3647 user_posts_json = subprocess.check_output(json_posts_args, stdin = user_posts_stream.stdout)
3748 user_posts = json.loads(user_posts_json)
3849 return user_posts
3950
@@ -54,9 +65,9 @@
5465 return (post)
5566
5667 def format_post_file(post):
5768 content = ''
58- content += str(json.dumps(post['frontmatter'], indent=4))
69 + content += str(json.dumps(post['frontmatter'], indent = 4))
5970 content += '\n\n'
6071 content += str(post['text'])
6172 return content
6273
@@ -76,14 +87,13 @@
7687 posts = get_user_posts(userid)
7788 for post in posts:
7889 write_post_file(build_post_structure(post))
7990
80-write_posts_from_user(conf.userid)
8191
8292 def get_user_metadata(userid):
8393 user_metadata_args = ['sbot', 'links', '--source', userid, '--dest', userid, '--rel', 'about', '--values']
8494 json_metadata_args = ['json', '--deep-merge', '-c', 'this.value.content.type == "about"']
85- user_metadata_stream = subprocess.Popen(user_metadata_args, stdout=subprocess.PIPE)
95 + user_metadata_stream = subprocess.Popen(user_metadata_args, stdout = subprocess.PIPE)
8696 user_metadata_json = subprocess.check_output(json_metadata_args, stdin = user_metadata_stream.stdout)
8797 user_metadata = json.loads(user_metadata_json)
8898 return user_metadata
8999
@@ -97,8 +107,15 @@
97107
98108 def write_hugo_config_from_user(userid):
99109 metadata = get_user_metadata(userid)
100110 with open('hugo/config.json', 'w') as f:
101- f.write (json.dumps(build_hugo_config(metadata)))
111 + f.write (json.dumps(build_hugo_config(metadata), indent = 4))
102112 # TODO: add the user's image in the right place
103113
114 +def run_hugo():
115 + subprocess.run(['hugo', '-s', 'hugo'])
116 +
117 +run_sbot()
118 +write_posts_from_user(conf.userid)
104119 write_hugo_config_from_user(conf.userid)
120 +run_hugo()
121 +

Built with git-ssb-web