feat: tweet filter (v1.1.0)

master
wlt233 2 months ago
parent b5cd47758b
commit 8019920dfb

@ -6,7 +6,11 @@
"check_interval": 42,
"check_list": {
"1145141919": {
"url": "https://x.com/i/lists/1873731145141919810"
"url": "https://x.com/i/lists/1873731145141919810",
"filter": [
"only_image",
"only_origin"
]
}
}
}

@ -163,10 +163,21 @@ def check_new_tweets(tweets, url):
LATEST_TWEET_ID_DICT[url] = tweets[0]["rest_id"]
return []
def check_timeline(driver, url):
data = get_timeline(driver, url)
def filter_tweets(tweets, filter_list):
if "only_image" in filter_list:
tweets = [t for t in tweets if t["media"]]
if "only_origin" in filter_list:
tweets = [t for t in tweets if (not t["quoted"]) and (not t["retweeted"])]
return tweets
def check_timeline(driver, config):
data = get_timeline(driver, config["url"])
tweets = parse_timeline(data)
return check_new_tweets(tweets, url)
new_tweets = check_new_tweets(tweets, config["url"])
return filter_tweets(new_tweets, config["filter"])
@ -181,7 +192,7 @@ def main(config):
json_data = {}
check_list = config.get("check_list", [])
for group_id, group_config in check_list.items():
new_tweets = check_timeline(driver, group_config["url"])
new_tweets = check_timeline(driver, group_config)
if new_tweets:
json_data[group_id] = new_tweets

Loading…
Cancel
Save