GithubHelp home page GithubHelp logo

Comments (4)

geduldig avatar geduldig commented on May 19, 2024

Hi,
I have not written a Django view, so I will have to rely on your knowledge for that. I would like to help you make this work, but it's not clear to my why running your code as a view would not work while it does work as a stand-alone script. The fact that you are able to break out of the loop in the latter case would suggest that it meets your requirement of breaking out of the iterator reliably. It seems like that functionality does work as it should. Could the issue be in the Django view? If you were to replace your loop code in the view with a simple iteration, does that work reliably? For example,

count = 0
while True:
    count+=1
    if count>200: return HttpResponse("Complete")

My other thought is, are there other HTTP requests in your Django code that may conflict with the Twitter requests?

Jonas

from twitterapi.

th3o6a1d avatar th3o6a1d commented on May 19, 2024

Hey Jonas,

Thanks for your response. I suspect it may have been the latter. After re-tooling it a little, the following seems to work. It's not where I where I want it to be yet (trying to stream geocoded tweets to a map for a public health app http://github.com/th3o6a1d/suicide_watch . My version of django doesn't support streaming yet, and I'm trying to avoid an upgrade), but the issue is resolved as far as I'm concerned. If I encounter it again, I'll refer back to this post.

for tweet in stream:
            cleaned_tweet = (tweet['text'], [tweet['coordinates']['coordinates'][1], tweet['coordinates']['coordinates'][0]])
            print cleaned_tweet
            for i in wordlist:
                if cleaned_tweet[0].find(i)>0:
                    with open('redflags.json','a') as output_file:
                        json.dump(cleaned_tweet,output_file)
                    f = open('redflags.json')
                    print "ALERT ALERT ALERT"
                    return HttpResponse(f.read())
    except:
        print "PASSED"

Jason

from twitterapi.

geduldig avatar geduldig commented on May 19, 2024

Interesting project!
If the problem is streaming, I wonder if my class TwitterRestPager would help you. It makes a Twitter REST API call appear stream-like. You would use it like this:

pager = TwitterRestPager(api, 'search/tweets', {'q':'suicide', 'geocode':'37.78,-122.39,1mi'});        
for item in pager.get_iterator(wait=5, new_tweets=True):
  print(item['text'] if 'text' in item else item)

The pager downloads consecutive pages of results (default:10 tweets) with a short pause (default:5 seconds) between pages.

from twitterapi.

th3o6a1d avatar th3o6a1d commented on May 19, 2024

Thanks for the great suggestion. I'm not quite sure which will be better at this point, so I coded the rest pager into a django view. Also remade the repository as I had some issues with hiding my credentials (I'm new to this GitHub thing. So cool). http://github.com/th3o6a1d/suicide_watch. Thanks for watching my repo...stay in touch.

from twitterapi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.