-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from neutral-info/Develop-add_filters
Develop add filters
- Loading branch information
Showing
13 changed files
with
178 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,13 @@ | ||
TABLE_DICT = dict( | ||
News="vwNews", | ||
NewsPosition="NewsPosition", | ||
Position="position", | ||
Channel="channel", | ||
Producer="producer", | ||
) | ||
|
||
DATABASE_DICT = dict( | ||
News="JSON2", | ||
NewsPosition="JSON2", | ||
Position="JSON2", | ||
Channel="JSON2", | ||
Producer="JSON2", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
|
||
from api.v1.api import api_router | ||
from api.v1.api import api_router |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,31 @@ | ||
import typing | ||
|
||
from fastapi import APIRouter | ||
from loguru import logger | ||
from starlette.requests import Request | ||
|
||
from api.backend.responses import success_msg | ||
from api.tools import load | ||
from api.v1.schema.input import ItemTypeInput | ||
from api.v1.schema.items import ItemList | ||
|
||
router = APIRouter() | ||
|
||
|
||
@router.get("/item") | ||
async def get_data(itemtype: ItemTypeInput): | ||
def convert_lisdict2list( | ||
listdictdata: typing.List[typing.Dict[str, typing.Union[str]]] | ||
) -> typing.List[str]: | ||
convert_data = [] | ||
if itemtype == "Position": | ||
convert_data = ["時代力量", "國民黨", "民進黨", "親民黨", "民眾黨", "無立場"] | ||
elif itemtype == "Channel": | ||
convert_data = ["新聞", "社群論壇", "聊天", "部落格", "內容農場", "影音"] | ||
for d in listdictdata: | ||
for k in d: | ||
convert_data.append(d[k]) | ||
return convert_data | ||
|
||
|
||
@router.get("/item", response_model=ItemList) | ||
async def get_data(request: Request, itemtype: ItemTypeInput): | ||
raw_data = load.NID_items(dataset=itemtype) | ||
convert_data = convert_lisdict2list(raw_data) | ||
|
||
logger.info(f"get itemtype:{itemtype} data") | ||
return success_msg(convert_data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import typing | ||
from pydantic import BaseModel | ||
|
||
|
||
class ItemList(BaseModel): | ||
News: typing.List[str] |
Oops, something went wrong.