Example #1
0
 def marcapJob(marcapDtos: List[StockRunCrawling]) -> None:
     service: StockService = Locator.getInstance().get(StockService)
     logger = Logger("TaskService_marcapJob")
     for dto in marcapDtos:
         logger.info("#### schedule job start ####")
         logger.info("command" + dto.startDateStr + "~" + dto.endDateStr)
         dto.taskUniqueId = dto.taskId + dto.market+dto.startDateStr + dto.endDateStr + str(uuid.uuid4())
         if dto.isNow:
             dto.startDateStr = getNowDateStr()
             dto.endDateStr = getNowDateStr()
         logger.info("real:" + dto.startDateStr + "~" + dto.endDateStr)
     service.crawlingMarcapStockData(marcapDtos)
Example #2
0
async def startScheduler() -> None:
    taskScheduler: TaskScheduler = Locator.getInstance().get(TaskScheduler)
    taskScheduler.start()
Example #3
0
from fastapi import APIRouter

from app.module.locator import Locator

from app.service.UserService import UserService
from app.service.FactorService import FactorService
from app.model.dto import FactorDataResponse

router = APIRouter(prefix="/factor")
userService: UserService = Locator.getInstance().get(UserService)
factorService: FactorService = Locator.getInstance().get(FactorService)


@router.get("/get")
async def getFactorData(code: str, year: str, month: str,
                        source: str) -> FactorDataResponse:
    li = await factorService.getFactor(code, year, month, source)
    return FactorDataResponse(**{"list": li, "count": len(li)})
Example #4
0
from app.repo.FactorRepository import FactorRepository
from app.service.UserService import UserService
from app.service.TaskService import TaskService
from app.service.StockService import StockService
from app.service.FactorService import FactorService
from app.datasource.StockMongoDataSource import StockMongoDataSource
from app.datasource.FactorFileDataSource import FactorFileDataSource
from app.datasource.FactorMongoDataSource import FactorMongoDataSource
from app.datasource.FactorDartMongoDataSource import FactorDartMongoDataSource
from app.datasource.TaskMongoDataSource import TaskMongoDataSource
from app.router.socket.task import TaskSocketRouter
from app.router.socket.stock import StockSocketRouter
from app.router.socket.factor import FactorSocketRouter


locator = Locator.getInstance()
manager = ConnectionManager()

# DATASOURCE
stockMongoDataSource = StockMongoDataSource()
factorMongoDataSource = FactorMongoDataSource()
factorFileDataSource = FactorFileDataSource()
factorDartMongoDataSource = FactorDartMongoDataSource()
taskMongoDataSource = TaskMongoDataSource()

# REPOSITORY
tasksRepository = TasksRepository(taskMongoDataSource)
crawlerRepository = CrawlerRepository(stockMongoDataSource, tasksRepository)
stockRepository = StockRepository(stockMongoDataSource, tasksRepository)
factorRepository = FactorRepository(factorMongoDataSource, factorDartMongoDataSource, factorFileDataSource)
repositories = {
Example #5
0
from typing import Any, Optional
from fastapi import APIRouter, WebSocket, WebSocketDisconnect, status
import asyncio

from fastapi.params import Depends, Query
from app.module.socket.manager import ConnectionManager
from app.module.locator import Locator

from app.service.UserService import UserService
from uvicorn.config import logger

router = APIRouter()
userService: UserService = Locator.getInstance().get(UserService)
manager: ConnectionManager = Locator.getInstance().get(ConnectionManager)


async def get_token(
        websocket: WebSocket,
        token: Any = Query(None),
) -> Optional[str]:
    logger.info("TOKEN:" + str(token))
    if token is None or not userService.check_token(token):
        await websocket.close(code=status.WS_1008_POLICY_VIOLATION)
        return None
    return token


@router.websocket("/ws/{client_id}")
async def websocket_endpoint(
    websocket: WebSocket, client_id: int,
    token: Any = Depends(get_token)) -> None:
Example #6
0
from typing import Dict
from fastapi import APIRouter

from app.model.user import User, UserInDB
from fastapi import Depends, HTTPException
from fastapi.security import OAuth2PasswordRequestForm
from app.datasource.UserDataSource import fake_users_db
from app.module.locator import Locator

from app.service.UserService import UserService

router = APIRouter(prefix="/user")
userService: UserService = Locator.getInstance().get(UserService)


@router.post("/token")
async def login(form_data: OAuth2PasswordRequestForm = Depends()) -> Dict:
    user_dict = fake_users_db.get(form_data.username)
    if not user_dict:
        raise HTTPException(status_code=400, detail="아이디 또는 비밀번호가 일치하지 않습니다")
    user = UserInDB(**user_dict)
    hashed_password = userService.fake_hash_password(form_data.password)
    if not hashed_password == user.hashed_password:
        raise HTTPException(status_code=400, detail="아이디 또는 비밀번호가 일치하지 않습니다")

    return {"access_token": user.username, "token_type": "bearer"}


@router.get("/me")
async def read_users_me(current_user: User = Depends(
    userService.get_current_active_user)) -> UserInDB:
Example #7
0
from fastapi import APIRouter

from app.module.locator import Locator

from app.service.UserService import UserService
from app.service.StockService import StockService
from app.model.dto import StockMarketCapitalResponse

router = APIRouter(prefix="/stock")
userService: UserService = Locator.getInstance().get(UserService)
stockService: StockService = Locator.getInstance().get(StockService)


@router.get("/marcap")
async def getStockData(market: str, startDate: str,
                       endDate: str) -> StockMarketCapitalResponse:
    li = await stockService.getStockData(market, startDate, endDate)
    return StockMarketCapitalResponse(**{"list": li, "count": len(li)})