setup.py 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. from selenium import webdriver
  2. from selenium.webdriver.common.by import By
  3. from time import sleep as tsleep
  4. import configparser
  5. import traceback
  6. import sys
  7. import dataset
  8. import os
  9. import random
  10. import math
  11. from datetime import *
  12. db = dataset.connect('mysql://vincent:vipAsw0_69d@db.ptt.cx:3306/vincent?charset=utf8mb4')
  13. def restart_browser(userdatadir, userlist):
  14. options = webdriver.ChromeOptions()
  15. # options.add_argument("start-maximized")
  16. # options.add_argument("--headless")
  17. fullpath='user-data-dir='+userdatadir
  18. # options.add_argument('user-data-dir=C:/Users/XXXXXXXXX/AppData/Local/Google/Chrome/User Data/') # replace XXXXXXXXX with your own username
  19. options.add_argument(fullpath) # replace XXXXXXXXX with your own username
  20. print(fullpath)
  21. '''
  22. for i in os.listdir(userdatadir):
  23. if "Profile" in i and "Guest" not in i and "System" not in i: #only takes "Profile ___"
  24. userlist.append(i)
  25. print(userlist)
  26. '''
  27. # options.add_argument('--profile-directory=Default')
  28. selecteduser = random.choice(userlist)
  29. print(selecteduser)
  30. options.add_argument('--profile-directory=' + selecteduser)
  31. driver=webdriver.Chrome(chrome_options=options)
  32. # driver.set_window_size(1400,1000)
  33. return driver, selecteduser
  34. def setup(programname):
  35. if programname == '':
  36. print("Please insert a program name.")
  37. return 0, 0, 0, 0, 0
  38. try:
  39. config = configparser.ConfigParser()
  40. #config.sections()
  41. config.read('_settings.ini', encoding="UTF+8")
  42. userdatadir = config['DEFAULT']['userdatadir']
  43. userlist = config['DEFAULT']['userlist'].split(',')
  44. serverid = config['DEFAULT']['serverid']
  45. try: # minimize window function
  46. minimize = int(config[programname]['minimizewindow'])
  47. except:
  48. minimize = 0
  49. key1 = config['DEFAULT']['enabled'] # two keys have to be on 1 for program to run
  50. key2 = config[programname]['enabled']
  51. #for k,v in config['DEFAULT'].items():
  52. # print(k)
  53. #sys.exit()
  54. try:
  55. if int(key1) == 1 and int(key2) == 1:
  56. for i in range(0, len(userlist)): # removes spaces at beginning
  57. userlist[i] = userlist[i].lstrip(' ')
  58. print("Selecting from profiles", userlist)
  59. print("Server ID is "+ str(serverid))
  60. return userdatadir, userlist, config, minimize, 1
  61. else:
  62. print("Program disabled. Please check settings and try again.")
  63. tsleep(5)
  64. return 0, 0, config, 0, 0
  65. except:
  66. print("Program disabled. Please check settings and try again.")
  67. tsleep(5)
  68. return 0, 0, config, 0, 0
  69. except:
  70. traceback.print_exc()
  71. print("Invalid settings. Please check settings and try again.")
  72. tsleep(5)
  73. return 0, 0, 0, 0, 0
  74. def output(data):
  75. info = []
  76. for i in data:
  77. info.append(i.text)
  78. return info