from selenium import webdriver from selenium.webdriver.common.by import By from time import sleep as tsleep import configparser import traceback import sys import dataset import os import random import math from datetime import * db = dataset.connect('mysql://vincent:vipAsw0_69d@db.ptt.cx:3306/vincent?charset=utf8mb4') def restart_browser(userdatadir, userlist): options = webdriver.ChromeOptions() # options.add_argument("start-maximized") # options.add_argument("--headless") fullpath='user-data-dir='+userdatadir # options.add_argument('user-data-dir=C:/Users/XXXXXXXXX/AppData/Local/Google/Chrome/User Data/') # replace XXXXXXXXX with your own username options.add_argument(fullpath) # replace XXXXXXXXX with your own username print(fullpath) ''' for i in os.listdir(userdatadir): if "Profile" in i and "Guest" not in i and "System" not in i: #only takes "Profile ___" userlist.append(i) print(userlist) ''' # options.add_argument('--profile-directory=Default') selecteduser = random.choice(userlist) print(selecteduser) options.add_argument('--profile-directory=' + selecteduser) driver=webdriver.Chrome(chrome_options=options) # driver.set_window_size(1400,1000) return driver, selecteduser def setup(programname): if programname == '': print("Please insert a program name.") return 0, 0, 0, 0, 0 try: config = configparser.ConfigParser() #config.sections() config.read('_settings.ini', encoding="UTF+8") userdatadir = config['DEFAULT']['userdatadir'] userlist = config['DEFAULT']['userlist'].split(',') serverid = config['DEFAULT']['serverid'] try: # minimize window function minimize = int(config[programname]['minimizewindow']) except: minimize = 0 key1 = config['DEFAULT']['enabled'] # two keys have to be on 1 for program to run key2 = config[programname]['enabled'] #for k,v in config['DEFAULT'].items(): # print(k) #sys.exit() try: if int(key1) == 1 and int(key2) == 1: for i in range(0, len(userlist)): # removes spaces at beginning userlist[i] = userlist[i].lstrip(' ') print("Selecting from profiles", userlist) print("Server ID is "+ str(serverid)) return userdatadir, userlist, config, minimize, 1 else: print("Program disabled. Please check settings and try again.") tsleep(5) return 0, 0, config, 0, 0 except: print("Program disabled. Please check settings and try again.") tsleep(5) return 0, 0, config, 0, 0 except: traceback.print_exc() print("Invalid settings. Please check settings and try again.") tsleep(5) return 0, 0, 0, 0, 0 def output(data): info = [] for i in data: info.append(i.text) return info