commit 37bab39059d10ec3c92cb5c91aa7cdbc632c46ec Author: heshunme Date: Fri Nov 29 16:09:42 2024 +0800 爬虫搞定,100篇文章有了 diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..3a86cee --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# 默认忽略的文件 +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/PsycologyAPI.iml b/.idea/PsycologyAPI.iml new file mode 100644 index 0000000..d0876a7 --- /dev/null +++ b/.idea/PsycologyAPI.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..067e287 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,54 @@ + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..63337c1 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,32 @@ + + + + + + + + + + EditorConfig + + + GitHub 操作 + + + 正则表达式 + + + 版本控制 + + + + + 用户定义 + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..6b96f60 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/db.sqlite3 b/db.sqlite3 new file mode 100644 index 0000000..f9ae210 Binary files /dev/null and b/db.sqlite3 differ diff --git a/main.py b/main.py new file mode 100644 index 0000000..6d7c6d9 --- /dev/null +++ b/main.py @@ -0,0 +1,13 @@ +from fastapi import FastAPI + +app = FastAPI() + + +@app.get("/") +async def root(): + return {"message": "Hello World"} + + +@app.get("/hello/{name}") +async def say_hello(name: str): + return {"message": f"Hello {name}"} diff --git a/models/__init__.py b/models/__init__.py new file mode 100644 index 0000000..d57dc0a --- /dev/null +++ b/models/__init__.py @@ -0,0 +1,10 @@ +# -*- coding: utf-8 -*- +# @Time : 2024/11/13 下午3:10 +# @Author : 河瞬 +# @FileName: __init__.py.py +# @Software: PyCharm + +from .source import Source +from .category import Category +from .raw_data import RawData +from .processed_data import ProcessedData diff --git a/models/category.py b/models/category.py new file mode 100644 index 0000000..886b408 --- /dev/null +++ b/models/category.py @@ -0,0 +1,16 @@ +# -*- coding: utf-8 -*- +# @Time : 2024/11/14 下午4:04 +# @Author : 河瞬 +# @FileName: category.py +# @Software: PyCharm +from tortoise.models import Model +from tortoise import fields + + +class Category(Model): + id = fields.IntField(primary_key=True) + name = fields.TextField() + description = fields.TextField() + # 这个类别是有分层类似树状结构的,所以需要一个field来表示父类和子类 + parent = fields.ForeignKeyField("models.Category", related_name="children", null=True) + children = fields.ReverseRelation["Category"] diff --git a/models/processed_data.py b/models/processed_data.py new file mode 100644 index 0000000..351817c --- /dev/null +++ b/models/processed_data.py @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- +# @Time : 2024/11/14 下午4:02 +# @Author : 河瞬 +# @FileName: processed_data.py +# @Software: PyCharm +from tortoise.models import Model +from tortoise import fields + + +class ProcessedData(Model): + id = fields.IntField(primary_key=True) + raw_data = fields.ForeignKeyField("models.RawData", related_name="processed_data") + category = fields.ForeignKeyField("models.Category", related_name="processed_data") + summary = fields.TextField() + processed_at = fields.DatetimeField(auto_now_add=True) diff --git a/models/raw_data.py b/models/raw_data.py new file mode 100644 index 0000000..49d071e --- /dev/null +++ b/models/raw_data.py @@ -0,0 +1,18 @@ +# -*- coding: utf-8 -*- +# @Time : 2024/11/13 下午3:38 +# @Author : 河瞬 +# @FileName: raw_data.py +# @Software: PyCharm +from tortoise.models import Model +from tortoise import fields + + +class RawData(Model): + id = fields.IntField(primary_key=True) + url = fields.TextField() + title = fields.TextField() + content = fields.TextField(null=True) + source = fields.ForeignKeyField("models.Source", related_name="raw_data") + detected_at = fields.DatetimeField(auto_now_add=True) + fetched_at = fields.DatetimeField(auto_now=True) + is_processed = fields.BooleanField(default=False) diff --git a/models/source.py b/models/source.py new file mode 100644 index 0000000..0a1f500 --- /dev/null +++ b/models/source.py @@ -0,0 +1,13 @@ +# -*- coding: utf-8 -*- +# @Time : 2024/11/14 下午3:54 +# @Author : 河瞬 +# @FileName: source.py +# @Software: PyCharm +from tortoise.models import Model +from tortoise import fields + + +class Source(Model): + id = fields.IntField(primary_key=True) + name = fields.TextField() + index_url = fields.TextField() diff --git a/test_main.http b/test_main.http new file mode 100644 index 0000000..a2d81a9 --- /dev/null +++ b/test_main.http @@ -0,0 +1,11 @@ +# Test your FastAPI endpoints + +GET http://127.0.0.1:8000/ +Accept: application/json + +### + +GET http://127.0.0.1:8000/hello/User +Accept: application/json + +###