Interesting question.

I would have to think about your larger question, but the smaller issue, is 
that you need to close the crsr and you need to commit, 
I would think that you would not want to make commit automatic, so that 
your code has a chance to do some error checking and perhaps roll back.



On Tuesday, March 27, 2012 3:59:28 AM UTC-4, coded kid wrote:
>
> Hi guys, I’m confused on how to make this work. I want to stream 
> user’s tweets in my django app using tweepy. I’ve written the 
> streaming code but the problem I’m facing is: should I paste the code 
> in views.py and input- return 
> render_to_response('tweet.html',context_instance=RequestContext(request)) 
> after writing the code. Just like this: 
>
>
> Q= sys.argv[1:] 
>
> db=MySQLdb.connect("localhost","","","Juzme") 
>
> auth=tweepy.OAuthHandler(consumer_key, consumer_secret) 
> auth.set_access_token(access_token, access_token_secret) 
>
> cur=db.cursor() 
>
> class CustomStreamListener(tweepy.StreamListener): 
>     def on_status(self, status): 
>         try: 
>             print "%s\t%s\t%s\t%s" % (status.text, 
>                                       status.author.screen_name, 
>                                       status.created_at, 
>                                       status.source,) 
>             cur.execute("INSERT INTO tweets VALUES (%s, %s, %s, %s)", 
> (status.text, 
>   
> status.author.screen_name, 
>   
> status.created_at, 
>   
> status.source)) 
>         except Exception, e: 
>             print >> sys.stderr, 'Encountered Exception:', e 
>             pass 
>     def on_error(self, status_code): 
>         print >> sys.stderr, 'Encountered error with status code:', 
> status_code 
>         return True 
>     def on_timeout(self): 
>         print >> sys.stderr, 'Timeout...' 
>         return True 
> streaming_api=tweepy.streaming.Stream(auth, CustomStreamListener(), 
> timeout=60) 
> print >> sys.stderr, 'Filtering the public timeline for "%s"' % (' 
> '.join(sys.argv[1:]),) 
> streaming_api.filter(follow=[], track=Q) 
> return 
> render_to_response('tweet.html',context_instance=RequestContext(request)) 
>
> If I can do it like this, won’t there be any code in template? Or 
> what’s the best way I can carry out this operation. I hope you get my 
> point? Thanks! 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/ayxpyVfTYB4J.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to