API - check if workouts directory exist before exporting gpx file
+ remove json files
This commit is contained in:
parent
06d4a53fbb
commit
576b3fd66c
@ -76,18 +76,22 @@ class UserDataExporter:
|
|||||||
zip_object.write(
|
zip_object.write(
|
||||||
picture_path, self.user.picture.split('/')[-1]
|
picture_path, self.user.picture.split('/')[-1]
|
||||||
)
|
)
|
||||||
for file in os.listdir(self.workouts_directory):
|
if os.path.exists(self.workouts_directory):
|
||||||
if os.path.isfile(
|
for file in os.listdir(self.workouts_directory):
|
||||||
os.path.join(self.workouts_directory, file)
|
if os.path.isfile(
|
||||||
) and file.endswith('.gpx'):
|
os.path.join(self.workouts_directory, file)
|
||||||
zip_object.write(
|
) and file.endswith('.gpx'):
|
||||||
os.path.join(self.workouts_directory, file),
|
zip_object.write(
|
||||||
f"gpx/{file}",
|
os.path.join(self.workouts_directory, file),
|
||||||
)
|
f"gpx/{file}",
|
||||||
|
)
|
||||||
|
|
||||||
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,23 +112,26 @@ 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()
|
||||||
|
|
||||||
export_request.completed = True
|
try:
|
||||||
if archive_file_name and archive_file_path:
|
export_request.completed = True
|
||||||
export_request.file_name = archive_file_name
|
if archive_file_name and archive_file_path:
|
||||||
export_request.file_size = os.path.getsize(archive_file_path)
|
export_request.file_name = archive_file_name
|
||||||
db.session.commit()
|
export_request.file_size = os.path.getsize(archive_file_path)
|
||||||
|
db.session.commit()
|
||||||
|
|
||||||
if current_app.config['CAN_SEND_EMAILS']:
|
if current_app.config['CAN_SEND_EMAILS']:
|
||||||
ui_url = current_app.config['UI_URL']
|
ui_url = current_app.config['UI_URL']
|
||||||
email_data = {
|
email_data = {
|
||||||
'username': user.username,
|
'username': user.username,
|
||||||
'fittrackee_url': ui_url,
|
'fittrackee_url': ui_url,
|
||||||
'account_url': f'{ui_url}/profile/edit/account',
|
'account_url': f'{ui_url}/profile/edit/account',
|
||||||
}
|
}
|
||||||
user_data = {
|
user_data = {
|
||||||
'language': get_language(user.language),
|
'language': get_language(user.language),
|
||||||
'email': user.email,
|
'email': user.email,
|
||||||
}
|
}
|
||||||
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…
x
Reference in New Issue
Block a user