I was bored, looking for something to read, then I have:
I wrote a script rndeat.py, using python-recipes for accessing ActiveState Code and Pygments (optional) for syntax highlighting, to randomly pick one recipe:
You can query with one programming language and/or tags to get a random recipe. Here is the help of this simple script:
If you don't have Pygments, you can use
Some are really fun to read, some are bored and too long, some are even older than your son or daughter (dated back to 2001, as far as I can see).
I am thinking a
Disclaimer: This code is licensed under the MIT License, I am not responsible to anything that this code can cause, including, but not limited to, any health issues, such as obesity, food poisoning, etc.
I wrote a script rndeat.py, using python-recipes for accessing ActiveState Code and Pygments (optional) for syntax highlighting, to randomly pick one recipe:
You can query with one programming language and/or tags to get a random recipe. Here is the help of this simple script:
$ ./rndeat.py -h usage: rndeat.py [-h] [-l LANG] [-t [TAG [TAG ...]]] [-s STYLE] Random eats. optional arguments: -h, --help show this help message and exit -l LANG, --lang LANG show recipe in the language (default: python) -t [TAG [TAG ...]], --tags [TAG [TAG ...]] show recipe with tags -s STYLE, --style STYLE highlighting style, "list" to get a list of styles (default: default)It ridiculously uses 3 API calls in order to get a random recipe, although it could possibly reduce to 1 API in a long run if adding caching in this script. The Python recipes only have a few thousands, there might be somewhere you can download entire recipe database. But, it might just like the API, I can't find any documentation about it except this python-recipes, basically it's been two years without new commits.
If you don't have Pygments, you can use
sed
to extract the code by looking for code +:
and use your favorite highlighter, even load into Vim. Well, or just hack the script, that would be quicker.Some are really fun to read, some are bored and too long, some are even older than your son or daughter (dated back to 2001, as far as I can see).
I am thinking a
-i
for interactive mode, so it can cache data in memory and allows you to bring up Python interpreter with the script if possible. It might be easier and fun to play with the recipe.Disclaimer: This code is licensed under the MIT License, I am not responsible to anything that this code can cause, including, but not limited to, any health issues, such as obesity, food poisoning, etc.
I don't see a point in "random" recipe, even if I'm terribly bored. Plus you could have made your code w/o using additional package as using activestate API for your example is just trivial url request which returns json response.
ReplyDeleteProblem with the API is that you can't query recipes, but can only use known tags for searching. Solution for this problem is more likely candidate for boring time. But not in the way activestate solved it - by using custom Google search, as that is just bloated approach, from Python perspective, at least (and mine too).
Cheers
It's clearly you will never be as bored as I could be.
ReplyDeleteYes, I could have written my own code to access. The problem is there is no documentation about ActiveState Recipes API. The existing library is only reliable source and that makes no sense to write your own when you are reading some finished code.
By the way, it's better to keep distance off Google Search unless you scrape. The Google's Web Search API is deprecated and will be retired next year if I recall correctly. I think there is already a paid version like Bing.
Yes, Bing was what I had in mind. Bing offers free json/xml API but
ReplyDeletelimited to number of requests of course, and per API key, not per IP
unfortunately, but that's like enough for single user.
OTOH
using regular Bing query from Python is not so bad also, as they
respond with valid XHTML, so you won't have to load HTML DOM, but parse
fast XML.
Only use I found in activestate API was request recipe
by number and get json with recipe description. That's by reading
recipesapi.py from the package you used, as I also couldn't find any
information about the API from activestate.
I think Google also provides free quota, but probably not much, can't really remember the exactly amount. I think Bing provides about free 1K or 10K request quota, can remember, either. I have been using the new Bing API since this March.
ReplyDeleteIt's so strange to me, ActiveState is a place for coding, I guess they don't want people to use API anymore since that library I used was written by ActiveState, if I recall correctly.
It must be that, as I can't believe that there are technical limitation which won't allow common API features. Also Google offers them all kind of statistics w/o bothering too much. Could be else, I'm just guessing
ReplyDelete