Update get_context.py

This commit is contained in:
nanos 2023-03-06 12:51:46 +00:00 committed by GitHub
parent 8f435d9c4e
commit a0d9a89997
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -388,31 +388,26 @@ class OrderedSet:
if __name__ == "__main__": if __name__ == "__main__":
HELP_MESSAGE = """ HELP_MESSAGE = """
Usage: ACCESS_TOKEN=XXXX python3 pull_context.py <server> <reply_interval_in_hours> <home_timeline_length> Usage: python3 pull_context.py <access_token> <server> <reply_interval_in_hours> <home_timeline_length>
To run this script, set the ACCESS_TOKEN environment variable to your The access token can be generated at
Mastodon access token. The access token can be generated at
https://<server>/settings/applications, and must have read:search, https://<server>/settings/applications, and must have read:search,
read:statuses and admin:read:accounts scopes. read:statuses and admin:read:accounts scopes.
""" """
try:
ACCESS_TOKEN = os.environ["ACCESS_TOKEN"]
except KeyError: if len(sys.argv) < 5:
print("ACCESS_TOKEN environment variable not set.")
print(HELP_MESSAGE) print(HELP_MESSAGE)
sys.exit(1) sys.exit(1)
if len(sys.argv) < 4: ACCESS_TOKEN = sys.argv[2]
print(HELP_MESSAGE) SERVER = sys.argv[2]
sys.exit(1) REPLY_INTERVAL_IN_HOURS = int(sys.argv[3])
SERVER = sys.argv[1]
REPLY_INTERVAL_IN_HOURS = int(sys.argv[2])
SEEN_URLS_FILE = "artifacts/seen_urls" SEEN_URLS_FILE = "artifacts/seen_urls"
REPLIED_TOOT_SERVER_IDS_FILE = "artifacts/replied_toot_server_ids" REPLIED_TOOT_SERVER_IDS_FILE = "artifacts/replied_toot_server_ids"
MAX_HOME_TIMELINE_LENGTH = int(sys.argv[3]) MAX_HOME_TIMELINE_LENGTH = int(sys.argv[4])
SEEN_URLS = OrderedSet([]) SEEN_URLS = OrderedSet([])
if os.path.exists(SEEN_URLS_FILE): if os.path.exists(SEEN_URLS_FILE):
@ -437,4 +432,4 @@ read:statuses and admin:read:accounts scopes.
f.write("\n".join(list(SEEN_URLS)[:10000])) f.write("\n".join(list(SEEN_URLS)[:10000]))
with open(REPLIED_TOOT_SERVER_IDS_FILE, "w", encoding="utf-8") as f: with open(REPLIED_TOOT_SERVER_IDS_FILE, "w", encoding="utf-8") as f:
json.dump(dict(list(REPLIED_TOOT_SERVER_IDS.items())[:10000]), f) json.dump(dict(list(REPLIED_TOOT_SERVER_IDS.items())[:10000]), f)