Skip to content

Commit

Permalink
feat: tags
Browse files Browse the repository at this point in the history
  • Loading branch information
RanKKI committed May 10, 2023
1 parent 1ca7a35 commit 24e4d58
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 6 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
**/__cache__
**/.DS_Store
**/__pycache__
**/__pycache__
.venv/
28 changes: 24 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,30 @@
draft: true
---

本项目收集各类法律法规、部门规章、案例等,并将其按照章节等信息进行了处理。

## 应用

- [LawRefBook](https://github.com/RanKKI/LawRefBook) 是原生 iOS 应用,使用 SwiftUI 构建。

## 贡献指南
app 在设计的时候将法律法规和 app 本身分离开了, 只需要增加法条和修改 data.json 即可添加某部法律..
- 首先将法律法规按照 [法律法规模版](法律法规模版.md) 排版好,放入文件夹 `法律法规` 下合适的位置
- 使用脚本 `python3 scripts/update.py` (脚本会自动处理,将新增法律加入列表以及合适的位置)
- 提交更改,并提 pr

### 手动贡献

- 根据[法律法规模版](法律法规模版.md) 的格式,将法律法规放入 `法律法规` 文件夹下合适的位置
-`scripts` 目录下运行 `python database.py`(会自动更新 `sqlite` 内容)
- 提交更改,并提 pr

### 自动脚本

`scripts` 目录下有一 `request.py` 脚本,支持从 [国家法律法规数据库](https://flk.npc.gov.cn) 爬取最新的法律法规。

`scripts` 目录下,执行以下指令

- `python requessts.py` (脚本会自动处理,将新增法律加入列表以及合适的位置)
- `python database.py` (会自动更新 `sqlite` 内容)
- 提交更改,并提 pr

---

PS 如果你有发现某部法律不完整,有问题,或者需要新增某些,但又不会自己提 pr,你可以在提一个 issue,或者直接联系设置中我的邮箱,我会在下个版本修复或增加
Binary file modified db.sqlite3
Binary file not shown.
12 changes: 12 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
beautifulsoup4==4.12.2
certifi==2023.5.7
charset-normalizer==3.1.0
idna==3.4
jieba==0.42.1
lxml==4.9.2
peewee==3.16.2
Pillow==9.5.0
python-docx==0.8.11
requests==2.30.0
soupsieve==2.4.1
urllib3==2.0.2
4 changes: 3 additions & 1 deletion scripts/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ class Law(BaseModel):
order = peewee.IntegerField(null=True)
ver = peewee.IntegerField(null=False, default=0)

tags = peewee.TextField(null=True)

category_id = peewee.ForeignKeyField(Category, backref="laws")

def __repr__(self) -> str:
Expand Down Expand Up @@ -79,7 +81,7 @@ def get_laws(self, name: str = None, publish_at: datetime | str = None) -> List[
publish_at = publish_at.strftime('%Y-%m-%d')
expr = None
if name:
expr = Law.name == name
expr = (Law.name == name) | (Law.subtitle == name)
if publish_at:
expr = expr & (Law.publish == publish_at)
if expr:
Expand Down
25 changes: 25 additions & 0 deletions scripts/extract_tags.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import re
from pathlib import Path

from database import get_laws, law_db
import jieba.analyse

BASE_PATH = Path("../")

def main():
for folder, f in get_laws():
file_path = BASE_PATH / folder / f"{f}.md"
if "案例" not in str(file_path):
continue
sentence = file_path.read_text(encoding="utf-8")
seg_list = jieba.analyse.textrank(sentence, topK=10, withWeight=False, allowPOS=('n', 'nz', 'nt', 'nw'))
exist_laws = law_db.get_laws(file_path.stem)
if not exist_laws:
continue
law = exist_laws[0]
law.tags = ",".join(seg_list)
law.save()


if __name__ == "__main__":
main()

0 comments on commit 24e4d58

Please sign in to comment.