Last active
October 6, 2015 00:15
-
-
Save omaciel/b452042863f2c0ae44d4 to your computer and use it in GitHub Desktop.
Helper to generate a RST-formatted article stub for my monthly blog post about books.
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
{ | |
"2015": { | |
"october": { | |
"read": [ | |
{ | |
"author": "John Steinbeck", | |
"title": "The Moon Is Down" | |
} | |
], | |
"reading": [ | |
{ | |
"author": "Marcel Proust", | |
"title": "The Complete Short Stories Of Marcel Proust" | |
}, | |
{ | |
"author": "Herman Melville", | |
"title": "Billy Budd and Other Stories" | |
} | |
] | |
}, | |
"september": { | |
"read": [ | |
{ | |
"author": "Nick Hornby", | |
"title": "A Long Way Down" | |
}, | |
{ | |
"author": "Jane Austen", | |
"title": "Sense and Sensibility" | |
}, | |
{ | |
"author": "Paolo Bacigalupi", | |
"title": "The Water Knife" | |
}, | |
{ | |
"author": "Osamu Tezuka", | |
"title": "Buddha, Vol. 1\\: Kapilavastu" | |
}, | |
{ | |
"author": "Franz Kafka", | |
"title": "Selected Short Stories" | |
} | |
], | |
"reading": [ | |
{ | |
"author": "Herman Melville", | |
"title": "Billy Budd and Other Stories" | |
} | |
], | |
"gift": [ | |
{ | |
"author": "Machado de Assis", | |
"title": "Helena" | |
}, | |
{ | |
"author": "Machado de Assis", | |
"title": "Contos Fluminenses" | |
}, | |
{ | |
"author": "Jose de Alencar", | |
"title": "O Guarani" | |
}, | |
{ | |
"author": "Clarice Lispector", | |
"title": "O Lustre" | |
}, | |
{ | |
"author": "Dias Gomes", | |
"title": "O Santo Inquerito" | |
}, | |
{ | |
"author": "Gilberto Freire", | |
"title": "Dona Sinha e o Filho Padre" | |
}, | |
{ | |
"author": "Saul Bellow", | |
"title": "Seize the Day" | |
}, | |
{ | |
"author": "Ariano Suassuma", | |
"title": "Auto da Compadecida" | |
}, | |
{ | |
"author": "Rubem Fonseca", | |
"title": "O Buraco na Parece" | |
}, | |
{ | |
"author": "Rubem Fonseca", | |
"title": "Bufo & Spallanzani" | |
}, | |
{ | |
"author": "Machado de Assis", | |
"title": "Quincas Borda" | |
}, | |
{ | |
"author": "Joaquim Manuel de Macedo", | |
"title": "A Moreninha" | |
}, | |
{ | |
"author": "Jose Saramago", | |
"title": "Todos os Nomes" | |
}, | |
{ | |
"author": "William Faulkner", | |
"title": "As I Lay Dying" | |
}, | |
{ | |
"author": "Leo Tolstoy", | |
"title": "War and Peace" | |
} | |
] | |
}, | |
"august": { | |
"read": [ | |
{ | |
"author": "Edgar Rice Burroughs", | |
"title": "A Princess of Mars" | |
}, | |
{ | |
"author": "Shirley Jackson", | |
"title": "The Lottery\\: And Other Stories" | |
}, | |
{ | |
"author": "Robert M. Pirsig", | |
"title": "Zen and the Art of Motorcycle Maintenance\\: An Inquiry Into Values" | |
}, | |
{ | |
"author": "John Steinbeck", | |
"title": "Cannery Row" | |
}, | |
{ | |
"author": "Shirley Jackson", | |
"title": "We Have Always Lived in the Castle" | |
}, | |
{ | |
"author": "Arthur C. Clarke", | |
"title": "The Sentinel" | |
}, | |
{ | |
"author": "Neil Gaiman", | |
"title": "Neverwhere" | |
}, | |
{ | |
"author": "Graciliano Ramos", | |
"title": "Vidas Secas" | |
} | |
], | |
"reading": [ | |
{ | |
"author": "Franz Kafka", | |
"title": "Selected Short Stories" | |
}, | |
{ | |
"author": "Herman Melville", | |
"title": "Billy Budd and Other Stories" | |
} | |
], | |
"bought": [ | |
{ | |
"author": "John Steinbeck", | |
"title": "Cannery Row" | |
}, | |
{ | |
"author": "Herman Melville", | |
"title": "Typee" | |
}, | |
{ | |
"author": "Jane Austen", | |
"title": "The Oxford Illustrated Jane Austen\\: Volume VI\\: Minor Works" | |
}, | |
{ | |
"author": "Lewis Carrol", | |
"title": "The Annotated Alice\\: The Definitive Edition" | |
}, | |
{ | |
"author": "Henry James", | |
"title": "Italian Hours" | |
}, | |
{ | |
"author": "Ray Bradbury", | |
"title": "The Vintage Bradbury" | |
}, | |
{ | |
"author": "Franz Kafka", | |
"title": "Amerika" | |
}, | |
{ | |
"author": "Nikolai Gogol", | |
"title": "The Diary of a Madman, the Government Inspector, and Selected Stories" | |
}, | |
{ | |
"author": "Henry James", | |
"title": "The Turn of the Screw" | |
}, | |
{ | |
"author": "William Golding", | |
"title": "Lord of the Flies" | |
}, | |
{ | |
"author": "Marcel Proust", | |
"title": "Remembrance of Things Past\\: Volume One" | |
}, | |
{ | |
"author": "Franz Kafka", | |
"title": "Selected Short Stories" | |
}, | |
{ | |
"author": "Alexandre Dumas", | |
"title": "The Count of Monte Cristo" | |
}, | |
{ | |
"author": "Flannery O'Connor", | |
"title": "A Good Man Is Hard to Find And Other Stories" | |
}, | |
{ | |
"author": "Henry Miller", | |
"title": "Tropic of Cancer" | |
}, | |
{ | |
"author": "Marcel Proust", | |
"title": "Swann's Way" | |
}, | |
{ | |
"author": "Milan Kundera", | |
"title": "The Unbearable Lightness of Being" | |
}, | |
{ | |
"author": "Nick Hornby", | |
"title": "A Long Way Down" | |
}, | |
{ | |
"author": "Dan Brown", | |
"title": "Digital Fortress" | |
}, | |
{ | |
"author": "Saul Bellow", | |
"title": "Seize the Day" | |
}, | |
{ | |
"author": "Stieg Larsson", | |
"title": "The Girl Who Played with Fire" | |
}, | |
{ | |
"author": "Edgar Allan Poe", | |
"title": "Complete Tales & Poems" | |
}, | |
{ | |
"author": "Bram Stoker", | |
"title": "Dracula" | |
} | |
] | |
}, | |
"july": { | |
"read": [ | |
{ | |
"author": "John Steinbeck", | |
"title": "Of Mice and Men" | |
}, | |
{ | |
"author": "Ernest Cline", | |
"title": "Armada" | |
}, | |
{ | |
"author": "Ray Bradbury", | |
"title": "The October Country" | |
}, | |
{ | |
"author": "Arthur Conan Doyle", | |
"title": "The Memoirs of Sherlock Holmes" | |
}, | |
{ | |
"author": "Neal Stephenson", | |
"title": "Cryptonomicon" | |
}, | |
{ | |
"author": "Michael Lopp", | |
"title": "Managing Humans\\: Biting and Humorous Tales of a Software Engineering Manager" | |
}, | |
{ | |
"author": "C. S. Lewis", | |
"title": "The Magician's Nephew" | |
}, | |
{ | |
"author": "C. S. Lewis", | |
"title": "The Lion, the Witch and the Wardrobe" | |
}, | |
{ | |
"author": "C. S. Lewis", | |
"title": "The Horse and His Boy" | |
}, | |
{ | |
"author": "Erich Maria Remarque", | |
"title": "All Quiet on the Western Front" | |
} | |
], | |
"reading": [ | |
{ | |
"author": "J. J. Abrams", | |
"title": "S" | |
}, | |
{ | |
"author": "Luciano Ramalho", | |
"title": "Fluent Python" | |
} | |
], | |
"bought": [ | |
{ | |
"author": "Junot Díaz", | |
"title": "This Is How You Lose Her" | |
}, | |
{ | |
"author": "Ernest Cline", | |
"title": "Ready Player One" | |
}, | |
{ | |
"author": "Ernest Cline", | |
"title": "Armada" | |
}, | |
{ | |
"author": "Harper Lee", | |
"title": "Go Set a Watchman" | |
}, | |
{ | |
"author": "Raymond Chandler", | |
"title": "The Little Sister" | |
}, | |
{ | |
"author": "Azar Nafisi", | |
"title": "Reading Lolita in Tehran" | |
}, | |
{ | |
"author": "Mario Vargas Llosa", | |
"title": "The War of the End of the World" | |
} | |
] | |
}, | |
"june": { | |
"read": [ | |
{ | |
"author": "Jim Whitehurst", | |
"title": "The Open Organization" | |
}, | |
{ | |
"author": "Flannery O'Connor", | |
"title": "Wise Blood" | |
} | |
], | |
"reading": [ | |
{ | |
"author": "Ray Bradbury", | |
"title": "The October Country" | |
}, | |
{ | |
"author": "J. J. Abrams", | |
"title": "S" | |
}, | |
{ | |
"author": "Arthur Conan Doyle", | |
"title": "The Memoirs of Sherlock Holmes" | |
}, | |
{ | |
"author": "Luciano Ramalho", | |
"title": "Fluent Python" | |
}, | |
{ | |
"author": "Neal Stephenson", | |
"title": "Cryptonomicon" | |
} | |
], | |
"gift": [ | |
{ | |
"author": "John Cheever", | |
"title": "John Cheever\\: Complete Novels" | |
}, | |
{ | |
"author": "Jorge Amado", | |
"title": "Capitães da Areia" | |
}, | |
{ | |
"author": "Jorge Amado", | |
"title": "Tenda dos Milagres" | |
}, | |
{ | |
"author": "Jorge Amado", | |
"title": "Cacau" | |
}, | |
{ | |
"author": "Jorge Amado", | |
"title": "A Morte e a Morte de Quincas Berro Dágua" | |
}, | |
{ | |
"author": "Graciliano Ramod", | |
"title": "Vidas Secas" | |
}, | |
{ | |
"author": "Howard Mittelmark", | |
"title": "Read This Next\\: 500 of the Best Books You'll Ever Read" | |
}, | |
{ | |
"author": "John Steinbeck", | |
"title": "The Short Stories of John Steinbeck" | |
}, | |
{ | |
"author": "Ray Bradbury", | |
"title": "The October Contry" | |
}, | |
{ | |
"author": "Henry David Thoreau", | |
"title": "Walden" | |
}, | |
{ | |
"author": "Isaac Asimov", | |
"title": "The Foundation Trilogy" | |
}, | |
{ | |
"author": "Edgar Rice Burroughs", | |
"title": "John Carter of Mars" | |
}, | |
{ | |
"author": "Michael Kelahan", | |
"title": "Classic American Short Stories" | |
}, | |
{ | |
"author": "Ray Bradbury", | |
"title": "The Martian Chronicles/The Illustrated Man/The Golden Apples of the Sun" | |
} | |
], | |
"bought": [ | |
{ | |
"author": "Robert M. Pirsig", | |
"title": "Zen and the Art of Motorcycle Maintenance\\: An Inquiry Into Values" | |
}, | |
{ | |
"author": "Fyodor Dostoyevsky", | |
"title": "The Possessed" | |
}, | |
{ | |
"author": "Fyodor Dostoyevsky", | |
"title": "Notes From Underground" | |
}, | |
{ | |
"author": "Camus", | |
"title": "The Fall" | |
}, | |
{ | |
"author": "Herman Melville", | |
"title": "Great Short Works of Herman Melville" | |
}, | |
{ | |
"author": "Anton Chekhov", | |
"title": "The Portable Chekhov" | |
}, | |
{ | |
"author": "Nick Hornby", | |
"title": "Slam" | |
}, | |
{ | |
"author": "Sophocles", | |
"title": "Sophocles I\\: Oedipus the King, Oedipus at Colonus, Antigone" | |
}, | |
{ | |
"author": "Machado de Assis", | |
"title": "Dom Casmurro" | |
}, | |
{ | |
"author": "Jack London", | |
"title": "Novels and Stories\\: Call of the Wild / White Fang / The Sea-Wolf / Klondike and Other Stories" | |
}, | |
{ | |
"author": "Marcel Proust", | |
"title": "The Complete Short Stories of Marcel Proust" | |
} | |
] | |
}, | |
"may": { | |
"read": [ | |
{ | |
"author": "Mikhail Bulgakov", | |
"title": "The Master and Margarita" | |
}, | |
{ | |
"author": "Bill Green", | |
"title": "I'm a Lebowski, You're a Lebowski\\: Life, The Big Lebowski, and What Have You" | |
}, | |
{ | |
"author": "Pamela Paul", | |
"title": "By The Book\\: Writers on Literature and the Literary Life from The New York Times Book Review" | |
}, | |
{ | |
"author": "Dave Hoover", | |
"title": "Apprenticeship Patterns\\: Guidance for the Aspiring Software Craftsman" | |
}, | |
{ | |
"author": "Junot Díaz", | |
"title": "The Brief Wondrous Life of Oscar Wao" | |
} | |
], | |
"reading": [ | |
{ | |
"author": "Arthur Conan Doyle", | |
"title": "The Memoirs of Sherlock Holmes" | |
}, | |
{ | |
"author": "Neal Stephenson", | |
"title": "Cryptonomicon" | |
}, | |
{ | |
"author": "Luciano Ramalho", | |
"title": "Fluent Python" | |
} | |
], | |
"bought": [ | |
{ | |
"author": "Gabriel Garcia Márquez", | |
"title": "Love in the Time of Cholera" | |
}, | |
{ | |
"author": "Gabriel Garcia Márquez", | |
"title": "Memories of my Melancholy Whores" | |
}, | |
{ | |
"author": "John Updike", | |
"title": "Rabbit at Rest" | |
} | |
] | |
}, | |
"april": { | |
"read": [ | |
{ | |
"author": "Robert A. Heinlein", | |
"title": "Stranger in a Strange Land" | |
}, | |
{ | |
"author": "Nick Hornby", | |
"title": "More Baths, Less Talking" | |
}, | |
{ | |
"author": "Steve Martin", | |
"title": "Shopgirl" | |
}, | |
{ | |
"author": "O. Henry", | |
"title": "Heart of the West" | |
}, | |
{ | |
"author": "Clifford D. Simak", | |
"title": "City" | |
}, | |
{ | |
"author": "Pearl S. Buck", | |
"title": "The Good Earth" | |
}, | |
{ | |
"author": "Neil Gaiman", | |
"title": "Trigger Warning\\: Short Fictions and Disturbances" | |
} | |
], | |
"reading": [ | |
{ | |
"author": "Pamela Paul", | |
"title": "By The Book\\: Writers on Literature and the Literary Life from The New York Times Book Review" | |
}, | |
{ | |
"author": "Dave Hoover", | |
"title": "Apprenticeship Patterns\\: Guidance for the Aspiring Software Craftsman" | |
}, | |
{ | |
"author": "Nick Hornby", | |
"title": "Ten Years in the Tub\\: A Decade Soaking in Great Books" | |
} | |
], | |
"gift": [ | |
{ | |
"author": "Flann O'Brien", | |
"title": "The Third Policeman" | |
}, | |
{ | |
"author": "Phillip K. Dick", | |
"title": "The Man in the High Castle" | |
} | |
], | |
"bought": [ | |
{ | |
"author": "Sydney Padula", | |
"title": "The Thrilling Adventures of Lovelace and Babbage\\: The (Mostly) True Story of the First Computer" | |
}, | |
{ | |
"author": "Arthur Conan Doyle", | |
"title": "The Horror of the Heights and Other Tales of Suspense" | |
}, | |
{ | |
"author": "John Williams", | |
"title": "Stoner" | |
}, | |
{ | |
"author": "Nikolai Gogol", | |
"title": "Taras Bulba" | |
}, | |
{ | |
"author": "Elizabeth Gaskell", | |
"title": "Gothic Tales" | |
}, | |
{ | |
"author": "F. Scott Fitzgerald", | |
"title": "The Great Gatsby" | |
}, | |
{ | |
"author": "F. Scott Fitzgerald", | |
"title": "This Side of Paradise" | |
}, | |
{ | |
"author": "F. Scott Fitzgerald", | |
"title": "The Last Tycoon" | |
}, | |
{ | |
"author": "F. Scott Fitzgerald", | |
"title": "Tender Is the Night" | |
}, | |
{ | |
"author": "F. Scott Fitzgerald", | |
"title": "The Beautiful and Damned" | |
}, | |
{ | |
"author": "Alexandr Sergeyevitch Pushkin", | |
"title": "The Complete Prose Tales of Alexandr Sergeyevitch Pushkin" | |
}, | |
{ | |
"author": "Ernest Hemingway", | |
"title": "To Have and Have Not" | |
}, | |
{ | |
"author": "Anton Chekhov", | |
"title": "The Portable Chekhov" | |
}, | |
{ | |
"author": "Ray Bradbury", | |
"title": "Long After Midnight" | |
}, | |
{ | |
"author": "Pearl S. Buck", | |
"title": "The Good Earth" | |
}, | |
{ | |
"author": "Jackson J. Benson", | |
"title": "The Short Novels of John Steinbeck" | |
}, | |
{ | |
"author": "Charlotte Bront\\u00eb", | |
"title": "Jane Eyre" | |
}, | |
{ | |
"author": "Maya Angelou", | |
"title": "I Know Why the Caged Bird Sings" | |
}, | |
{ | |
"author": "John Steinbeck", | |
"title": "Journal of a Novel" | |
}, | |
{ | |
"author": "Christopher Morley", | |
"title": "The Haunted Bookshop" | |
}, | |
{ | |
"author": "Ernest Hemingway", | |
"title": "The Garden of Eden" | |
}, | |
{ | |
"author": "George Orwell", | |
"title": "Animal Farm" | |
}, | |
{ | |
"author": "Flannery O'Connor", | |
"title": "Everything That Rises Must Converge" | |
}, | |
{ | |
"author": "Ernest Hemingway", | |
"title": "The Short Stories of Ernest Hemingway" | |
}, | |
{ | |
"author": "Jorge Luis Borge", | |
"title": "Labyrinths" | |
}, | |
{ | |
"author": "O. Henry", | |
"title": "Collected Stories" | |
}, | |
{ | |
"author": "Herman Melville", | |
"title": "Billy Budd and Other Stories" | |
}, | |
{ | |
"author": "Robert Galbraith", | |
"title": "The Cuckoo's Calling" | |
} | |
] | |
} | |
} | |
} |
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
import json | |
import sys | |
from datetime import datetime | |
GOODREADS_URL = u'https://www.goodreads.com/search?utf8=%E2%9C%93&query={0}' | |
picture = """ | |
.. figure:: https://omaciel.fedorapeople.org/book_review.png | |
:alt: Books - {0} | |
:align: left | |
:figwidth: 40 % | |
""" | |
def read_json(filename): | |
""" Reads a JSON file and returns it.""" | |
with open(filename, 'r+') as infile: | |
return json.load(infile) | |
def generate_report(year, month, filename): | |
# Today is | |
today = datetime.today() | |
month_and_year = u"{0} {1}".format(month.title(), year) | |
# Grab the data file | |
all_books = read_json(filename) | |
# Books for the month | |
month_books = all_books[year][month] | |
all_authors = list( | |
set([book['author'] | |
for section in month_books.values() | |
for book in section])) | |
all_titles = list( | |
set([book['title'] | |
for section in month_books.values() | |
for book in section])) | |
# Print the header | |
title = u"Books - {0}".format(month_and_year) | |
print title | |
print u"#" * len(title) | |
print u":date: {0}".format(today.strftime("%Y-%m-%d")) | |
print u":authors: Og Maciel" | |
print u":category:" | |
print u":tags: {0}".format(", ".join(author for author in all_authors)) | |
print u":description:" | |
print picture.format(month_and_year) | |
for section, books in month_books.items(): | |
print section.title() | |
print '-' * len(section) | |
books.sort() | |
for book in books: | |
print u'* `{0}`_ by `{1}`_'.format(book['title'], book['author']) | |
# Add book author and title to links lists | |
if book['author'] not in all_authors: | |
all_authors.append(book['author']) | |
if book['title'] not in all_titles: | |
all_titles.append(book['title']) | |
# Sort links lists | |
all_authors.sort() | |
all_titles.sort() | |
print '.. Author Links' | |
for author in all_authors: | |
url = GOODREADS_URL.format(author.replace(' ', '+')) | |
print u'.. _{0}: {1}'.format(author, url) | |
print '.. Books Links' | |
for book in all_titles: | |
url = GOODREADS_URL.format(book.replace(' ', '+')) | |
print u'.. _{0}: {1}'.format(book, url) | |
if __name__ == "__main__": | |
generate_report(sys.argv[1], sys.argv[2], 'books.json') |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment