Skip to content

Commit

Permalink
🎨🔥 remove dead code & formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
kaixinol committed Nov 20, 2023
1 parent d99212f commit 5d4be38
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 15 deletions.
3 changes: 1 addition & 2 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ def get_tweet():
set_work_directory(Path(__file__).absolute().parent)
config.load({"proxy": {"http": "socks5://127.0.0.1:7890", "https": "socks5://127.0.0.1:7890"}, "max_threads": 2,
"header": {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, "
"like Gecko) "}
, "inject_js": "/media/Data/Project/twitter_user_tweet_crawler/script.js",
"like Gecko) "}, "inject_js": "/media/Data/Project/twitter_user_tweet_crawler/script.js",
"save": "/media/Data/Project/twitter_user_tweet_crawler/output/", }
)
from twitter_user_tweet_crawler.tweet import Tweet
Expand Down
5 changes: 1 addition & 4 deletions tests/CI.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import unittest
from time import sleep

from selenium import webdriver
from selenium.webdriver.chrome.webdriver import WebDriver
from selenium.webdriver.common.by import By

from twitter_user_tweet_crawler.browser import get_browser
from twitter_user_tweet_crawler.util.config import config

config.load({"proxy": None, "max_threads": 2,
"header": {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, "
"like Gecko) "}
, "inject_js": "script.js",
"like Gecko) "}, "inject_js": "script.js",
}
)

Expand Down
2 changes: 1 addition & 1 deletion twitter_user_tweet_crawler/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def get_items_need_handle():
cookie = driver.get_cookies()
for drivers in work_list:
set_cookie(drivers)
driver.get("https://twitter.com/"+ config.user)
driver.get("https://twitter.com/" + config.user)
data_dict = {}
pool = ThreadPool(work_list, tweet_executor)

Expand Down
6 changes: 1 addition & 5 deletions twitter_user_tweet_crawler/browser.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
from selenium import webdriver
from selenium.webdriver.chrome.webdriver import WebDriver

from twitter_user_tweet_crawler.util.config import config

browsers = 0


def get_browser(headless: bool = False, id=None) -> WebDriver:
global browsers
def get_browser(headless: bool = False) -> WebDriver:
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--blink-settings=imagesEnabled=false')
chrome_options.add_argument('--disable-remote-fonts')
Expand Down
8 changes: 5 additions & 3 deletions twitter_user_tweet_crawler/tweet.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
from datetime import datetime
from pathlib import Path
from time import sleep
from urllib.parse import quote, urlparse

from emoji import is_emoji
from html2text import html2text
from loguru import logger
from requests import get
from rich.console import Console
from rich.markdown import Markdown
from rich.table import Table
Expand All @@ -15,10 +17,9 @@
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait
from urllib.parse import quote, urlparse

from .util.config import config
from .util.sql import insert_new_record, is_id_exists
from requests import get

inject: str
inject_js = config.inject_js
Expand Down Expand Up @@ -47,7 +48,7 @@ def __init__(self, link: str):
self.via_app = None
self.location = None

@logger.catch()
@logger.catch
def download_res(self, url: str, path: str):
with open(Path(config.save) / 'res' / path, 'wb') as fp:
fp.write(get(url, proxies=config.proxy, headers=config.header).content)
Expand Down Expand Up @@ -101,6 +102,7 @@ def get_img():
self.img = available_driver.execute_script("return document.fileName;")

def click_sensitive_element():
# TODO
try:
items = available_driver.find_element(By.XPATH, "//span[text()='查看']")
ActionChains(available_driver).move_to_element(i).click().perform()
Expand Down

0 comments on commit 5d4be38

Please sign in to comment.