-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathGoogle Photos Data Updater.py
131 lines (109 loc) · 4.33 KB
/
Google Photos Data Updater.py
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
# -*- coding: utf-8 -*-
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import NoAlertPresentException
import unittest
import time
import re
import pyautogui
import os
up = os.environ.get('USERPROFILE')
ChromePath = '--user-data-dir=' + up + '\\AppData\\Local\\Google\\Chrome\\User Data\\'
def FindImg(imageName):
imageOnScreen = pyautogui.locateOnScreen(imageName)
if imageOnScreen is not None:
print('%s Found on screen' % imageName)
return imageOnScreen
else:
print('%s Not Found on screen' % imageName)
return False
class GooglePhotosDataUpdater(unittest.TestCase):
def setUp(self):
# Chrome Setup - Make sure Chrome is already not running!
chromedriver = up + "/chromedriver.exe"
options = webdriver.ChromeOptions()
# Path to your chrome profile
options.add_argument(ChromePath)
self.driver = webdriver.Chrome(chrome_options=options,
executable_path=chromedriver)
# self.driver = webdriver.Firefox()
print("Chrome Launched!")
self.driver.implicitly_wait(30)
self.base_url = "https://photos.google.com/photo/***********"
self.verificationErrors = []
self.accept_next_alert = True
def test_google_photos_data_updater(self):
driver = self.driver
driver.get(self.base_url)
def DoThis():
driver.refresh()
pyautogui.moveTo(1200, 90)
time.sleep(1)
pyautogui.click()
ImgName = driver.find_element_by_xpath("//*[contains(@aria-label,'Filename:')]").text
print(ImgName)
if '2015' in ImgName.split('-')[1]:
year = '2015'
elif '2016' in ImgName.split('-')[1]:
year = '2016'
elif '2017' in ImgName.split('-')[1]:
year = '2017'
month = ImgName.split('-')[1][4:6]
day = ImgName.split('-')[1][6:8]
if year is not None:
if month is not None:
if day is not None:
pyautogui.moveTo(1143, 310)
time.sleep(1)
pyautogui.click()
time.sleep(1)
driver.find_element_by_xpath('//input[@aria-label="Year"]').click()
driver.find_element_by_xpath('//input[@aria-label="Year"]').clear()
driver.find_element_by_xpath('//input[@aria-label="Year"]').send_keys(year)
driver.find_element_by_xpath('//input[@aria-label="Month"]').clear()
driver.find_element_by_xpath('//input[@aria-label="Month"]').send_keys(month)
driver.find_element_by_xpath('//input[@aria-label="Day"]').clear()
driver.find_element_by_xpath('//input[@aria-label="Day"]').send_keys(day)
time.sleep(0.5)
pyautogui.moveTo(755, 533)
pyautogui.click()
time.sleep(2)
for i in range(0, 200):
try:
DoThis()
except:
pass
pyautogui.moveTo(948, 525)
pyautogui.click()
time.sleep(1)
def is_element_present(self, how, what):
try:
self.driver.find_element(by=how, value=what)
except NoSuchElementException as e:
return False
return True
def is_alert_present(self):
try:
self.driver.switch_to_alert()
except NoAlertPresentException as e:
return False
return True
def close_alert_and_get_its_text(self):
try:
alert = self.driver.switch_to_alert()
alert_text = alert.text
if self.accept_next_alert:
alert.accept()
else:
alert.dismiss()
return alert_text
finally:
self.accept_next_alert = True
def tearDown(self):
self.driver.quit()
self.assertEqual([], self.verificationErrors)
if __name__ == "__main__":
unittest.main()