From daf338c5bc4e22e465a82212aa4b497f59b0cc40 Mon Sep 17 00:00:00 2001 From: tsxc Date: Sun, 26 Jan 2025 15:58:23 +0800 Subject: [PATCH] =?UTF-8?q?=E8=84=9A=E6=9C=AC=E7=BC=96=E5=86=99=E5=AE=8C?= =?UTF-8?q?=E6=88=90=EF=BC=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 ++ Project.yml | 2 ++ libraries/__LIBRARY__.yml | 5 +++ pages/pages.yml | 10 ++++++ script.py | 64 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 84 insertions(+) create mode 100644 .gitignore create mode 100644 Project.yml create mode 100644 libraries/__LIBRARY__.yml create mode 100644 pages/pages.yml create mode 100644 script.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ecf61d6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +libraries/*.md +*.xaml +*.xml \ No newline at end of file diff --git a/Project.yml b/Project.yml new file mode 100644 index 0000000..023a8a7 --- /dev/null +++ b/Project.yml @@ -0,0 +1,2 @@ +version: 0.14.1 +default_page: pages \ No newline at end of file diff --git a/libraries/__LIBRARY__.yml b/libraries/__LIBRARY__.yml new file mode 100644 index 0000000..483c440 --- /dev/null +++ b/libraries/__LIBRARY__.yml @@ -0,0 +1,5 @@ +name: root +fill: + templates: + - MarkdownCard + - Raw \ No newline at end of file diff --git a/pages/pages.yml b/pages/pages.yml new file mode 100644 index 0000000..598f422 --- /dev/null +++ b/pages/pages.yml @@ -0,0 +1,10 @@ +name: pages +cards: + - page1 + - page2 + - page3 + - page4 + - page5 + - page6 + - page7 + - page8 diff --git a/script.py b/script.py new file mode 100644 index 0000000..ee061e6 --- /dev/null +++ b/script.py @@ -0,0 +1,64 @@ +import datetime +import requests +import xml.etree.ElementTree as ET +from dateutil.parser import parse +from markdownify import markdownify as md +import os + +response = requests.get("https://mc.boen.fun/feed") +os.open("feed.xml",os.O_CREAT) +with open("feed.xml","w",encoding='UTF-8') as f: + f.write(response.text) +tree =ET.parse("feed.xml") + +print(tree) +root = tree.getroot() + +# 删除所有临时文件 +for i in range(1,100): + try: + os.remove("libraries/"+"page"+str(i)+".md") + except: + pass + +os.open("pages/pages.yml",os.O_CREAT) +with open("pages/pages.yml","w",encoding='UTF-8') as f: + f.write("name: pages\ncards:\n") + +order=1 +for child in root: + for subchild in child: + if(subchild.tag == "item"): + for item in subchild: + # if(item.tag == "{http://purl.org/dc/elements/1.1/}creator"): + # print(item.text)# 作者 + # creator=item.text + if(item.tag == "title"): + print(item.text)# 标题 + title=item.text + if(item.tag == "pubDate"): + print(item.text)# 发布时间 + pubDate=item.text + if(item.tag == "link"): + # print(item.text)# 文章链接 + link=item.text + if(item.tag == "{http://purl.org/rss/1.0/modules/content/}encoded"): + # print(item.text)# 文章内容 + content=item.text + if(item.tag == "description"): + # print(item.text)# 文章描述 + description=item.text + print("=====================================") + pubDate=(parse(pubDate)+datetime.timedelta(hours=8)).strftime("%Y-%m-%d %H:%M:%S") + MDcontent=md(content) + os.open("libraries/"+"page"+str(order)+".md",os.O_CREAT) + with open("libraries/"+"page"+str(order)+".md","w",encoding='UTF-8') as f: + f.write("# "+title+"\n") + f.write("发布时间: "+pubDate+"\n") + f.write(MDcontent) + with open("pages/pages.yml","a",encoding='UTF-8') as f: + f.write(" - "+"page"+str(order)+"\n") + order+=1 + + +os.system("builder build") \ No newline at end of file