Random Taco Wednesday with Random Deadpool
New comics come out every Wednesday. I found an API for taco recipes. Deadpool loves tacos. Marvel has an API. The only logical thing to do was create a page that will give a Deadpool comic and a taco recipe. Here it is: http://antonioortegajr.com/marvel/tacosanddeadpool/deadpooltacowednesday.php
To create this page I started with a call to the Marvel API. You can find a sample of that here: http://antonioortegajr.com/marvel-api-is-fun/ the returned json is the variable $data
$data = curl_exec($ch);
and stored in a SomeName.txt file in the same folder using file_put_contents()
I use rand() to add the randomness to the Deadpool issue shown. This is also stored in a .txt file and referenced when echoing values from the json array.
For the tacos it’s pretty much the exact same call as the Marvel call. No API keys needed as I am just hitting an endpoint that randomizes the taco recipies: http://taco-randomizer.herokuapp.com/ this is forked form the API called tacofancy. Here is is at GitHub: https://github.com/sinker/tacofancy The project says they have over a hundred recipes and growing.
With both API calls made and the output stored in .txt files I call the Deadpool fun and taco goodness with file_get_contents() and a json_decode() for the contents stored in the .txt file. Like this for the tacos part:
$tacos = json_decode(file_get_contents(‘tacos.txt’), true);
Echo with a scoop of html to create a page, add a bit of CSS to add some styling and then serve up the goodness from each. The variable $tacos is the json we stored earlier and the key[url] gives me the link to the recipe from the array.
echo ‘<div id=”yuum”>’ . $tacos[url] . </div>;
The files to check the two APIs are set on cron jobs in my hosting. Updating once a week. Wednesdays at 10am.
This is still a work in progress. I will add a .zip file with the source and a ton of over explaining notes if anyone is interested.
What about Wednesday? I only grab a new comic and taco recipe each Wednesday so I don’t blow up on API calls. More important than anything, I think Deadpool would approve.