File size: 1,016 Bytes
4e1b77d 11da7cf abc03b0 607c0f5 1b420ad 607c0f5 4e1b77d d639071 45d40ce 4e1b77d 45d40ce 4e1b77d 272b76f 4e1b77d 607c0f5 11da7cf 607c0f5 11da7cf 607c0f5 11da7cf 607c0f5 c2de41d 11da7cf 607c0f5 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | import re
import os
import sys
from api_client import fetch_users, get_endpoint, get_phpsessid
ROOT_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", ".."))
inp = input("Enter User IDs: ")
user_ids = re.findall(r"\d+", inp)
user_ids = [int(uid) for uid in user_ids]
if len(user_ids) == 0:
sys.exit()
def main() -> int:
phpsessid = get_phpsessid()
endpoint = get_endpoint()
try:
data = fetch_users(user_ids, phpsessid, endpoint)
except Exception as exc:
print(f"Error: {exc}")
return 1
for user_data in data:
if "error" in user_data:
print(f"User ID {user_data.get('user_id')} Error: {user_data.get('error')}")
continue
filename = user_data["filename"]
post_ids = user_data["post_ids"]
with open(os.path.join(ROOT_DIR, filename + ".txt"), "w", encoding="utf-8") as f:
f.write("\n".join(map(str, post_ids)))
return 0
if __name__ == "__main__":
raise SystemExit(main())
|