-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
42 lines (36 loc) · 1.45 KB
/
main.py
File metadata and controls
42 lines (36 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# !/usr/bin/python3.8
# -*- coding: utf-8 -*-
# @Notes : restful 启动
from fastapi import FastAPI, Query
from pyunit_time import Time
from fastapi.middleware.cors import CORSMiddleware
from pydantic import BaseModel
app = FastAPI(title='时间抽取', description='基于规则抽取、时间抽取接口文档', version='1.0')
app.add_middleware(
CORSMiddleware,
allow_origins=['*'],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
class ResponseModal(BaseModel):
"""返回格式类型"""
msg: str = 'success'
code: int = 200
result: list = [
{
"baseDate": "获取文本认为的开始时间",
"key": "时间关键字",
"keyDate": "关键字分析出的时间"
}
]
@app.get('/unit/time', summary='时间提取接口', response_model=ResponseModal)
def py_time(current_time: str = Query(None, description='填写你认为的开始时间',
regex=r'[1-9]\d{3}-([0-9]|1[0-2])-([0-9]|[1-2][0-9]|3[0-1]) \d{1,2}:\d{1,2}:\d{1,2}',
title='2020-4-22 00:00:00'),
data: str = Query(..., description='输入要分析的语句', title='一个小时前')):
try:
time = Time(current_time=current_time, format_time='YYYY-MM-DD HH:mm:ss').parse(string=data)
return ResponseModal(result=time)
except Exception as e:
return ResponseModal(msg=str(e), code=0)