Example of using djapp.org API

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/env python
"""
That simple script demonstrates the possibility of remote interacting with djapp.org service.
Script accepts only one argument - search string.
"""
import sys
import logging
import urllib
query = ' '.join(sys.argv[1:])
if not query:
logging.error('Usage: %s <query string>' % sys.argv[0])
sys.exit()
BASE_URL = 'http://djapp.org'
url = BASE_URL + '/api/search?query=%s' % urllib.quote(query)
resp = urllib.urlopen(url).read()
count = 0
for line in resp.splitlines():
if line.strip():
count += 1
slug, name, summary, url = line.split('||')
url = BASE_URL + url
print name
print ' %s' % summary
print ' %s' % url
print
print 'Number of results: %d' % count