[fs2zammad] allow arbitrary source directory as CLI arg

This commit is contained in:
fnux 2024-08-05 11:15:52 +02:00
parent 2d3526918e
commit 230d8703ff
No known key found for this signature in database
GPG key ID: 4502C902C00A1E12

View file

@ -303,14 +303,21 @@ with open("rt2zammad.json") as handle:
h2t = html2text.HTML2Text() h2t = html2text.HTML2Text()
zammad = get_zammad_session() zammad = get_zammad_session()
source_directory = "tickets/"
if len(sys.argv) >= 2:
source_directory = sys.argv[1]
if not os.path.isdir(source_directory):
print(f"Could not find source directory {source_directory}. Exiting.")
sys.exit(1)
os.makedirs("users", exist_ok=True) os.makedirs("users", exist_ok=True)
os.makedirs("tickets", exist_ok=True) os.makedirs("tickets", exist_ok=True)
os.makedirs("attachments", exist_ok=True) os.makedirs("attachments", exist_ok=True)
os.makedirs("failed", exist_ok=True) os.makedirs("failed", exist_ok=True)
os.makedirs("processed", exist_ok=True) os.makedirs("processed", exist_ok=True)
ticket_ids = os.listdir("tickets/") ticket_ids = os.listdir(source_directory)
print(f"Found {len(ticket_ids)} tickets on filesystem.") print(f"Found {len(ticket_ids)} tickets on filesystem (source directory: {source_directory})")
ticket_ids = list(map(int, ticket_ids)) ticket_ids = list(map(int, ticket_ids))
ticket_ids.sort() ticket_ids.sort()