Trying to capture data from twitter feeds

By : glls
Source: Stackoverflow.com
Question!

When running my server i get the following error

ValueError at /
The view hashtrack.views.index didn't return an HttpResponse object. It returned None instead.
Request Method: GET
Request URL:    http://127.0.0.1:8000/
Django Version: 1.8.2
Exception Type: ValueError
Exception Value:    
The view hashtrack.views.index didn't return an HttpResponse object. It returned None instead.
Exception Location: C:\Python34\lib\site-packages\django\core\handlers\base.py in get_response, line 151
Python Executable:  C:\Python34\python.exe
Python Version: 3.4.3
Python Path:    
['C:\\Users\\torjeli\\tweesh',
 'C:\\Python34\\lib\\site-packages\\setuptools-15.2-py3.4.egg',
 'C:\\Python34\\lib\\site-packages\\distribute-0.6.49-py3.4.egg',
 'C:\\Python34\\lib\\site-packages\\cython-0.22-py3.4-win32.egg',
 'C:\\Python34\\lib\\site-packages\\scrapy-0.24.6-py3.4.egg',
 'C:\\Python34\\lib\\site-packages\\six-1.9.0-py3.4.egg',
 'C:\\Python34\\lib\\site-packages\\cssselect-0.9.1-py3.4.egg',
 'C:\\Python34\\lib\\site-packages\\pyopenssl-0.15.1-py3.4.egg',
 'C:\\Windows\\system32\\python34.zip',
 'C:\\Python34\\DLLs',
 'C:\\Python34\\lib',
 'C:\\Python34',
 'C:\\Python34\\lib\\site-packages',
 'C:\\Python34\\lib\\site-packages\\win32',
 'C:\\Python34\\lib\\site-packages\\win32\\lib',
 'C:\\Python34\\lib\\site-packages\\Pythonwin']
Server time:    Sun, 31 May 2015 18:59:22 -0400

I have tried running the script on the background of the page but i get the same error code, the hashtags do get printed in the console window, I'm trying to get the tweets into csv file to later use the data.

from django.shortcuts import render_to_response
from django.http import HttpResponse
from tweepy import *


CKey = 'xxxxx'           #API Key
ConSec = 'xxxxx'         #Consumer Secret
AccTok = 'xxxxx'         #Access Token
AccTSec = 'xxxxx'        #Access Token Secret


class StdOutListener(StreamListener):

    def on_status(self, status):

        print(status.text)
        return True

    def on_error(self, status):

        print(status)


def index(request):
    try:
        listener = StdOutListener()
        auth = OAuthHandler(CKey, ConSec)
        auth.set_access_token(AccTok, AccTSec)
        stream = Stream(auth, listener)
        gimme = stream.filter(track=["lol"])
        return HttpResponse(gimme)

        #return render_to_response('index.html')
    except RuntimeError:
        pass
By : glls


Answers

So, I managed to capture the data on a CSV, but the page doesnt load while the process is running.... But i do get a CSV file with all the information I wanted.

from django.http import HttpResponse
from tweepy import *



CKey = 'xxxxx'           #API Key
ConSec = 'xxxxx'         #Consumer Secret
AccTok = 'xxxxx'         #Access Token
AccTSec = 'xxxxx'        #Access Token Secret


class StdOutListener(StreamListener):

def on_status(self, status):
    try:

        hashdb = open("hashtag.csv", 'a')
        hashdb.write(status.text)
        hashdb.write('\n')
        hashdb.close()
    except BaseException:
        print("could not process")
def on_error(self, status_code):
    print(status_code)
    return status_code


def index(request):

    listener = StdOutListener()
    auth = OAuthHandler(CKey, ConSec)
    auth.set_access_token(AccTok, AccTSec)
    stream = Stream(auth, listener)
    gimme = stream.filter(track=["lol"])
    html = "
By : glls


This video can help you solving your question :)
By: admin