import os
import requests
import datetime
import time
url = "https://api.followin.io/feed/list/recommended/news"
Data_folder = "/www/wwwroot/llmweb/xinwen1lian"
Data_folder2 = "/www/pachongFile/followinFile"
headers = {
"Accept": "application/json, text/plain, */*",
"Content-Type": "application/json",
"Origin": "https://followin.io",
"Referer": "https://followin.io/",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36"
}
def write(file_path,content):
with open(file_path,"a",encoding="UTF-8") as fp:
for f in content["data"]["list"]:
fp.write(f["title"]+"\n")
fp.write("时间:" + datetime.datetime.fromtimestamp(f["publish_time"] / 1000).strftime(
"%Y-%m-%d %H:%M") + "\n")
fp.write(f["content"].replace("\n", "")+"\n\n")
fp.close()
def param(page_index):
payload = {
"count": 20,
"last_source": "algo",
"only_important": False,
"page": page_index
}
if page_index != 1:
payload["last_cursor"]=last_cursor
return payload
return payload
def run():
payload = param(page_index)
response_content = requests.post(url,json=payload,headers=headers)
content = response_content.json()
write(file_path,content)
write(file_path2,content)
last_cursor = content["data"]["last_cursor"]
return last_cursor
f_path = os.path.join(Data_folder,"begin.txt")
with open(f_path,"a",encoding="UTF-8") as fp:
fp.write("hello")
while True:
file_path = os.path.join(Data_folder,"followin{}.txt".format(datetime.datetime.now().strftime("%Y%m%d%H%M%S")))
file_path2 = os.path.join(Data_folder2,"followin{}.txt".format(datetime.datetime.now().strftime("%Y%m%d%H%M%S")))
page_index = 1
for index in range(1,21):
last_cursor = run()
page_index += 1
if f_path:
os.remove(f_path)
f_path = file_path
time.sleep(60*60)