forked from zhangjing1/finishline
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 9fa59d2
Showing
5 changed files
with
147 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.pyc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
""" Finish Line! A CLI tool for wrapping up your sprints. | ||
See the README for more information. | ||
Author: Ralph Bean <[email protected]> | ||
""" | ||
|
||
import argparse | ||
import datetime | ||
import collections | ||
|
||
import bs4 | ||
import docutils.examples | ||
import requests | ||
import jinja2 | ||
|
||
|
||
custom_filters = { | ||
'slugify': lambda x: x.lower().replace(' ', '-'), | ||
'rst2html': lambda rst: docutils.examples.html_parts(rst)['body'], | ||
'replace': lambda string, char: char * len(string), | ||
} | ||
|
||
|
||
def scrape_links(session, args): | ||
response = session.get(args.url) | ||
soup = bs4.BeautifulSoup(response.text, 'html5lib') | ||
return [l.text for l in soup.find(id='content').findAll('a')[5:]] | ||
|
||
|
||
def parse_arguments(): | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument('--url', help='HTTP-accessible directory where sprint videos and descriptions are stored.') | ||
parser.add_argument('--title', help='Title of the report.') | ||
parser.add_argument('--template', help='Path to a template for output.') | ||
args = parser.parse_args() | ||
if not args.url: | ||
raise ValueError('--url is required') | ||
if not args.title: | ||
raise ValueError('--title is required') | ||
if not args.template: | ||
raise ValueError('--template is required') | ||
return args | ||
|
||
|
||
def prepare(session, args, links): | ||
get = lambda filename: session.get(args.url + '/' + filename).text | ||
|
||
try: | ||
links.remove('readme.rst') | ||
summary = get('readme.rst') | ||
except KeyError: | ||
summary = None | ||
|
||
collated = collections.defaultdict(dict) | ||
for link in links: | ||
key, extension = link.rsplit('.') | ||
collated[key][extension] = link | ||
|
||
entries = [] | ||
for key, items in collated.items(): | ||
|
||
username, rest = key.split('-', 1) | ||
heading = "%s, %s" % (username, rest) | ||
|
||
extensions = items.keys() | ||
try: | ||
rst = extensions.remove('rst') | ||
body = get(items[rst]) | ||
except ValueError: | ||
body = None | ||
|
||
assert(len(extensions) == 1) | ||
link = items[extensions[0]] | ||
|
||
entries.append((heading, body, args.url + '/' + link,)) | ||
|
||
return dict(summary=summary, entries=entries) | ||
|
||
|
||
def render(args, data): | ||
env = jinja2.Environment( | ||
loader=jinja2.FileSystemLoader('templates'), | ||
) | ||
env.filters.update(custom_filters) | ||
template = env.get_template(args.template) | ||
|
||
data = data.copy() | ||
|
||
fmt = "%Y/%m/%d %H:%M:%S" | ||
data['current_date'] = datetime.datetime.now().strftime(fmt) | ||
|
||
data.update(args._get_kwargs()) | ||
|
||
return template.render(**data) | ||
|
||
|
||
if __name__ == '__main__': | ||
import logging | ||
logging.basicConfig(level=logging.INFO) | ||
|
||
args = parse_arguments() | ||
|
||
session = requests.session() | ||
|
||
links = scrape_links(session, args) | ||
|
||
data = prepare(session, args, links) | ||
|
||
output = render(args, data) | ||
print output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
bs4 | ||
docutils | ||
html5lib | ||
requests | ||
jinja2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
--- | ||
categories: fedora, factory2, sprint | ||
date: {{current_date}} | ||
permalink: http://threebean.org/blog/{{title | slugify}}/ | ||
title: {{title}} | ||
--- | ||
|
||
{{summary|rst2html}} | ||
|
||
{% for entry_title, entry_text, entry_link in entries %} | ||
<h2>{{entry_title}}</h2> | ||
{% if entry_text %} | ||
{{entry_text|rst2html}} | ||
{% endif %} | ||
|
||
<p><video width="600" height="350" controls="controls" autobuffer="autobuffer"> | ||
<source src="{{entry_link}}"/> | ||
</video></p> | ||
|
||
{% endfor %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{{title}} | ||
{{title|replace('=')}} | ||
|
||
{{summary}} | ||
{% for entry_title, entry_text, entry_link in entries %}{{entry_title}} | ||
{{entry_title|replace('-')}} | ||
{% if entry_text %}{{entry_text}}{% endif %} | ||
{{entry_link}} | ||
{% endfor %} |