Comments (4)
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.
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.
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.
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)
- Wrong documentation version on gh-pages HOT 1
- No includes in _RestIterable response without hydration
- lang filtering does not seem to work HOT 1
- Attempting to pull more than 10 tweets with search/tweets HOT 1
- Question: how do I acquire `screen_name` using `author_id`?? HOT 1
- DM Example not working HOT 2
- gracefully handling a stalled stream HOT 51
- Upgrade Ads API to version 10 - Deadline March 31, 2022
- Bearer Token Issue with Academic Access in Twitter API V2 HOT 1
- SUBSCRIPTION ENDPOINT NOT WORKING HOT 2
- `expansions` does not work with `author_id` HOT 2
- Twitter Ads API version 10 deprecation - End of life date September 29, 2022
- Add support for `/users/:id/bookmarks` endpoint
- Add support for OAuth2 authentication with access_tokens HOT 1
- Not able to create Webhook with Twitter HOT 2
- Request method fails to attach additional metadata HOT 2
- Authenticating error (api_version='2') HOT 8
- Can't attach media V2 HOT 2
- Publish Tweets w/ v2 HOT 3
- OP_NO_TICKET SSL Option no longer supported by Twitter HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from twitterapi.