json profile export
This commit is contained in:
parent
ae6650c775
commit
0b8b5ce498
27
microblog.py
27
microblog.py
@ -160,8 +160,7 @@ def parse_txt(filename):
|
|||||||
state = 0
|
state = 0
|
||||||
return posts
|
return posts
|
||||||
|
|
||||||
def get_posts(filename, config):
|
def get_posts(posts, config):
|
||||||
posts = parse_txt(filename)
|
|
||||||
taginfos = []
|
taginfos = []
|
||||||
tagcloud = dict() # (tag, count)
|
tagcloud = dict() # (tag, count)
|
||||||
tagged = dict() # (tag, index of message)
|
tagged = dict() # (tag, index of message)
|
||||||
@ -347,6 +346,22 @@ if __name__ == "__main__":
|
|||||||
s = None
|
s = None
|
||||||
return s
|
return s
|
||||||
|
|
||||||
|
import json
|
||||||
|
# generate json basd on profile
|
||||||
|
def export_profile(post_count, last_update, config):
|
||||||
|
if "alias" not in config["profile"] \
|
||||||
|
or "url" not in config["profile"]:
|
||||||
|
print("Warning: no profile exported", file=sys.stderr)
|
||||||
|
return
|
||||||
|
profile = {
|
||||||
|
"username" : config["profile"]["alias"],
|
||||||
|
"url": config["profile"]["url"],
|
||||||
|
"last-updated": last_update,
|
||||||
|
"post-count" : post_count
|
||||||
|
}
|
||||||
|
with open(config["file_output"], 'w') as f:
|
||||||
|
print(json.dumps(profile), file=f)
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
tpl, content = get_args()
|
tpl, content = get_args()
|
||||||
cfg = load_settings()
|
cfg = load_settings()
|
||||||
@ -359,7 +374,13 @@ if __name__ == "__main__":
|
|||||||
if "page" not in cfg:
|
if "page" not in cfg:
|
||||||
print("exit: table 'page' absent in settings.toml", file=sys.stderr)
|
print("exit: table 'page' absent in settings.toml", file=sys.stderr)
|
||||||
return
|
return
|
||||||
tl, tc, tg = get_posts(content, cfg["post"])
|
p = parse_txt(content)
|
||||||
|
if "syndication" in cfg:
|
||||||
|
if cfg["syndication"]["enabled"] == True:
|
||||||
|
export_profile(
|
||||||
|
len(p), p[0].get_epoch_time(), cfg["syndication"]
|
||||||
|
)
|
||||||
|
tl, tc, tg = get_posts(p, cfg["post"])
|
||||||
if tl == []:
|
if tl == []:
|
||||||
return
|
return
|
||||||
# main timeline
|
# main timeline
|
||||||
|
Loading…
x
Reference in New Issue
Block a user