Home>

I am trying to find out what machine doctors search the Internet using machine learning. I'm thinking of using doctor tweets as learning data. Initially, tweets containing the word "doctor" were retrieved using the following code, but most of the tweets were from non-doctors.

I would like to get tweets from people whose occupations are doctors in my profile.

Reference URL
https://qiita.com/stmn/items/7cd39502ce5e8959678b

from requests_oauthlib import OAuth1Session
import csv
import json
import time
import setting

twitter = OAuth1Session (setting.CONSUMER_KEY, setting.CONSUMER_SECRET, setting.ACCESS_TOKEN, setting.ACCESS_TOKEN_SECRET)
count = 0

def get_target_ward (ward):
url ="https: //api.twitter.com/1.1/search/tweets.json"
params = {'q': ward,
'count': 100
}
req = twitter.get (url, params = params)
timeline = json.loads (req.text)
tweet_list = []
for tweet in timeline ['statuses']:
tweet_list.append (tweet ["text"])
tweet_list = list (set (tweet_list))
for (i, tweet) in enumerate (tweet_list):
print (str (i) +":"+ tweet)

return tweet_list

def write_csv (tweet_list):
with open ("mamayu_tweet"+ str (count) +".csv","w") as f:
writer = csv.writer (f, lineterminator ='\ n')
writer.writerow (tweet_list)

ifname=='main&apos ;:

all_list = []

ward ="Doctor"
while True:
tweet_list = get_target_ward (ward)
write_csv (tweet_list)
time.sleep (60)
count = count + 1