Use chrome profile to change language
This commit is contained in:
parent
49dc53ed32
commit
3978c44bbc
6
V6.py
6
V6.py
@ -9,7 +9,6 @@ from modules.db import add_to_database
|
|||||||
from modules.driver_tools import *
|
from modules.driver_tools import *
|
||||||
from modules.error import *
|
from modules.error import *
|
||||||
|
|
||||||
import os
|
|
||||||
from selenium.common.exceptions import NoSuchElementException
|
from selenium.common.exceptions import NoSuchElementException
|
||||||
|
|
||||||
# create a webdriver
|
# create a webdriver
|
||||||
@ -25,9 +24,7 @@ def create_driver(mobile=False):
|
|||||||
"Chrome/22 Mobile Safari/537.36"
|
"Chrome/22 Mobile Safari/537.36"
|
||||||
)
|
)
|
||||||
|
|
||||||
# Profile dir
|
chrome_profile_dir = init_profile(config.UserCredentials.get_mail())
|
||||||
chrome_profile_dir = "/app/MsRewards-Reborn/user_data/profile/"+config.UserCredentials.get_mail()
|
|
||||||
os.makedirs(chrome_profile_dir, exist_ok=True)
|
|
||||||
|
|
||||||
# Full list on https://github.com/GoogleChrome/chrome-launcher/blob/main/docs/chrome-flags-for-tools.md
|
# Full list on https://github.com/GoogleChrome/chrome-launcher/blob/main/docs/chrome-flags-for-tools.md
|
||||||
arguments = [
|
arguments = [
|
||||||
@ -53,7 +50,6 @@ def create_driver(mobile=False):
|
|||||||
chrome_options.add_argument(arg)
|
chrome_options.add_argument(arg)
|
||||||
|
|
||||||
driver = uc.Chrome(options=chrome_options)
|
driver = uc.Chrome(options=chrome_options)
|
||||||
set_language(driver)
|
|
||||||
return driver
|
return driver
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
import os
|
||||||
|
import json
|
||||||
from random import uniform
|
from random import uniform
|
||||||
|
|
||||||
from selenium.common import TimeoutException
|
from selenium.common import TimeoutException
|
||||||
@ -10,33 +12,36 @@ from modules.Tools.logger import debug
|
|||||||
from modules.Tools.tools import *
|
from modules.Tools.tools import *
|
||||||
|
|
||||||
|
|
||||||
def set_language(ldriver):
|
def init_profile(mail):
|
||||||
ldriver.get("chrome://settings/languages")
|
chrome_profile_dir = "/app/MsRewards-Reborn/user_data/profile/"+mail
|
||||||
action = ActionChains(ldriver)
|
os.makedirs(chrome_profile_dir, exist_ok=True)
|
||||||
action.reset_actions()
|
|
||||||
# select language
|
preferences_file = os.path.join(chrome_profile_dir, "Default", "Preferences")
|
||||||
x_coord = 1200
|
if not os.path.exists(preferences_file):
|
||||||
y_coord = 150
|
os.makedirs(os.path.join(chrome_profile_dir, "Default"), exist_ok=True)
|
||||||
action.move_by_offset(x_coord, y_coord).click().perform()
|
with open(preferences_file, "w") as f:
|
||||||
sleep(0.5)
|
json.dump(
|
||||||
# scroll down
|
{
|
||||||
action.reset_actions()
|
"intl": {
|
||||||
elm = ldriver.find_element(By.XPATH, "/html/body")
|
"accept_languages": "fr-FR,en-US,en",
|
||||||
ActionChains(ldriver) \
|
"selected_languages": "fr-FR,en-US,en"
|
||||||
.send_keys("french") \
|
}
|
||||||
.pause(0.5) \
|
}, f
|
||||||
.send_keys(Keys.TAB + Keys.TAB + Keys.ENTER + Keys.TAB + Keys.TAB + Keys.ENTER) \
|
)
|
||||||
.perform()
|
else:
|
||||||
x_coord = 1163
|
with open(preferences_file, "r") as f:
|
||||||
y_coord = 717
|
settings = json.load(f)
|
||||||
action.move_by_offset(x_coord, y_coord).click().perform()
|
|
||||||
# put to the top
|
if "intl" not in settings:
|
||||||
sleep(0.5)
|
settings["intl"] = {}
|
||||||
action.reset_actions()
|
|
||||||
x_coord = 1257
|
settings["intl"]["accept_languages"] = "fr-FR,en-US,en"
|
||||||
y_coord = 328
|
settings["intl"]["selected_languages"] = "fr-FR,en-US,en"
|
||||||
action.move_by_offset(x_coord, y_coord).click().perform()
|
|
||||||
action.click().perform()
|
with open(preferences_file, "w") as f:
|
||||||
|
json.dump(settings, f)
|
||||||
|
|
||||||
|
return chrome_profile_dir
|
||||||
|
|
||||||
|
|
||||||
# Deal with RGPD popup as well as some random popup like 'are you satisfied' one
|
# Deal with RGPD popup as well as some random popup like 'are you satisfied' one
|
||||||
|
Loading…
Reference in New Issue
Block a user