Skip to content
Snippets Groups Projects
Commit 9c76d60c authored by Köllőd Csaba's avatar Köllőd Csaba
Browse files

Update downloadFilesOfNeuroFlowDevice.py

parent d98bd0f8
Branches
No related tags found
No related merge requests found
import json
from getpass import getpass
from pathlib import Path
import json
import os
import requests
......@@ -12,7 +12,8 @@ class tcolors:
ENDC = '\033[0m'
def download_data():
def download_data(path='.'):
path = Path(path)
print("\n" + tcolors.HEADER + "================================" + tcolors.ENDC)
print(tcolors.HEADER + "NeuroFlow Lab Kutatói Alkalmazás" + tcolors.ENDC)
print(tcolors.HEADER + "================================" + tcolors.ENDC + "\n")
......@@ -20,6 +21,7 @@ def download_data():
email = input("Kutató email címe: ")
password = getpass("Kutató jelszava: ")
deviceID = input("Eszköz egyedi azonosítója: ")
path = path.joinpath(deviceID)
headers = {'Content-Type': 'application/json'}
payload = {'email': email, 'password': password, 'deviceID': deviceID}
......@@ -28,14 +30,14 @@ def download_data():
if r.status_code == 200:
listOfFiles = r.json()['files']
print("\nLe fogok tölteni " + str(len(listOfFiles)) + " darab fájl-t a '" + deviceID + "' nevű könyvtárba...")
print(f'\nLe fogok tölteni {len(listOfFiles)} darab fájl-t a {path} könyvtárba...')
if not os.path.exists(deviceID):
os.makedirs(deviceID)
print(tcolors.OK + "Létrehoztam a '" + deviceID + "' nevű könytárat." + tcolors.ENDC)
if not path.exists():
path.mkdir(parents=True, exist_ok=True)
print(tcolors.OK + "Létrehoztam a '" + str(path) + "' könytárat." + tcolors.ENDC)
print("")
for file in listOfFiles:
for i, file in enumerate(listOfFiles):
print("Indítom a '" + file + "' nevű fájl letöltését...")
headers = {'Content-Type': 'application/json'}
......@@ -44,11 +46,11 @@ def download_data():
headers=headers, data=json.dumps(payload))
if r.status_code == 200:
path = deviceID + '/' + file
with open(path, "wb") as binary_file:
save_path = path.joinpath(file)
with open(save_path, "wb") as binary_file:
binary_file.write(r.content)
print(tcolors.OK + "LETÖLTVE" + tcolors.ENDC)
print(tcolors.OK + "LETÖLTVE" + tcolors.ENDC, f'{100. * i / len(listOfFiles):.2f} %')
else:
print(tcolors.FAIL + "HIBA" + tcolors.ENDC)
......@@ -59,6 +61,7 @@ def download_data():
print("\n" + tcolors.FAIL + "Hibás email cím vagy jelszó!" + tcolors.ENDC + "\n")
elif r.status_code == 446:
print("\n" + tcolors.FAIL + "Hibás eszköz azonosító!" + tcolors.ENDC + "\n")
return path
if __name__ == '__main__':
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment