You would still need to update the twarc package - both the command line tool and using twarc as a library use the package version - these two commands, should show the same version, v2.1.1
It appears you have a slightly older version - 2.0.13 to upgrade run:
pip install --upgrade twarc
then check:
pip show twarc
should show:
Name: twarc
Version: 2.1.1
...
twarc2 version
should show:
twarc v2.1.1
The reason why there is no output file is that the code you’re running does not save any files - it prints tweets to output. Also you are requesting only 10 results per call, which is ok for a test but not optimal, so you will use a lot of calls to cover the time range (which is all of twitter’s history currently, as the dates are)
This is a more optimal code snippet that should work for you:
import datetime
import itertools
import json
from twarc.client2 import Twarc2
from twarc.expansions import flatten
# Your bearer token here
t = Twarc2(bearer_token="AAA...zzz")
# Start and end times must be in UTC
start_time = datetime.datetime(2006, 3, 21, 0, 0, 0, 0, datetime.timezone.utc)
end_time = datetime.datetime(2021, 4, 27, 0, 0, 0, 0, datetime.timezone.utc)
query = "tatemodern lang:en -is:retweet"
# search_results is a generator, max_results is max tweets per page, 500 max for full archive search.
search_results = t.search_all(query=query, start_time=start_time,
end_time=end_time, max_results=500)
# Write all results to `results.jsonl`, one response per line:
for page in search_results:
with open("results.jsonl", "a", encoding="utf8") as json_file:
json.dump(page, json_file)
json_file.write("\n")
This will write a file results.jsonl that you can later process to extract whatever you need.