Articles sur : API

Utilisez l'API Leviia - Python

Initialisation :


Cette partie de code doit être au début de votre programme.

import xml.etree.ElementTree as ET;
import requests;

domain = "cloud.leviia.com";
auth=('antoine', 'password');
url = "http://"+domain+"/remote.php/dav/files/"+auth[0];

Remplacez « antoine » et « password » par votre identifiant et votre mot de passe.

Lister le contenu d'un dossier :


path = "/path/on/leviia";

r = requests.request('PROPFIND', url+path, data=None, auth=auth);
data = ET.fromstring(r.text);
list = [el[0].text for el in data];
print(list);

Récupérer un fichier :


path = "/path/on/leviia";

r = requests.request('GET', url+path, auth=auth);
open('/path/local', 'wb').write(r.content);

Envoyer un fichier :


path = "/path/on/leviia";

file = open("/path/on/computeur", "rb");
r = requests.request('PUT', url+path, data=file, auth=auth);

Créer un dossier :


path = "/path/on/leviia";

r = requests.request('MKCOL', url+path, auth=auth);


Supprimer un fichier/dossier :


path = "/path/on/leviia";

r = requests.request('DELETE', url+path, auth=auth);

Déplacer un fichier/dossier :


path = "/path/on/leviia";

r = requests.request('MOVE', url+path, data=None,headers={"Destination":url+"/new/path"}, auth=auth);

Copier un fichier/dossier :


path = "/path/on/leviia";

r = requests.request('COPY', url+path, data=None,headers={"Destination":url+"/new/path"}, auth=auth);

Mis à jour le : 12/05/2023

Cet article a-t-il répondu à vos questions ?

Partagez vos commentaires

Annuler

Merci !