From 63186e4bdc43c27f39942624355e451496ccf23a Mon Sep 17 00:00:00 2001 From: Ching Date: Fri, 4 Mar 2022 17:19:07 +0800 Subject: [PATCH] =?UTF-8?q?feat(dockerfile;=20run):=20=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=20dockerfile=20=E8=84=9A=E6=9C=AC=EF=BC=9Bchrome=20=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=20headless=20=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修改 dockerfile 脚本;chrome 使用 headless 参数 Signed-off-by: Ching --- .gitignore | 2 ++ Dockerfile | 5 ++--- last_id.txt | 3 +++ main.py | 7 ++++++- run.sh | 3 ++- 5 files changed, 15 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index f8b73e7..5745d50 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,8 @@ __pycache__/ # C extensions *.so +last_id.txt + # Distribution / packaging .Python build/ diff --git a/Dockerfile b/Dockerfile index 99a0c15..677be5d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,11 +1,10 @@ FROM selenium/standalone-chrome -ADD . /app - +COPY . /app WORKDIR /app RUN sudo apt update RUN sudo apt install -y python3-pip RUN pip3 install -r requirements.txt -CMD ["python3", "main.py"] +ENTRYPOINT ["python3", "main.py"] diff --git a/last_id.txt b/last_id.txt index 1c89816..791b53f 100644 --- a/last_id.txt +++ b/last_id.txt @@ -1,2 +1,5 @@ 107896829133801546 107897040775908429 +107897463271547378 +107897497559464026 +107897507395948056 diff --git a/main.py b/main.py index 097c5a8..f5a2fc6 100644 --- a/main.py +++ b/main.py @@ -2,6 +2,7 @@ from mastodon import Mastodon import argparse from selenium import webdriver from selenium.webdriver.common.by import By +from selenium.webdriver.chrome.options import Options import time @@ -18,7 +19,11 @@ def post_fanfou(webdrive_, fanfou_status, images=None): pass def run(instance, access_token, fanfou_account, fanfou_password): - chrome = webdriver.Chrome() + chrome_options = Options() + chrome_options.add_argument('--headless') + chrome_options.add_argument('--no-sandbox') + chrome_options.add_argument('--disable-dev-shm-usage') + chrome = webdriver.Chrome(chrome_options=chrome_options) # login to fanfou chrome.get('https://m.fanfou.com/') login_name = chrome.find_element(by=By.NAME, value='loginname') diff --git a/run.sh b/run.sh index a0fd671..1be2e82 100755 --- a/run.sh +++ b/run.sh @@ -1,4 +1,5 @@ #!/bin/sh source ./env.sh -docker build -t $YOUR_CONTAINER_NAME .; docker container run -it -v $(pwd):/app $YOUR_CONTAINER_NAME --mastodon-token $M_TOKEN --mastodon-instance $M_INSTANCE --fanfou-account $FF_ACCOUNT --fanfou-password $FF_PASSWORD +docker build -t $YOUR_CONTAINER_NAME . +docker container run -it -v $(pwd):/app $YOUR_CONTAINER_NAME --mastodon-token $M_TOKEN --mastodon-instance $M_INSTANCE --fanfou-account $FF_ACCOUNT --fanfou-password $FF_PASSWORD