0

I wrote the code.

But I don't think it's going to work.

I want to extract words from the concept of " or " rather than the concept of " and ".

It seems like only ' keyword 1 ' is extracted.

How do I make corrections?

import tweepy
import time
import os

search_term = 'keyword1'
search_term2= 'keyword2'

lat = "37.6"
lon = "127.0"
radius = "200km"
location = "%s,%s,%s" % (lat, lon, radius)


API_key = "11111"
API_secret = "22222"
Access_token = "33333"
Access_token_secret = "444"


auth = tweepy.OAuthHandler(API_key, API_secret)
auth.set_access_token(Access_token, Access_token_secret)

api = tweepy.API(auth)

c=tweepy.Cursor(api.search,
            q=(search_term or search_term2),
            rpp=1000,
            geocode=location,
            include_entities=True)

data = {}
i = 1
for tweet in c.items():
    data['text'] = tweet.text
    print(i, ":", data)
    i += 1
time.sleep(1)


wfile = open(os.getcwd()+"/twtw2.txt", mode='w')   
data = {}   
i = 0       

for tweet in c.items():
    data['text'] = tweet.text   
    wfile.write(data['text']+'\n')  
    i += 1
    time.sleep(1)

wfile.close()
1
  • 4
    It's not clear what exactly you're asking. Also, you shouldn't include your secrets and tokens in code you post publicly.
    – jonrsharpe
    Commented Apr 16, 2017 at 14:27

1 Answer 1

0

Maybe change this line

q=(search_term or search_term2),

to

q="{}+OR+{}".format(search_term,search_term2),
  • Case matters here for the OR operator
  • enter q as a string, not as an expression that is short-circuit evaluated

By the way, your credentials (from your post) also work for me.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.