Skip to content

Commit

Permalink
使用特定版本chrome與env檔案
Browse files Browse the repository at this point in the history
  • Loading branch information
Sun-I-Fu committed Sep 17, 2023
1 parent 129c3a1 commit 408329e
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 6 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ driver_path
*.json
!src/*
config.py
Application
.env
chromedriver.exe
12 changes: 9 additions & 3 deletions classversion.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
import sqlite3
from drive_downloader import download_driver
from pathlib import Path
import time
import yaml
from selenium.common.exceptions import NoSuchElementException
import util
import driver_control
import os
from debugger import Debugger
from datetime import datetime
from dotenv import load_dotenv

load_dotenv()


class ocr_crawler:
def __init__(self, cite: str, test: bool = True) -> None:
self.cite = cite
self.home = Path.cwd()
self.test = test
self.driverpath = download_driver(self.home)
# self.driverpath = self.home / 'chromedriver.exe'
self.driverpath = self.home / Path(os.getenv("DriverPath"))
self.chromepath = self.home / Path(os.getenv("Chromepath"))
self.driver = None
self.db_path = self.home / 'sql' / f"{cite}.db"
self.read_csv()
Expand Down Expand Up @@ -56,7 +61,8 @@ def read_csv(self) -> None:

def new_driver(self):
Debugger.info_print('new driver')
self.driver = util.new_driver(self.driverpath)
self.driver = util.new_driver(dpath=self.driverpath,
cpath=self.chromepath)

def close(self):
if self.driver:
Expand Down
6 changes: 4 additions & 2 deletions debugger.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import requests
import os
import json
import time
import sys
from config import DC_WEBHOOK
from dotenv import load_dotenv
load_dotenv()


class Debugger(object):
Expand Down Expand Up @@ -49,7 +51,7 @@ def dc_print(msg, debug=True):
headers = {
'Content-Type': 'application/json'
}
response = requests.post(DC_WEBHOOK,
response = requests.post(os.getenv('DC_WEBHOOK'),
data=json.dumps(data), headers=headers)
if response.status_code == 204:
print("訊息已成功發送到Discord Webhook!")
Expand Down
Empty file removed feature_file/.gitkeep
Empty file.
3 changes: 2 additions & 1 deletion util/new_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
import sys


def new_driver(dpath: Path) -> webdriver.Chrome:
def new_driver(dpath: Path, cpath: Path) -> webdriver.Chrome:
'''開啟瀏覽器視窗(Chrome)'''
print('執行開始')

options = webdriver.ChromeOptions()
options.add_experimental_option('excludeSwitches', ['enable-logging'])
options.binary_location = str(cpath)
try:
s = Service(executable_path=dpath.resolve())
driver = webdriver.Chrome(service=s, options=options)
Expand Down

0 comments on commit 408329e

Please sign in to comment.