Browse Source

pas de doublons

master
BARRAUX Arthur 2 years ago
parent
commit
7489a5c379
  1. 4
      .gitignore
  2. 17
      app.py
  3. 3
      requirement.txt

4
.gitignore

@ -1 +1,3 @@
nextcloud_auth.json
nextcloud.json
__pycache__/*
token.json

17
app.py

@ -40,6 +40,7 @@ class Connection:
self.nextcloud_pass = data['pass']
self.nextcloud_url = data['url']
self.nextcloud_destination_folder = data['destination_folder']
self.google_connect()
def google_connect(self):
# The file token.json stores the user's access and refresh tokens, and is
@ -49,7 +50,7 @@ class Connection:
self.creds = Credentials.from_authorized_user_file('token.json', self.SCOPES)
# If there are no (valid) credentials available, let the user log in.
if not self.creds or not self.creds.valid:
if self.creds and self.creds.expired and self.reds.refresh_token:
if self.creds and self.creds.expired and self.creds.refresh_token:
self.creds.refresh(Request())
else:
flow = InstalledAppFlow.from_client_secrets_file(
@ -65,19 +66,19 @@ def download(connection, next_page=None):
try:
service = build('photoslibrary', 'v1', credentials=connection.creds, static_discovery=False)
results = service.mediaItems().list(pageSize=100, pageToken=next_page).execute()
results = service.mediaItems().list(pageSize=20, pageToken=next_page).execute()
items = results.get('mediaItems', [])
next_page = results.get('nextPageToken')
images = []
for item in items:
print(f"{item['filename']} {item['mimeType']}")
url = connection.nextcloud_url + '/remote.php/dav/files/' + connection.nextcloud_user + '/' + connection.nextcloud_destination_folder + '/' + item['filename']
if "video" in item['mimeType']:
requests.put(url, auth=HTTPBasicAuth(connection.nextcloud_user, connection.nextcloud_pass), data=requests.get(item['baseUrl']+'=dv').content)
else:
requests.put(url, auth=HTTPBasicAuth(connection.nextcloud_user, connection.nextcloud_pass), data=requests.get(item['baseUrl']+'=d').content)
if requests.get(url, auth=HTTPBasicAuth(connection.nextcloud_user, connection.nextcloud_pass)).status_code != 200:
if "video" in item['mimeType']:
requests.put(url, auth=HTTPBasicAuth(connection.nextcloud_user, connection.nextcloud_pass), data=requests.get(item['baseUrl']+'=dv').content)
else:
requests.put(url, auth=HTTPBasicAuth(connection.nextcloud_user, connection.nextcloud_pass), data=requests.get(item['baseUrl']+'=d').content)
return next_page
@ -89,7 +90,7 @@ def download(connection, next_page=None):
if __name__ == '__main__':
connection = Connection()
next_page = download(connection)
while next_page != 'null':
while next_page != None:
next_page = download(connection, next_page)
print('done')
# [END docs_quickstart]

3
requirement.txt

@ -5,14 +5,17 @@ google-api-core==2.11.0
google-api-python-client==2.71.0
google-auth==2.15.0
google-auth-httplib2==0.1.0
google-auth-oauthlib==0.8.0
googleapis-common-protos==1.57.1
httplib2==0.21.0
idna==3.4
oauthlib==3.2.2
protobuf==4.21.12
pyasn1==0.4.8
pyasn1-modules==0.2.8
pyparsing==3.0.9
requests==2.28.1
requests-oauthlib==1.3.1
rsa==4.9
six==1.16.0
uritemplate==4.1.1

Loading…
Cancel
Save