def POST(self): form = web.input(search_term="Donald Trump") searchTerm = form.search_term numberTweets = form.num filename = searchTerm.replace(" ","")+".csv" #save tweets to csv file saveData(searchTerm, filename, numberTweets) #read the saved file arr = readCSV(filename) #Use Alchemy API to get sentiment and save as csv writeResult(arr, "out"+filename, searchTerm) arr, info = readData("out"+filename) #Save Graph keyword = ["Positive","Negative","Neutral"] plt.clf() ax = plt.subplot(111) y = np.arange(len(keyword)) ax.bar(y[0], info[0], color='g', align='center') ax.bar(y[1], info[1], color='r', align='center') ax.bar(y[2], info[2], color='b', align='center') #plt.bar(y, info, align='center') fig = plt.gcf() plt.xticks(y, keyword) imagePath = "static/"+filename.replace(".csv",".png") fig.savefig(imagePath) return render.index(arr = arr, imagePath=imagePath)
def POST(self): form = web.input(search_term="Donald Trump") searchTerm = form.search_term numberTweets = form.num filename = searchTerm.replace(" ", "") + ".csv" #save tweets to csv file saveData(searchTerm, filename, numberTweets) #read the saved file arr = readCSV(filename) #Use Alchemy API to get sentiment and save as csv writeResult(arr, "out" + filename, searchTerm) arr, info = readData("out" + filename) #Save Graph keyword = ["Positive", "Negative", "Neutral"] plt.clf() ax = plt.subplot(111) y = np.arange(len(keyword)) ax.bar(y[0], info[0], color='g', align='center') ax.bar(y[1], info[1], color='r', align='center') ax.bar(y[2], info[2], color='b', align='center') #plt.bar(y, info, align='center') fig = plt.gcf() plt.xticks(y, keyword) imagePath = "static/" + filename.replace(".csv", ".png") fig.savefig(imagePath) return render.index(arr=arr, imagePath=imagePath)
def index(): if request.method == 'POST': #form = web.input(search_term="Donald Trump") searchTerm = request.form['search_term'] numberTweets = request.form['num'] filename = searchTerm.replace(" ","")+".csv" #save tweets to csv file arr = saveData(searchTerm, filename, numberTweets) #Use Alchemy API to get sentiment and save as csv print "Entering writeresult" alchemyResult = threadCaller(arr, "out"+filename, searchTerm) #alchemyResult = writeResult(arr, "out"+filename, searchTerm) arr, info = getReadings(alchemyResult) print "after write result" # arr, info = readData("out"+filename) #Save Graph keyword = ["Positive","Negative","Neutral"] plt.clf() ax = plt.subplot(111) y = np.arange(len(keyword)) ax.bar(y[0], info[0], color='g', align='center') ax.bar(y[1], info[1], color='r', align='center') ax.bar(y[2], info[2], color='b', align='center') #plt.bar(y, info, align='center') fig = plt.gcf() plt.xticks(y, keyword) imagePath = "static/"+filename.replace(".csv",".png") fig.savefig(imagePath) return render_template("index.html",arr = arr, imagePath=imagePath, info=info) else: return render_template("form.html")
def get_tasks(): print "hahah" if 'name' in request.args: searchTerm = request.args['name'] numberTweets = 100 filename = searchTerm.replace(" ","")+".csv" arr = saveData(searchTerm, filename, numberTweets) print "Entering writeresult" alchemyResult = threadCaller(arr, "out"+filename, searchTerm) arr, info = getReadings(alchemyResult) print searchTerm return jsonify({'Analysis':{'Positive':info[0],'Negative':info[1],'Neutral':info[2]},'Tweets':arr}) else: return jsonify({"test":tasks})