-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdiapo-recup.py
More file actions
188 lines (170 loc) · 6.77 KB
/
diapo-recup.py
File metadata and controls
188 lines (170 loc) · 6.77 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#!/usr/bin/python3.11
# -*- coding: utf-8 -*-
# récupérer les liens de mes photos google
from selenium import webdriver # contrôle le navigateur
from selenium.webdriver import ActionChains # clique droit
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By # accède aux élements de la page web
from selenium.webdriver.common.keys import Keys
from webdriver_manager.chrome import ChromeDriverManager # utiliser le navigateur chrome
import time
from fileList import FileList
# lancer le navigateur, ici chrome
service = Service()
options = webdriver.ChromeOptions()
options.add_argument ('--enable-unsafe-swiftshader')
options.add_argument ('--ignore-certificate-errors')
options.add_argument ('--ignore-ssl-errors')
options.add_argument ('--log-level=3')
driver = webdriver.Chrome (service=service, options=options)
actionChains = ActionChains (driver)
cities =( 'ftb', 'blr', 'fontainebleau', 'bois le rois', 'avon', 'rueil', 'paris', 'issy' )
citiesDico ={ 'ftb': 'fontainebleau', 'blr': 'bois le rois' }
class PhotoGoogle():
def __init__ (self):
self.date =""
self.city =""
self.place = 'NULL'
self.themes = 'NULL'
self.title =""
self.url =""
def extractCityFromLocation (self):
pass
def doTitle (self):
if self.title[-3] =='.': self.title = self.title[:-3]
elif self.title[-4] =='.': self.title = self.title[:-4]
# la ville
d=0
while d<8:
if cities[d] in self.title:
self.city = cities[d]
self.title = self.title.replace (cities[d], "")
self.title = self.title.replace (" ", " ")
self.title = self.title.strip()
d=8
d+=1
if self.city in cities[:2]: self.city = citiesDico [self.city]
# la date
if '202' in self.title and not self.date:
lTitle = len (self.title)
d= self.title.find ('202')
f= lTitle
if " " in self.title[d:]: f= self.title.find (" ",d)
self.date = self.title[d:f]
# la ville
if self.city: self.title = self.title[:d] + self.title[f:]
elif d>2 and self.title[:d].count (" ") ==1:
self.city = self.title[:d-1]
self.title = self.title[f:]
elif f< lTitle -2 and self.title[f:].count (" ") ==1:
self.city = self.title[f+1:]
self.title = self.title[:d]
else: self.title = self.title[:d] + self.title[f:]
self.title = self.title.replace (" ", " ")
def __str__(self):
photoStr = self.date +'\t'+ self.city +'\t'+ self.title +'\t'+ self.themes +'\t'+ self.place +'\t'+ self.url
return photoStr
def __eq__(self, photo):
# également ne !=, gt >, lt <, ge >=, le <=
if photo.__class__ != self.__class__: return False
elif self.city == photo.city and self.place == photo.place and self.date == photo.date and self.themes == photo.themes and self.title == photo.title and self.url == photo.url:
return True
else: return False
def __ne__(self, photo):
if photo.__class__ != self.__class__: return False
else: return not self.__eq__(photo)
def __gt__(self, photo):
if photo.__class__ != self.__class__: return False
elif self.city > photo.city: return True
elif self.city < photo.city: return False
elif self.place > photo.place: return True
elif self.place < photo.place: return False
elif self.date > photo.date: return True
elif self.date < photo.date: return False
elif self.themes > photo.themes: return True
elif self.themes < photo.themes: return False
elif self.title > photo.title: return True
elif self.title < photo.title: return False
elif self.url > photo.url: return True
else: return False
def __lt__(self, photo):
if photo.__class__ != self.__class__: return False
else: return not self.__gt__(photo)
def __ge__(self, photo):
if photo.__class__ != self.__class__: return False
elif self.__eq__(photo): return True
else: return self.__gt__(photo)
def __le__(self, photo):
if photo.__class__ != self.__class__: return False
elif self.__eq__(photo): return True
else: return self.__lt__(photo)
def comparByDate (self, photo):
if self.date > photo.date: return 1
elif self.date < photo.date: return -1
elif self.city > photo.city: return 1
elif self.city < photo.city: return -1
elif self.place > photo.place: return 1
elif self.place < photo.place: return -1
elif self.themes > photo.themes: return 1
elif self.themes < photo.themes: return -1
elif self.title > photo.title: return 1
elif self.title < photo.title: return -1
else: return 0
def comparByCity (self, photo):
if self.city > photo.city: return 1
elif self.city < photo.city: return -1
elif self.place > photo.place: return 1
elif self.place < photo.place: return -1
elif self.date > photo.date: return 1
elif self.date < photo.date: return -1
elif self.themes > photo.themes: return 1
elif self.themes < photo.themes: return -1
elif self.title > photo.title: return 1
elif self.title < photo.title: return -1
else: return 0
class PhotoGoogleList (FileList):
def __str__(self):
photoStr =""
for photo in self.list: photoStr = photoStr + photo.__str__() + self.sep
return photoStr
def getImgData (first=False):
photoGoogle = PhotoGoogle()
time.sleep (0.5)
# trouver le bouton pour afficher les infos
buttonInfos = driver.find_elements (By.TAG_NAME, 'button')[4]
# buttonInfos = driver.find_element (By.XPATH, './/button[@aria-label="Ouvrir les infos"]')
buttonInfos.click()
time.sleep (0.5)
# récupérer le nom du fichier, qui contient des infos sur la photo
imgAll = driver.find_elements (By.XPATH, './/dd/div[@aria-label]')
imgLen = len (imgAll)
imgData =""
i=0
while i< imgLen and imgData =="":
imgTmp = imgAll[i].get_dom_attribute ('aria-label')
if 'Nom du fichier' == imgTmp[:14]: imgData = imgAll[i].text[:-4]
i+=1
photoGoogle.title = imgData
photoGoogle.doTitle()
imgAll = driver.find_elements (By.XPATH, './/dd/div')
for img in imgAll: print ('info', img.text)
buttonInfos.click()
time.sleep (0.5)
# récupérer les images de la page
imgAll = driver.find_elements (By.XPATH, './/img[contains(@src, "https://lh3.googleusercontent.com/pw/AP1Gcz")]')
imgLen = len (imgAll)
if first: photoGoogle.url = imgAll[0].get_dom_attribute ('src')[43:]
else: photoGoogle.url = imgAll[2].get_dom_attribute ('src')[43:]
# aller à la page suivante
print (photoGoogle)
"""
if imgLen ==6 or first:
first = False
buttonNext = driver.find_element (By.XPATH, './/div[@aria-label="Afficher la photo suivante"]')
buttonNext.click()
getImgData()
"""
urlFirstPhoto = 'https://photos.google.com/share/AF1QipPao_azUraa3kWyoa7bgp67IGn60OYuyuVxnxrrOlO2Nfg1iY75owjIc1xDE7u2_A/photo/AF1QipMbNMMi93nR__ljAPKMR8PMICLgv-dZNphucGpc?key=Q1dlVDFqaVZlNTY4Q1puS3UwSmZsT21YUU1uWTJB'
urlFirstPhoto = 'https://photos.google.com/share/AF1QipPao_azUraa3kWyoa7bgp67IGn60OYuyuVxnxrrOlO2Nfg1iY75owjIc1xDE7u2_A/photo/AF1QipPjZNnadwTNFU4YJv4FEIfv98-xneKvGxAilKGd?key=Q1dlVDFqaVZlNTY4Q1puS3UwSmZsT21YUU1uWTJB'
driver.get (urlFirstPhoto)
getImgData (True)