fsfi

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit de28e88a8d4d5fbef16f76808f493b17240a8ae0
parent 5ac17a6bbcd4ee1bbd1a5ab58c946e10a78fd896
Author: rsiddharth <s@ricketyspace.net>
Date:   Mon, 13 May 2019 22:29:28 -0400

Add bin/news.

Diffstat:
bin/news | 76++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 76 insertions(+), 0 deletions(-)

diff --git a/bin/news b/bin/news @@ -0,0 +1,76 @@ +#!/usr/bin/env python3 +# +# SPDX-License-Identifier: ISC +# +# Copyright © 2019 Free Software Foundation India. +# + +import os +import re +import sys + + +# placeholders +PH = { + 'title': '<!-- NEWS-ITEM-TITLE -->', + 'date': '<!-- DATE -->', + 'content': '<!-- MAIN-CONTENT -->', +} + + +def err(s): + print('Error: {}'.format(s)) + sys.exit(1) + + +def files(): + return os.scandir('md/news') + + +def read(f): + with open(f) as f: + c = f.read() + return c + + +def title(c): + m = re.search(r'^\# (.+)$', c, re.M) + + if not m: + err('Title not found') + + return m.group(1) + + +def date(c): + m = re.search(r'pubdate: ([0-9]{8})', c) + + if not m: + err('Publication date not found') + + return m.group(1) + + +def content(c): + m = re.search(r'^\# (.+)$', c, re.M) + + if not m: + err('Unable to slurp content') + + return c[m.end():] + + +def process(f): + c = read(f.path) + + t = title(c) + d = date(c) + c = content(c) + + +def run(): + for f in files(): + process(f) + +if __name__ == "__main__": + run()