fix bug: login userid input & check new tweets failed (v1.6.1)

master
wlt233 3 months ago
parent 6fa28b46ee
commit 156b2d9dee

@ -1,6 +1,6 @@
from collections import defaultdict
import json
import time
from collections import defaultdict
from datetime import datetime
from pprint import pprint
@ -11,7 +11,6 @@ from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as ec
from selenium.webdriver.support.wait import WebDriverWait
USERID, USERNAME, PASSWORD = "", "", ""
def login():
global USERID, USERNAME, PASSWORD, DRIVER
@ -21,8 +20,9 @@ def login():
try:
options = webdriver.ChromeOptions()
options.set_capability("goog:loggingPrefs", {"performance": "ALL"})
# options.add_argument("--headless")
options.add_argument("--headless")
driver = webdriver.Chrome(options=options)
driver.set_page_load_timeout(30)
driver.get("https://x.com/i/flow/login")
WebDriverWait(driver, 10).until(
@ -34,10 +34,11 @@ def login():
WebDriverWait(driver, 10).until(
ec.presence_of_element_located((By.CSS_SELECTOR, 'input[autocomplete="on"]')))
username_field = driver.find_element(By.CSS_SELECTOR, 'input[autocomplete="on"]')
username_field.send_keys(USERID)
buttons = driver.find_elements(By.TAG_NAME, 'button')
buttons[1].click()
userid_field = driver.find_element(By.CSS_SELECTOR, 'input[autocomplete="on"]')
if not userid_field.get_attribute("value"):
userid_field.send_keys(USERID)
buttons = driver.find_elements(By.TAG_NAME, 'button')
buttons[1].click()
WebDriverWait(driver, 10).until(
ec.presence_of_element_located((By.CSS_SELECTOR, 'input[autocomplete="current-password"]')))
@ -191,19 +192,24 @@ def parse_tweet(tweet):
LATEST_TWEET_ID_DICT = {}
LATEST_TWEET_TS_DICT = {}
def check_new_tweets(tweets, url):
global LATEST_TWEET_ID_DICT
new_tweets = []
if url in LATEST_TWEET_ID_DICT:
new_tweets = []
for tweet in tweets:
if tweet["rest_id"] == LATEST_TWEET_ID_DICT[url]:
LATEST_TWEET_ID_DICT[url] = tweets[0]["rest_id"]
return new_tweets
break
if tweet["timestamp"] < LATEST_TWEET_TS_DICT[url]:
break
if time.time() - tweet["timestamp"] > 1200:
break
new_tweets.append(tweet)
LATEST_TWEET_ID_DICT[url] = tweets[0]["rest_id"]
return []
LATEST_TWEET_TS_DICT[url] = tweets[0]["timestamp"]
return new_tweets
def filter_tweets(tweets, filter_list):

Loading…
Cancel
Save