Permalink
Browse files

dplasearch page now allows for user input of search terms

  • Loading branch information...
1 parent 5d763fe commit 954df423edb7e8dfe3787465e64655b617d59073 @thatandromeda committed Apr 5, 2012
Showing with 93 additions and 60 deletions.
  1. +5 −3 README.md
  2. +61 −57 dpla_timeline.py
  3. BIN dpla_timeline.pyc
  4. +27 −0 dplasearch.py
View
@@ -7,11 +7,13 @@ Done
+ clean up json quirks so Timeline can read the result
+ output Timeline-formatted json (including hardcoded start date)
+ HTML page
++ allow for user input of search terms
Todo
----
-+ figure out why query isn't returning what it should
-+ allow for user input of search terms
+ better handling of dates (e.g. when the standard date field returns only a year, or something spurioius, do I want to harvest source-specific data?)
+ generate a logical start date
-+ figure out a way of dealing with annoying NPR embeds spawning iTunes a million times (suppress, replace with better multimedia, etc.)
++ figure out a way of dealing with annoying NPR embeds spawning iTunes a million times (suppress, replace with better multimedia, etc.)
++ get better embeds from biodiversity library
++ deal with NaN dates
++ redirect from user input page to timeline page; how does cherrypy find that page?
View
118 dpla_timeline.py 100644 → 100755
@@ -1,62 +1,66 @@
+#!/usr/bin/python
import urllib2
import json
-query = "penguins"
-limit = 20
-
-url = ''.join([
- 'http://api.dp.la/dev/item/?search_type=keyword',
- '&query=%s' % query,
- '&limit=%s' % limit,
- ])
-jsondata = urllib2.urlopen(url).read()
-pydata = json.loads(jsondata)
-
-datalist = []
-start = '2000'
-
-f = open('your_data.json', 'w')
-
-opening_data = '{"timeline":{"headline":"DPLA Search Timeline","type":"default","startDate":"%s","text":"Hello, World.","date":' % start
-f.write(opening_data)
-
-for item in pydata['docs']:
- if 'date' in item:
- startDate = item['date']
- if '>' in startDate:
- startDate = "2013"
- else:
- startDate = ''
- if 'title' in item:
- headline = item['title'].replace('"','"')
- else:
- headline = ''
- if 'description' in item:
- text = item['description'][0].replace('"','"')
- else:
- text = ''
- if 'content_link' in item:
- media = item['content_link'][0]
- else:
- media = ''
- if 'data_source' in item:
- credit = item['data_source']
- else:
- credit = ''
-
- output = {}
- asset = {}
- output['startDate'] = startDate
- output['headline'] = headline
- output['text'] = text
- asset['media'] = media
- asset['credit'] = credit
- asset['caption'] = ''
- output['asset'] = asset
+def timeline(query):
+ limit = 20
- datalist.append(output)
+ url = ''.join([
+ 'http://api.dp.la/dev/item/?search_type=keyword',
+ '&query=%s' % query,
+ '&limit=%s' % limit,
+ ])
+ jsondata = urllib2.urlopen(url).read()
+ pydata = json.loads(jsondata)
-datalist = json.dumps(datalist)
-f.write(datalist)
-f.write('}}')
-f.close()
+ datalist = []
+ start = '2000'
+
+ f = open('your_data.json', 'w')
+
+ opening_data = '{"timeline":{"headline":"DPLA Search Timeline","type":"default","startDate":"%s","text":"Hello, World.","date":' % start
+ f.write(opening_data)
+
+ for item in pydata['docs']:
+ if 'date' in item:
+ startDate = item['date']
+ if '>' in startDate:
+ startDate = "2013"
+ else:
+ startDate = ''
+ if 'title' in item:
+ headline = item['title'].replace('"','"')
+ else:
+ headline = ''
+ if 'description' in item:
+ text = item['description'][0].replace('"','"')
+ else:
+ text = ''
+ if 'content_link' in item:
+ media = item['content_link'][0]
+ else:
+ media = ''
+ if 'data_source' in item:
+ credit = item['data_source']
+ else:
+ credit = ''
+
+ output = {}
+ asset = {}
+ output['startDate'] = startDate
+ output['headline'] = headline
+ output['text'] = text
+ asset['media'] = media
+ asset['credit'] = credit
+ asset['caption'] = ''
+ output['asset'] = asset
+
+ datalist.append(output)
+
+ datalist = json.dumps(datalist)
+ f.write(datalist)
+ f.write('}}')
+ f.close()
+
+if __name__=="__main__":
+ timeline()
View
Binary file not shown.
View
@@ -0,0 +1,27 @@
+import cherrypy
+from dpla_timeline import timeline
+
+class HelloWorld(object):
+ def index(self):
+ return """
+ <html>
+ <head>
+ </head>
+ <body>
+ hello world<br /><br />yup
+ <form action="getParam" method="post">
+ <input type='text' name='param' />
+ <input type='submit' value='Timeline it!' />
+ </form>
+ </body>
+ </html>
+ """
+ index.exposed = True
+
+ def getParam(self, param):
+ timeline(param)
+ return True
+
+ getParam.exposed = True
+
+cherrypy.quickstart(HelloWorld())

0 comments on commit 954df42

Please sign in to comment.