I have used LongURL a few times because referrers in Blogger Stats, just to make sure the URL would be fine to click on. I felt it’s time to wrap up a script, so, the lu.sh:
$ lu.sh http://t.co/eHkavAoT2N
{
"title": "Downloading only when modified using cURL in Bash",
"all-redirects": [
"https://yjlv.blogspot.com/2012/03/downloading-only-when-modified-using.html"
],
"long-url": "https://yjlv.blogspot.com/2012/03/downloading-only-when-modified-using.html"
}
Before I started the coding, I didn’t know LongURL is actually open sourced until I read its API documentation page. Happy to see that and the API is quite easy to use. It didn’t take me long to code, if that’s coding at all. The script just dumps the output as I see no reason to format it if jq isn’t available on the system.
About a week ago, I learned about jq and now I used it to format the output, although it’s not a required dependency. Anyway, I also learned how to join array into string like ",".join(list) in Python, but this would look quite awkward:
jq '[["BEGIN"], [.[].key + "SEP"][:-1], [.[].key][-1:], ["END"]] | add | add'
There probably is a better way to do it. I used it to form a regular expression, which is used to pre-check the input URL against the known services before sending a request via API.
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.