Muschamp Rd

Quotation Collection Mashup

September 8th, 2012
PHP logo

I’m a collector. I’m not a hoarder because I display my collections. One of the things I’ve steadily collected over the last 15 or 20 years is quotations. Not “quotes”, quotes is a verb…

These quotations were spread over journals, webpages, .sig files, and blog postings. As I had a lot of time on my hands I collected the best of the best of the best quotations into a single .csv (text) file. From this file and using quite a lot of ever more carefully written PHP I created my favourite quotation mashup.

Overdue for an Update

It is now 2019 and I haven’t been updating this PHP code. Many changes have been mad to the APIs themselves so lots of things I was able to do originally are now no longer possible. The mashup still works but a lot of the cooler features I coded no longer work. I might be able to re-implement them but open APIs are a lot less common in 2019 and my priority is getting a new job, not updating old code.

Award Winning Mashup

This bit of PHP code which is actually built on top of a lot of other PHP code which I’ve written while unemployed, recently got some minor recognition as one of the Best New Flickr Mashups. Sadly I don’t use the Flickr API all that much, it is my fall back image search API. I use Rotten Tomatoes as my first choice for movies, as my first choice for musicians, and I think Amazon Product API as my first choice for everything else. Only for a few cases does Flickr’s API get used by this mashup.

I’ve continued to add to my quotation collection, refine and refactor my PHP code, and hopefully make the collection usable and accessible for me and others. I’ve tried to make it easy to tweet, like, pin, and otherwise share the quotations if you find them amusing, informative, or otherwise interesting.

Built a WordPress Widget too

If you just want a widget to display a random quotation in the sidebar of your blog, I built that too at some point. However considering all the work I’ve now put into it, I hope someone who actually likes PHP takes my code and builds something with it, perhaps first checking it into an actual code repository. Considering some people’s obsession with all things sharing and social media, methods/functions that create fancy sharing buttons or that pull data from half a dozen different APIs and web services must be useful to someone.

It is Open Source

I’ve made pretty much all the code available and unlike some of the PHP code I’ve downloaded online it is actually documented and tested fairly well for a personal side project written by someone who is both rusty and doesn’t like coding in PHP. Perhaps someone who curses less when they code in PHP can make something better of it.

How It Works

The quotations and authors are in a text file (.csv) which I use as the input for more than just the mashup. Each line of the file has three pieces of data, the source/author of the quotation, the quotation itself, and basically a hint where the quotations comes from. Many of my quotations are from songs or films so knowing this I can look for related data from different sources online. I actually added a fourth bit of data at some point.

Everything else on the screen that isn’t part of the standard layout and navigation for is fetched from somewhere else using various APIs.

The buttons and badges below the quotations are made with PHP, though the fanciest Facebook button required a lot of work, to satisfy the full requirements of Facebook’s Open Graph. By linking to Amazon and in many cases the iTunes Store people can buy the book, movie, or possibly the album or song the quotation is from.

All the information that is fetched from an API should be cached locally. This helps with performance. Images are not cached or stored locally, I switched to smaller images at some point to decrease the load time of the page. The Amazon Product API makes you jump through a lot of hoops and recently changed their terms of service, I know as a result Goodreads stopped using it, but having invested so much time and effort into the Amazon Product API, I still rely on it a lot in my mashup codebase for things like CD and DVD covers.

The short bio comes from the Rotten Tomatoes for films, from for songs, and everything else is pulled from the Wikipedia. For movies and songs I try to find the trailer or a performance by the artist in YouTube. For long dead authors it is best not to display their most popular video, as things can get strange.

The Future

Ideally I would have gotten a new job shortly after I wrote the last CFA® exam of my life. Now I’ve passed all three but still I do not have a new job. I was focussing on learning Python but I’ve had to code a little in PHP and JavaScript to get my website and blog to run better to start the year. If I can I hope to revisit this codebase as this is the one mashup I made that I care about, but having gone through so many API policy changes I will simplify things so that it is easier to maintain. If you have thoughts on using APIs with PHP you can leave them below.

One Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Posts on Muskblog © Andrew "Muskie" McKay.
CFA Institute does not endorse, promote or warrant the accuracy or quality of Muskblog. CFA® and Chartered Financial Analyst® are registered trademarks owned by CFA Institute.