API - check if workouts directory exist before exporting gpx file
+ remove json files
This commit is contained in:
parent
06d4a53fbb
commit
576b3fd66c
@ -76,6 +76,7 @@ class UserDataExporter:
|
|||||||
zip_object.write(
|
zip_object.write(
|
||||||
picture_path, self.user.picture.split('/')[-1]
|
picture_path, self.user.picture.split('/')[-1]
|
||||||
)
|
)
|
||||||
|
if os.path.exists(self.workouts_directory):
|
||||||
for file in os.listdir(self.workouts_directory):
|
for file in os.listdir(self.workouts_directory):
|
||||||
if os.path.isfile(
|
if os.path.isfile(
|
||||||
os.path.join(self.workouts_directory, file)
|
os.path.join(self.workouts_directory, file)
|
||||||
@ -86,8 +87,11 @@ class UserDataExporter:
|
|||||||
)
|
)
|
||||||
|
|
||||||
file_exists = os.path.exists(zip_path)
|
file_exists = os.path.exists(zip_path)
|
||||||
|
os.remove(user_data_file_name)
|
||||||
|
os.remove(workout_data_file_name)
|
||||||
return (zip_path, zip_file) if file_exists else (None, None)
|
return (zip_path, zip_file) if file_exists else (None, None)
|
||||||
except Exception:
|
except Exception as e:
|
||||||
|
appLog.error(f'Error when generating user data archive: {str(e)}')
|
||||||
return None, None
|
return None, None
|
||||||
|
|
||||||
|
|
||||||
@ -108,6 +112,7 @@ def export_user_data(export_request_id: int) -> None:
|
|||||||
exporter = UserDataExporter(user)
|
exporter = UserDataExporter(user)
|
||||||
archive_file_path, archive_file_name = exporter.generate_archive()
|
archive_file_path, archive_file_name = exporter.generate_archive()
|
||||||
|
|
||||||
|
try:
|
||||||
export_request.completed = True
|
export_request.completed = True
|
||||||
if archive_file_name and archive_file_path:
|
if archive_file_name and archive_file_path:
|
||||||
export_request.file_name = archive_file_name
|
export_request.file_name = archive_file_name
|
||||||
@ -128,3 +133,5 @@ def export_user_data(export_request_id: int) -> None:
|
|||||||
data_export_email.send(user_data, email_data)
|
data_export_email.send(user_data, email_data)
|
||||||
else:
|
else:
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
except Exception as e:
|
||||||
|
appLog.error(f'Error when exporting user data: {str(e)}')
|
||||||
|
Loading…
Reference in New Issue
Block a user