Skip to content

Commit

Permalink
refactored
Browse files Browse the repository at this point in the history
  • Loading branch information
priyatam committed Jul 30, 2014
1 parent ec423ec commit 7f19327
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 2 deletions.
File renamed without changes.
1 change: 0 additions & 1 deletion scripts/clojure/target/repl-port

This file was deleted.

1 change: 0 additions & 1 deletion scripts/clojure/target/stale/extract-native.dependencies

This file was deleted.

18 changes: 18 additions & 0 deletions scripts/python/poem.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
title: You May Forget
author: Sappho
country: Greece
year: 600/500 bc
gender: female
tags:
- time
- love
- lyric
- memory
---

You may forget but
let me tell you
this: someone in
some future time
will think of us.
2 changes: 2 additions & 0 deletions scripts/python/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
markdown
PyYaml
68 changes: 68 additions & 0 deletions scripts/python/zendown.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/usr/bin/env python
"""
Script to convert poems & stories written in Zenup to HTML
usage:
zenup.py <folder-to-zenup-files>
copyright:
(c) 2014 by Priyatam Mudivarti
license:
BSD-style License; see LICENSE for more details.
"""

import sys
import os
import yaml
import markdown as md
import argparse


def load(path):
"""Create a dictionary for retrieving content's raw body, metadata"""
data = []
for fname in os.listdir(path):
if fname.endswith('.md') or fname.endswith('.txt'):
try:
meta, raw = read_contents(path, fname)
content = {
"name": meta.get("_type", "contents") + "/" + fname,
"original": raw,
"html": md.markdown(post['body']),
"modified_date": format_date(path + os.sep + fname)
}
content.update(meta)
data.append(content)
except:
logger.error("Error while reading contents: %s: %s" % (fname, sys.exc_info()[0]))
else:
logger.warning("Incorrect Extension: %s" % fname)
return data


def read_contents(directory, fname):
"""Splits subdir/fname into a tuple of YAML and raw content"""
with open(directory + os.sep + fname, "r", "utf-8") as fin:
yaml_and_raw = fin.read().split('\n---\n')
if len(yaml_and_raw) == 1:
return {}, yaml_and_raw[0]
else:
return yaml.load(yaml_and_raw[0]), yaml_and_raw[1]


def format_date(fname):
"""Formats to internal date format"""
return datetime.strptime(time.ctime(os.path.getmtime(fname)), "%a %b %d %H:%M:%S %Y").strftime("%m-%d-%y")


def parse_cmdline_args(args):
"""Parse command line args"""
parser = argparse.ArgumentParser(description='Zenup: A minimalist static site generator and router.')
parser.add_argument("root", type=str,
help='path to root project folder containing zenup files')
return parser.parse_args(args[1:])

if __name__ == '__main__':
args = parse_cmdline_args(sys.argv)
if args.root:
load(args)

0 comments on commit 7f19327

Please sign in to comment.