Use chrome profile to change language

This commit is contained in:
augustin64 2024-04-10 11:35:46 +02:00
parent 49dc53ed32
commit 3978c44bbc
3 changed files with 34 additions and 33 deletions

6
V6.py
View File

@ -9,7 +9,6 @@ from modules.db import add_to_database
from modules.driver_tools import *
from modules.error import *
import os
from selenium.common.exceptions import NoSuchElementException
# create a webdriver
@ -25,9 +24,7 @@ def create_driver(mobile=False):
"Chrome/22 Mobile Safari/537.36"
)
# Profile dir
chrome_profile_dir = "/app/MsRewards-Reborn/user_data/profile/"+config.UserCredentials.get_mail()
os.makedirs(chrome_profile_dir, exist_ok=True)
chrome_profile_dir = init_profile(config.UserCredentials.get_mail())
# Full list on https://github.com/GoogleChrome/chrome-launcher/blob/main/docs/chrome-flags-for-tools.md
arguments = [
@ -53,7 +50,6 @@ def create_driver(mobile=False):
chrome_options.add_argument(arg)
driver = uc.Chrome(options=chrome_options)
set_language(driver)
return driver

View File

@ -1,3 +1,5 @@
import os
import json
from random import uniform
from selenium.common import TimeoutException
@ -10,33 +12,36 @@ from modules.Tools.logger import debug
from modules.Tools.tools import *
def set_language(ldriver):
ldriver.get("chrome://settings/languages")
action = ActionChains(ldriver)
action.reset_actions()
# select language
x_coord = 1200
y_coord = 150
action.move_by_offset(x_coord, y_coord).click().perform()
sleep(0.5)
# scroll down
action.reset_actions()
elm = ldriver.find_element(By.XPATH, "/html/body")
ActionChains(ldriver) \
.send_keys("french") \
.pause(0.5) \
.send_keys(Keys.TAB + Keys.TAB + Keys.ENTER + Keys.TAB + Keys.TAB + Keys.ENTER) \
.perform()
x_coord = 1163
y_coord = 717
action.move_by_offset(x_coord, y_coord).click().perform()
# put to the top
sleep(0.5)
action.reset_actions()
x_coord = 1257
y_coord = 328
action.move_by_offset(x_coord, y_coord).click().perform()
action.click().perform()
def init_profile(mail):
chrome_profile_dir = "/app/MsRewards-Reborn/user_data/profile/"+mail
os.makedirs(chrome_profile_dir, exist_ok=True)
preferences_file = os.path.join(chrome_profile_dir, "Default", "Preferences")
if not os.path.exists(preferences_file):
os.makedirs(os.path.join(chrome_profile_dir, "Default"), exist_ok=True)
with open(preferences_file, "w") as f:
json.dump(
{
"intl": {
"accept_languages": "fr-FR,en-US,en",
"selected_languages": "fr-FR,en-US,en"
}
}, f
)
else:
with open(preferences_file, "r") as f:
settings = json.load(f)
if "intl" not in settings:
settings["intl"] = {}
settings["intl"]["accept_languages"] = "fr-FR,en-US,en"
settings["intl"]["selected_languages"] = "fr-FR,en-US,en"
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

View File

@ -1 +1 @@
v6.8.43
v6.8.44