-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackup_service.py
More file actions
43 lines (32 loc) · 1.78 KB
/
backup_service.py
File metadata and controls
43 lines (32 loc) · 1.78 KB
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
38
39
40
41
42
43
import file_service
from util import http_client
import print_service
def start_backup() -> None:
print_service.print_heading('Preparations')
print_service.print_subheading('Creating directory for backup files...')
msg = file_service.create_directory_for_backup_files()
print(msg)
print_service.print_subheading('Determining already downloaded files...')
downloaded_elements = file_service.get_backup_file_names_without_file_extension()
print('Count: ' + str(len(downloaded_elements)))
print_service.print_subheading('Determining available files...')
all_elements = http_client.fetch_dates_with_sensor_data()
print('Count: ' + str(len(all_elements)))
files_to_download = [element for element in all_elements if element not in downloaded_elements]
if len(downloaded_elements) > 0:
last_downloaded_element = downloaded_elements[-1]
print('Last downloaded: ' + last_downloaded_element)
if last_downloaded_element in all_elements:
files_to_download.append(last_downloaded_element)
number_of_files_to_download = len(files_to_download)
print('Files to download: ' + str(number_of_files_to_download))
print_service.print_heading('Backup')
print_service.print_subheading('Downloading files...')
number_of_downloaded_files = 0
print_service.show_progress_bar(number_of_downloaded_files, number_of_files_to_download)
for file_to_download in files_to_download:
file_content = http_client.download_file(file_to_download)
file_service.write_content_to_backup_file(file_to_download, file_content)
number_of_downloaded_files += 1
print_service.show_progress_bar(number_of_downloaded_files, number_of_files_to_download)
print('Downloaded files: ' + str(number_of_downloaded_files))