def mainpage(): zeitgeist = dict() clist = candidates.keys() for c in clist: print("Scrapin' %s" % c) (results, alltext, alltagstext) = getTweets(c) sentiment = allSentiments([r.text for r in results]) zeitgeist[c] = (results, alltext, alltagstext, sentiment) page = "<html><head>" page += """<link href='http://fonts.googleapis.com/css?family=Open+Sans +Condensed:700,300&subset=latin,latin-ext' rel='stylesheet' type='text/css'>""" page += """<style type="text/css">""" page += style_info page += "</style>" page += "</head><body>" page += performAnalysis() for c in clist: print("Renderin' %s" % c) (results, alltext, alltagstext, sentiment) = zeitgeist[c] page += "<h1>%s</h1><br>" % c page += "Candidate sentiment: %s<br>" % sentiment page += getSentimentTweets(api, c) page += "<br>" page += "<h1>Word cloud:</h1>" page += wordle_applet.format(text=alltext) page += "<h1>Tag cloud:</h1>" page += wordle_applet.format(text=alltagstext) page += "<br>" page += "</body></html>" return page
def searchresults(): query = request.form['query'] (results, alltext, alltagstext) = getTweets(query) page = "" page += "<h1>Search: %s</h1>" % query page += "<h1>Word cloud:</h1>" page += wordle_applet.format(text=alltext) page += "<h1>Tag cloud:</h1>" page += wordle_applet.format(text=alltagstext) page += "<br><h1>Sentiment analysis</h1>" return page