Skip to content

Commit 044aec8

Browse files
committed
2 parents f09a5ae + 3795bf8 commit 044aec8

3 files changed

Lines changed: 14 additions & 10 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
1. 登录 GitHub,进入你的项目仓库。
2020
2. 点击仓库的 `Settings` 选项卡。
21-
3. 在左侧菜单中找到 `Secrets` 部分,点击 `Actions`
21+
3. 在左侧菜单中找到 `Secrets and variables` 部分,点击 `Actions`
2222
4. 点击 `New repository secret` 按钮。
2323
5. 分别添加 `USERNAME``PASSWORD`
2424
-`Name` 字段中输入 `USERNAME`,在 `Value` 字段中输入你的 LinuxDo 用户名或者邮箱。

main.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
import os
2-
import time
32
import random
3+
import time
44

5-
from tabulate import tabulate
5+
from loguru import logger
66
from playwright.sync_api import sync_playwright
7-
7+
from tabulate import tabulate
88

99
USERNAME = os.environ.get("USERNAME")
1010
PASSWORD = os.environ.get("PASSWORD")
1111

12-
1312
HOME_URL = "https://linux.do/"
1413

1514

1615
class LinuxDoBrowser:
1716
def __init__(self) -> None:
1817
self.pw = sync_playwright().start()
19-
self.browser = self.pw.firefox.launch(headless=True)
18+
self.browser = self.pw.firefox.launch(headless=True, timeout=30000)
2019
self.context = self.browser.new_context()
2120
self.page = self.context.new_page()
2221
self.page.goto(HOME_URL)
2322

2423
def login(self):
24+
logger.info("Login")
2525
self.page.click(".login-button .d-button-label")
2626
time.sleep(2)
2727
self.page.fill("#login-account-name", USERNAME)
@@ -32,14 +32,15 @@ def login(self):
3232
time.sleep(10)
3333
user_ele = self.page.query_selector("#current-user")
3434
if not user_ele:
35-
print("Login failed")
35+
logger.error("Login failed")
3636
return False
3737
else:
38-
print("Check in success")
38+
logger.info("Login success")
3939
return True
4040

4141
def click_topic(self):
4242
for topic in self.page.query_selector_all("#list-area .title"):
43+
logger.info("Click topic: " + topic.get_attribute("href"))
4344
page = self.context.new_page()
4445
page.goto(HOME_URL + topic.get_attribute("href"))
4546
time.sleep(3)
@@ -55,10 +56,12 @@ def run(self):
5556
self.print_connect_info()
5657

5758
def click_like(self, page):
59+
logger.info("Click like")
5860
page.locator(".discourse-reactions-reaction-button").first.click()
59-
print("Like success")
61+
logger.info("Like success")
6062

6163
def print_connect_info(self):
64+
logger.info("Print connect info")
6265
page = self.context.new_page()
6366
page.goto("https://connect.linux.do/")
6467
rows = page.query_selector_all("table tr")

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
playwright==1.43.0
22
wcwidth==0.2.13
3-
tabulate==0.9.0
3+
tabulate==0.9.0
4+
loguru==0.7.2

0 commit comments

Comments
 (0)