Created
April 25, 2017 15:25
-
-
Save omaciel/7b65d99b88547884e128777cbe7e82aa to your computer and use it in GitHub Desktop.
Generate the template code for a new podcast episode show notes
This file contains hidden or 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
import sys | |
import optparse | |
from ConfigParser import SafeConfigParser | |
ddg = "https://duckduckgo.com/?q=" | |
lastfm = "http://www.last.fm/search?q=" | |
imdb = "http://www.imdb.com/find?s=all&q=" | |
amazon = "http://www.amazon.com/s/ref=nb_sb_noss?url=search-alias%3Dstripbooks&field-keywords=" | |
music_attrib = """ | |
<em>* <strong>Música</strong>: <a title="http://freemusicarchive.org/music/Red_Hook_Ramblers/Live__WFMU_on_Antique_Phonograph_Music_Program_with_MAC_Feb_8_2011/Red_Hook_Ramblers_-_12_-_Aint_Gonna_Give_Jelly_Roll" href="http://freemusicarchive.org/music/Red_Hook_Ramblers/Live__WFMU_on_Antique_Phonograph_Music_Program_with_MAC_Feb_8_2011/Red_Hook_Ramblers_-_12_-_Aint_Gonna_Give_Jelly_Roll" target="_blank">Ain't Gonna Give Jelly Roll</a> by <a title="http://freemusicarchive.org/music/Red_Hook_Ramblers/" href="http://freemusicarchive.org/music/Red_Hook_Ramblers/" target="_blank">Red Hook Ramblers</a> is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives (aka Music Sharing) License.</em> | |
""" | |
def _parse_values(cfg_file, section, item, delimeter="\n"): | |
items = cfg_file.get(section, item) | |
# We have a string with several \n embbeded in it. | |
items = items.split(delimeter) | |
# Some items may be empty, so remove them. | |
items = [item for item in items if len(item) > 0] | |
return items | |
def _print_bullet_list(items, service=""): | |
for item in items: | |
# Make a copy or original item. | |
cp_item = item | |
# Format item for html query. | |
item = item.replace(" ", "+") | |
# Some html formating for the bullet item. | |
if service == ddg: | |
item_html = '<a href=\"%s%s\">%s</a>' % (ddg, item, cp_item) | |
elif service == amazon: | |
item_html = '<strong>Livros: </strong><a href=\"%s%s\">%s</a>' % (amazon, item, cp_item) | |
elif service == lastfm: | |
item_html = '<strong>M√∫sica: </strong><a href=\"%s%s\">%s</a>' % (lastfm, item, cp_item) | |
elif service == imdb: | |
item_html = '<strong>Filmes: </strong><a href=\"%s%s\">%s</a>' % (imdb, item, cp_item) | |
else: | |
item_html = '<strong>%s</strong> %s' | |
print "<li>%s</li>" % item_html | |
def _print_tracks(cfg_file): | |
tracks = _parse_values(cfg_file, 'resumo', 'tracks') | |
tracks = [track.split("-") for track in tracks if len(track) > 0] | |
if not tracks: | |
return | |
print "<p><strong>Resumo:</strong>" | |
print "<ul>" | |
for track in tracks: | |
print "<li><strong>%s</strong> %s</li>" % (track[0], track[1]) | |
print "</ul>" | |
print "</p>" | |
def _print_top_5(cfg_file): | |
music = _parse_values(cfg_file, 'top5', 'music') | |
movies = _parse_values(cfg_file, 'top5', 'movies') | |
books = _parse_values(cfg_file, 'top5','books') | |
software = _parse_values(cfg_file, 'top5', 'software') | |
print "<p><strong>Top 5:</strong>" | |
print "<ul>" | |
_print_bullet_list(music, lastfm) | |
_print_bullet_list(movies, imdb) | |
_print_bullet_list(books, amazon) | |
_print_bullet_list(software, ddg) | |
print "</ul>" | |
print "</p>" | |
def _print_links(cfg_file): | |
links = _parse_values(cfg_file, 'links', 'items') | |
print "<p><strong>Links:</strong>" | |
print "<ul>" | |
_print_bullet_list(links, ddg) | |
print "</ul>" | |
print "</p>" | |
def _print_tags(cfg_file): | |
tags = [] | |
tags.extend(_parse_values(cfg_file, 'top5', 'music')) | |
tags.extend(_parse_values(cfg_file, 'top5', 'movies')) | |
tags.extend(_parse_values(cfg_file, 'top5','books')) | |
tags.extend(_parse_values(cfg_file, 'top5', 'software')) | |
tags.extend(_parse_values(cfg_file, 'links', 'items')) | |
print "TAGS:" | |
print ", ".join(tags) | |
if __name__ == "__main__": | |
p = optparse.OptionParser() | |
p.set_usage("Usage: castalio [OPTIONS]") | |
p.add_option('-f', '--file', type="string", dest="cfg") | |
options, arguments = p.parse_args() | |
if not options.cfg: | |
p.print_help() | |
sys.exit(-1) | |
podcast = SafeConfigParser() | |
podcast.read(options.cfg) | |
_print_tracks(podcast) | |
_print_top_5(podcast) | |
_print_links(podcast) | |
print music_attrib | |
_print_tags(podcast) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment