Skip to content

Commit

Permalink
Prevent stream if user has recent Twitter keys
Browse files Browse the repository at this point in the history
Related to #145
  • Loading branch information
bmaz committed Dec 7, 2022
1 parent d06a0b3 commit 139b78f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ gaps in the collection in case of connexion errors or reboots. It handles variou

Python >= 3.7 compatible.

Your Twitter API keys must have been created before **April 29, 2022**, in order to use Gazouilloire.
Your Twitter API keys must have been created before **April 29, 2022**, in order to fully use the tool.
If your keys were created after that date, Gazouilloire will work with the "search" endpoint only, and not the "filter".
See [Twitter's documentation](https://developer.twitter.com/en/docs/twitter-api/v1/tweets/filter-realtime/overview)
about this issue.

Expand Down
12 changes: 7 additions & 5 deletions gazouilloire/config_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def create_conf_example(dir_path):
return False


def check_api_keys(conf):
def api_keys_support_stream(conf):
try:
oauth, oauth2 = get_oauth(conf)
except Exception as e:
Expand All @@ -77,13 +77,15 @@ def check_api_keys(conf):
args = {'filter_level': 'none', 'stall_warnings': 'true', 'track': ['the']}
try:
streamiter = streamco.statuses.filter(**args)
return True
except TwitterHTTPError as e:
if "Please use V2 filtered and sample volume stream as alternatives" in str(e):
log.error("Your Twitter API keys were probably created after April 29, 2022. "
"Please use older API keys.")
log.warning("Your Twitter API keys were probably created after April 29, 2022. "
"Gazouilloire will only use the 'search' Twitter API, and not the 'stream'.")
return False
else:
log.error("Error while accessing the Twitter API, please retry: {}".format(e))
sys.exit(1)
sys.exit(1)


def required_format(conf):
Expand Down Expand Up @@ -134,7 +136,7 @@ def required_format(conf):
)
sys.exit(1)

check_api_keys(conf)
conf["start_stream"] = api_keys_support_stream(conf)


if "download_media" in conf:
Expand Down
15 changes: 8 additions & 7 deletions gazouilloire/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -886,13 +886,14 @@ def main(conf, path=".", max_id=0):
)
start_process(download, path)
signal.signal(signal.SIGINT, default_handler)
stream = Process(
target=streamer,
args=(pile, pile_deleted, oauth, oauth2, conf, locale, language, streamgeocode, exit_event),
daemon=True,
name="streamer "
)
start_process(stream, path)
if conf["start_stream"]:
stream = Process(
target=streamer,
args=(pile, pile_deleted, oauth, oauth2, conf, locale, language, streamgeocode, exit_event),
daemon=True,
name="streamer "
)
start_process(stream, path)
search = Process(
target=searcher,
args=(pile, oauth, oauth2, conf, locale, language, searchgeocode, exit_event, no_rollback, max_id),
Expand Down

0 comments on commit 139b78f

Please sign in to comment.