from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
import time
import os
import urllib.parse
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import expected_conditions as EC
import codecs
import random
from bs4 import BeautifulSoup
import requests
import time
import rpyc
import schedule
import sys
import docker


def scrolling(pgnum):
        global driver
        ub = driver.find_element_by_css_selector('body')
        for i in range(pgnum):
            ub.send_keys(Keys.PAGE_DOWN)
            if pgnum>1:
                time.sleep(0.5)

headers = {
        "Authorization": "Bearer " + "t35vhZtWNgvDNWHc3DJh0OKll3mcB9GvC8K2EAkBug2",
        "Content-Type": "application/x-www-form-urlencoded"
}


def do_job():
    proxy=["--proxy-server=socks4://65.184.223.253:5678","--proxy-server=socks4://217.79.124.92:5678","--proxy-server=socks4://51.161.82.222:9300","--proxy-server=52.11.2.59:3128","--proxy-server=socks4://139.60.12.6:1088","--proxy-server=socks4://206.126.57.190:5678","--proxy-server=socks4://194.208.93.221:5678","--proxy-server=socks4://192.253.209.65:5678","--proxy-server=socks4://139.60.78.28:5678"]

    client = docker.from_env()
    ls=client.containers.list()
    print(ls)
    ls[0].restart()

    time.sleep(10)
    options = webdriver.ChromeOptions()
    options.add_argument(random.choice(proxy))
#    options.add_argument("--proxy-server=socks4://64.124.145.1:1080")


    driver = webdriver.Remote(
        command_executor='http://127.0.0.1:4444/wd/hub',
    #command_executor='http://192.53.174.202:4444/wd/hub',
    #command_executor='http://172.104.93.163:4444/wd/hub',
    
    #command_executor='http://dev2.choozmo.com:14444/wd/hub',
    desired_capabilities=options.to_capabilities())
    #desired_capabilities=DesiredCapabilities.CHROME)
    driver.set_window_size(1400,1000)
    time.sleep(3)
    try:
        driver.get('https://www.sparkamplab.com/events/arvr-2021')
        scrolling(30)
        print('done scrolling')
        time.sleep(20)
    except:
        print('excpet')
    driver.quit()


do_job()
schedule.every(2).minutes.do(do_job)

while True:
    schedule.run_pending()
    time.sleep(1)


