Created
March 8, 2012 15:14
-
-
Save evz/2001451 to your computer and use it in GitHub Desktop.
Making search possible on a static site -- AppEngine app
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
application: static-eric-search | |
version: 1 | |
runtime: python27 | |
api_version: 1 | |
threadsafe: true | |
handlers: | |
- url: .* | |
script: main.app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function($){ | |
$('#searchsubmit').live('click', function(){ | |
$('.result').remove(); | |
$.getJSON('http://static-eric-search.appspot.com/?query='+$(this).prev().val()+'&callback=?', function(data){ | |
var info = ''; | |
if (data['status'] == 'ok'){ | |
$.each(data['resp'], function(key,val){ | |
info += '<div><h4><a href="#">' + val['title'] + '</a></h4>'; | |
info += '<p><em>Updated: ' + val['updated'] + '</em></p>'; | |
info += '<div style="display:none;"><p>' + val['summary'] + '</p></div></div>' | |
}); | |
} else { | |
info += '<div class"result"><h4>Your search found nothing. Try again</h4></div>'; | |
} | |
$('#search-results').append(info); | |
}); | |
}); | |
$('.result h4 a').live('click', function(){ | |
$(this).parent().parent().find('.result-summary').toggle('blind'); | |
}); | |
})(jQuery); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import logging | |
import json | |
import webapp2 as webapp | |
from feedparser import parse | |
class SearchSite(webapp.RequestHandler): | |
def get(self): | |
q = self.request.get('query', '') | |
cb = self.request.get('callback', '') | |
tree = parse('http://feeds.feedburner.com/static-eric') | |
d = {} | |
resp = [] | |
for entry in tree['entries']: | |
if q.lower() in entry['content'][0]['value'].lower(): | |
props = {} | |
props['title'] = entry['title'] | |
props['updated'] = entry['updated'] | |
props['summary'] = entry['summary'] | |
props['link'] = entry['links'][0]['href'] | |
resp.append(props) | |
d['status'] = 'ok' | |
else: | |
d['status'] = 'no_results' | |
d['resp'] = resp | |
d = json.dumps(d) | |
d = "%s(%s)" % (cb,str(d)) | |
self.response.out.write(d) | |
app = webapp.WSGIApplication([('/', SearchSite)], debug=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment