From 8e951f6b27fd28bd3e0daed27a6c37eb357f86bc Mon Sep 17 00:00:00 2001 From: Sven Slootweg Date: Wed, 30 Jan 2013 13:28:21 +0100 Subject: [PATCH] Add simple script for searching from a terminal --- shellsearch/search.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 shellsearch/search.py diff --git a/shellsearch/search.py b/shellsearch/search.py new file mode 100644 index 0000000..ea6e856 --- /dev/null +++ b/shellsearch/search.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python + +import requests, sys, re + +query = sys.argv[1] + +results = requests.post("http://learn.cryto.net/api/search", {"q": query}).json() + +for result in results: + name = result["title"].rstrip() + description = result["description"].strip().replace("\n", " ") + + if len(description) > 200: + description = re.match("^(.{0,300})\W", description).group(1) + "..." + + print "## %s\n%s" % (name, description) + + for item in result["items"]: + name = item["title"].ljust(70) + print "\t[%s] %s\t%s" % (item["type"], name, item["url"]) + + print ""