generated from MuckRock/documentcloud-hello-world-addon
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added error handling for bad project ID provided
- Loading branch information
1 parent
8c8d0c7
commit 38adac3
Showing
1 changed file
with
22 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
Upload transcribed audio files to DocumentCloud using Whisper | ||
""" | ||
import os | ||
import json | ||
import shutil | ||
import sys | ||
from subprocess import call, CalledProcessError | ||
|
@@ -172,13 +173,28 @@ def main(self): | |
|
||
with open(f"{basename}.txt", "w+", encoding="utf-8") as file_: | ||
format_segments(result, file_) | ||
try: | ||
self.client.documents.upload( | ||
f"{basename}.txt", | ||
original_extension="txt", | ||
access=access_level, | ||
**kwargs, | ||
) | ||
except APIError as e: | ||
error_data = json.loads(e.response) | ||
if "projects" in error_data: | ||
self.set_message( | ||
"Please check that you provided either a" | ||
"valid project ID or left it completely blank. Try again." | ||
) | ||
sys.exit(0) | ||
else: | ||
self.set_message( | ||
"API error reached, contact [email protected] for support" | ||
) | ||
print(e) | ||
sys.exit(1) | ||
|
||
self.client.documents.upload( | ||
f"{basename}.txt", | ||
original_extension="txt", | ||
access=access_level, | ||
**kwargs, | ||
) | ||
successes += 1 | ||
|
||
sfiles = "file" if successes == 1 else "files" | ||
|