From 56b9ff10d6a01b005beb7fffbd961ac0a21ae048 Mon Sep 17 00:00:00 2001 From: timberjoegithub Date: Wed, 29 May 2024 17:52:51 -0400 Subject: [PATCH] added docker remote browser support --- social.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/social.py b/social.py index 42b8ae8..3bf546f 100644 --- a/social.py +++ b/social.py @@ -1,5 +1,4 @@ import sqlalchemy -import env #data import time @@ -36,9 +35,12 @@ import instagrapi from moviepy.editor import VideoFileClip, concatenate_videoclips #import moviepy +from pathlib import Path + from sqlalchemy.ext.declarative import declarative_base #import mysqlclient #import mysql-connector-python +import env Base = declarative_base() ################################################################################################## @@ -178,6 +180,12 @@ def counter(driver): ################################################################################################## +def is_docker(): + cgroup = Path('/proc/self/cgroup') + return Path('/.dockerenv').is_file() or cgroup.is_file() and 'docker' in cgroup.read_text() + +################################################################################################## + def post_facebook(title, content, date, rating, address, picslist, instasession): #msg = 'Purple Ombre Bob Lace Wig Natural Human Hair now available on https://lace-wigs.co.za/' pics = ((picslist[1:-1].replace(",","")).replace("'","")).split(" ") @@ -1008,7 +1016,10 @@ def process_reviews(outputs): caps['acceptSslCerts'] = True options.set_capability('cloud:options', caps) #driver = webdriver.Chrome(desired_capabilities=caps) - driver = webdriver.Chrome(options=options) # Firefox(options=options) + if is_docker : + driver = webdriver.Remote("http://192.168.10.6:4444/wd/hub", options=options) + else: + driver = webdriver.Chrome(options=options) # Firefox(options=options) # Changing the property of the navigator value for webdriver to undefined driver.execute_script("Object.defineProperty(navigator, 'webdriver', {get: () => undefined})") driver.get(env.URL)