I am a python newbie. I am learning how to use api.
I want to use TwitterAPI to get tweets including "coronavirus", but I want to know the number of those tweets. It seems that there is a limit on the number of requests and I can not get all the tweets, but specify a time between 2020-7-13_00:00:00 and 2020-7-13_00:01:00, and from there I want to calculate the number of cases, but I do not know how to specify the time.
import urllib from requests_oauthlib import OAuth1 import requests import sys def main(): # API private key CK = `` # Consumer key CKS = `` # Consumer Secret AT ='' # access token ATS = `` # access token secret # Search parameters word ='coronavirus' # search word count = 100 # number of searches per time (maximum 100/default is 15) range = 5 # Upper limit of number of searches (up to 180/15 minutes reset) # Tweet search/text extraction tweets = search_tweets(CK, CKS, AT, ATS, word, count, range) #Display search results print(tweets[0:4]) def search_tweets(CK, CKS, AT, ATS, word, count, range): # Set string word +='exclude:retweets' # except RT word = urllib.parse.quote_plus(word) # request url = "https://api.twitter.com/1.1/search/tweets.json?lang=ja&q="+word+"&count="+str(count) auth = OAuth1(CK, CKS, AT, ATS) response = requests.get(url, auth=auth) data = response.json()['statuses'] # Second and subsequent requests cnt = 0 tweets =  while True: if len(data) == 0: break cnt += 1 if cnt>range: break for tweet in data: tweets.append(tweet['text']) maxid = int(tweet["id"])-1 url = "https://api.twitter.com/1.1/search/tweets.json?lang=ja&q="+word+"&count="+str(count)+"&max_id="+str(maxid) response = requests.get(url, auth=auth) try: data = response.json()['statuses'] except KeyError: # Data error handling when the number of requests reaches the upper limit print('Searched up to limit') break return tweets if __name__ =='__main__': main()
I use the code like this.
Is there any way? Thank you.
Answer # 1
According to the answer from tweepy get tweets between two dates
APIIt seems that you can not specify the time.
According to Tweet objects
created_atSince the date and time of tweet is stored in, you need to filter by yourself based on it.
For concrete code, I think it might be useful to refer to the python script example that narrows down the unixtimestamp criteria based on the created_at time obtained with the Twitter Timeline API.
- python - i want to change the data obtained from the twitter api to a dictionary type
- python - when specifying an element in beautifulsoup, can you write it by omitting the endless continuation of previouspreviousp
- specifying the range of the graph using python date
- [python3] "crawling and scraping by specifying a link" using scrapy is not possible
- python - i want to get all tweets of a specific user with api
- how to automate tweets with images from spython with json files
- python - get the follower's screen name with the twitter api
- emoji counting using twitter api in python
- python - sumy by specifying the maximum number of characters with sumy
- i want to get twitter retweet information with python
- specifying css selector when scraping wikipedia in python
- twitter - how to automatically display tweets from multiple accounts on the site
- python - i want to import the date and time name file by specifying variables
- [python] i want to automatically update and acquire tweets posted at any time using tweepy