summaryrefslogtreecommitdiffstats
path: root/bin/news
diff options
context:
space:
mode:
authorrsiddharth <s@ricketyspace.net>2019-05-13 22:29:28 -0400
committerrsiddharth <s@ricketyspace.net>2019-05-13 22:29:28 -0400
commitde28e88a8d4d5fbef16f76808f493b17240a8ae0 (patch)
tree0dc85656cc540da092b898cb06f31f641d48e655 /bin/news
parent5ac17a6bbcd4ee1bbd1a5ab58c946e10a78fd896 (diff)
Add bin/news.
Diffstat (limited to 'bin/news')
-rw-r--r--bin/news76
1 files changed, 76 insertions, 0 deletions
diff --git a/bin/news b/bin/news
new file mode 100644
index 0000000..07cef16
--- /dev/null
+++ 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()