|
|
|
@ -1,3 +1,4 @@
|
|
|
|
|
from collections import defaultdict
|
|
|
|
|
import json
|
|
|
|
|
import time
|
|
|
|
|
from datetime import datetime
|
|
|
|
@ -112,7 +113,7 @@ def parse_entry(entry):
|
|
|
|
|
|
|
|
|
|
def parse_content(content):
|
|
|
|
|
tweet = content["itemContent"]["tweet_results"]["result"]
|
|
|
|
|
if not "rest_id" in tweet: tweet = tweet["tweet"]
|
|
|
|
|
while not "rest_id" in tweet: tweet = tweet["tweet"]
|
|
|
|
|
data = parse_tweet(tweet)
|
|
|
|
|
if "quoted_status_result" in tweet:
|
|
|
|
|
data["quoted"] = parse_tweet(tweet["quoted_status_result"]["result"])
|
|
|
|
@ -142,6 +143,8 @@ def parse_entities(entity):
|
|
|
|
|
return data
|
|
|
|
|
|
|
|
|
|
def parse_tweet(tweet):
|
|
|
|
|
# with open("tweet.json", "w") as f: json.dump(tweet, f)
|
|
|
|
|
while not "rest_id" in tweet: tweet = tweet["tweet"]
|
|
|
|
|
data = {
|
|
|
|
|
"rest_id": tweet["rest_id"],
|
|
|
|
|
"name": tweet["core"]["user_results"]["result"]["legacy"]["name"],
|
|
|
|
@ -213,13 +216,22 @@ def main(config):
|
|
|
|
|
password = config["password"] # 密码
|
|
|
|
|
driver = login(userid, username, password)
|
|
|
|
|
|
|
|
|
|
check_list = config.get("check_list", [])
|
|
|
|
|
check_interval = config.get("check_interval", 42)
|
|
|
|
|
check_interval_slow = config.get("check_interval_slow", 600)
|
|
|
|
|
slow_hours = config.get("slow_hours", [0, 1, 2, 3, 4, 5, 6])
|
|
|
|
|
last_check_time = defaultdict(lambda: 0.0)
|
|
|
|
|
|
|
|
|
|
while 1:
|
|
|
|
|
json_data = {}
|
|
|
|
|
check_list = config.get("check_list", [])
|
|
|
|
|
for group_id, group_config in check_list.items():
|
|
|
|
|
new_tweets = check_timeline(driver, group_config)
|
|
|
|
|
if new_tweets:
|
|
|
|
|
json_data[group_id] = new_tweets
|
|
|
|
|
group_interval = group_config.get("interval", check_interval)
|
|
|
|
|
|
|
|
|
|
if time.time() - last_check_time[group_id] > group_interval:
|
|
|
|
|
new_tweets = check_timeline(driver, group_config)
|
|
|
|
|
if new_tweets:
|
|
|
|
|
json_data[group_id] = new_tweets
|
|
|
|
|
last_check_time[group_id] = time.time()
|
|
|
|
|
|
|
|
|
|
if json_data:
|
|
|
|
|
pprint(json_data)
|
|
|
|
@ -228,11 +240,14 @@ def main(config):
|
|
|
|
|
except Exception as e:
|
|
|
|
|
logger.error(str(e))
|
|
|
|
|
|
|
|
|
|
time.sleep(config.get("check_interval", 42))
|
|
|
|
|
if datetime.now().hour in slow_hours:
|
|
|
|
|
time.sleep(check_interval_slow)
|
|
|
|
|
else:
|
|
|
|
|
time.sleep(check_interval)
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
with open("config.json", 'r') as f:
|
|
|
|
|
config = json.load(f)
|
|
|
|
|
main(config)
|
|
|
|
|
|
|
|
|
|
# with open("lovelive.json", 'r') as f: pprint(parse_timeline(json.load(f)))
|
|
|
|
|
# with open("lovelive.json", 'r', encoding="utf8") as f: pprint(parse_timeline(json.load(f)))
|
|
|
|
|