Commit f5f8b2da2b1033c3b4868abfef39dbd8c6947227
Run sbot and hugo automatically
Greg K Nicholson committed on 10/15/2017, 1:16:58 AMParent: c12c00615ebc62ecf11607d4aef9cadefefd5030
Files changed
scuttleblog.py | changed |
scuttleblog.py | ||
---|---|---|
@@ -24,16 +24,27 @@ | ||
24 | 24 … | import datetime |
25 | 25 … | import json |
26 | 26 … | import os |
27 | 27 … | import re |
28 … | +import time | |
28 | 29 … | import subprocess |
29 | 30 … | |
30 | 31 … | import conf |
31 | 32 … | |
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 … | + | |
32 | 43 … | def get_user_posts(userid): |
33 | 44 … | user_posts_args = ['sbot', 'createUserStream', '--id', userid] |
34 | 45 … | 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) | |
36 | 47 … | user_posts_json = subprocess.check_output(json_posts_args, stdin = user_posts_stream.stdout) |
37 | 48 … | user_posts = json.loads(user_posts_json) |
38 | 49 … | return user_posts |
39 | 50 … | |
@@ -54,9 +65,9 @@ | ||
54 | 65 … | return (post) |
55 | 66 … | |
56 | 67 … | def format_post_file(post): |
57 | 68 … | content = '' |
58 | - content += str(json.dumps(post['frontmatter'], indent=4)) | |
69 … | + content += str(json.dumps(post['frontmatter'], indent = 4)) | |
59 | 70 … | content += '\n\n' |
60 | 71 … | content += str(post['text']) |
61 | 72 … | return content |
62 | 73 … | |
@@ -76,14 +87,13 @@ | ||
76 | 87 … | posts = get_user_posts(userid) |
77 | 88 … | for post in posts: |
78 | 89 … | write_post_file(build_post_structure(post)) |
79 | 90 … | |
80 | -write_posts_from_user(conf.userid) | |
81 | 91 … | |
82 | 92 … | def get_user_metadata(userid): |
83 | 93 … | user_metadata_args = ['sbot', 'links', '--source', userid, '--dest', userid, '--rel', 'about', '--values'] |
84 | 94 … | 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) | |
86 | 96 … | user_metadata_json = subprocess.check_output(json_metadata_args, stdin = user_metadata_stream.stdout) |
87 | 97 … | user_metadata = json.loads(user_metadata_json) |
88 | 98 … | return user_metadata |
89 | 99 … | |
@@ -97,8 +107,15 @@ | ||
97 | 107 … | |
98 | 108 … | def write_hugo_config_from_user(userid): |
99 | 109 … | metadata = get_user_metadata(userid) |
100 | 110 … | 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)) | |
102 | 112 … | # TODO: add the user's image in the right place |
103 | 113 … | |
114 … | +def run_hugo(): | |
115 … | + subprocess.run(['hugo', '-s', 'hugo']) | |
116 … | + | |
117 … | +run_sbot() | |
118 … | +write_posts_from_user(conf.userid) | |
104 | 119 … | write_hugo_config_from_user(conf.userid) |
120 … | +run_hugo() | |
121 … | + |
Built with git-ssb-web