neurostats-API 0.0.4__py3-none-any.whl → 0.0.6__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
@@ -1 +1 @@
1
- __version__='0.0.4'
1
+ __version__='0.0.6'
@@ -5,14 +5,11 @@ import pytz
5
5
  from datetime import datetime, timedelta, date
6
6
  from ..utils import StatsDateTime, StatsProcessor
7
7
  import yaml
8
- from ..utils import shared_client
9
-
10
8
 
11
9
  class StatsFetcher:
12
-
13
- def __init__(self, ticker):
10
+ def __init__(self, ticker, db_client):
14
11
  self.ticker = ticker
15
- self.db = shared_client[
12
+ self.db = db_client[
16
13
  "company"] # Replace with your database name
17
14
  self.collection = self.db["twse_stats"]
18
15
 
@@ -11,8 +11,8 @@ class FinanceOverviewFetcher(StatsFetcher):
11
11
  對應iFa.ai -> 財務分析 -> 重要指標(finance_overview)
12
12
  """
13
13
 
14
- def __init__(self, ticker):
15
- super().__init__(ticker)
14
+ def __init__(self, ticker, db_client):
15
+ super().__init__(ticker, db_client)
16
16
 
17
17
  self.target_fields = StatsProcessor.load_yaml("finance_overview_dict.yaml")
18
18
  self.inverse_dict = StatsProcessor.load_txt("seasonal_data_field_dict.txt", json_load=True)
@@ -3,9 +3,8 @@ import pandas as pd
3
3
 
4
4
  class TechFetcher(StatsFetcher):
5
5
 
6
- def __init__(self, ticker:str):
7
- super().__init__()
8
- self.ticker = ticker
6
+ def __init__(self, ticker:str, db_client):
7
+ super().__init__(ticker, db_client)
9
8
  self.full_ohlcv = self._get_ohlcv()
10
9
  self.basic_indexes = ['SMA5', 'SMA20', 'SMA60', 'EMA5', 'EMA20',
11
10
  'EMA40', 'EMA12', 'EMA26', 'RSI7', 'RSI14',
@@ -6,8 +6,8 @@ from ..utils import StatsDateTime, StatsProcessor
6
6
 
7
7
  class ValueFetcher(StatsFetcher):
8
8
 
9
- def __init__(self, ticker: str):
10
- super().__init__(ticker)
9
+ def __init__(self, ticker: str, db_client):
10
+ super().__init__(ticker, db_client)
11
11
 
12
12
  def prepare_query(self, start_date, end_date):
13
13
  pipeline = super().prepare_query()
@@ -1,4 +1,4 @@
1
1
  from .datetime import StatsDateTime
2
- from .db_client import shared_client
2
+ from .db_client import DBClient
3
3
  from .data_process import StatsProcessor
4
4
  from .fetcher import StatsFetcher
@@ -2,9 +2,15 @@ import os
2
2
  from pymongo import MongoClient
3
3
  from dotenv import load_dotenv
4
4
 
5
- # 載入 .env 檔案
6
- load_dotenv()
5
+ class DBClient:
6
+ def __init__(self, mongo_uri):
7
+ """初始化時接收 MongoDB 連接 URI"""
8
+ self.client = MongoClient(mongo_uri)
9
+ self.db = self.client["twse_company"]
10
+
11
+ def get_client(self):
12
+ return self.client
7
13
 
8
- # 創建並共享 MongoClient 連線
9
- mongo_uri = os.getenv('MONGO_URI', 'mongodb://localhost:27017')
10
- shared_client = MongoClient(mongo_uri)
14
+ def get_collection(self, collection_name):
15
+ """返回指定名稱的集合"""
16
+ return self.db[collection_name]
@@ -1,4 +1,3 @@
1
- from .db_client import shared_client
2
1
  import pandas as pd
3
2
  import json
4
3
  import pytz
@@ -9,8 +8,8 @@ import yaml
9
8
 
10
9
  class StatsFetcher:
11
10
 
12
- def __init__(self):
13
- self.db = shared_client["company"] # Replace with your database name
11
+ def __init__(self, db_client):
12
+ self.db = db_client["company"] # Replace with your database name
14
13
  self.collection = self.db["twse_stats"]
15
14
 
16
15
  self.timezone = pytz.timezone("Asia/Taipei")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: neurostats-API
3
- Version: 0.0.4
3
+ Version: 0.0.6
4
4
  Summary: The service of NeuroStats website
5
5
  Home-page: https://github.com/NeurowattStats/NeuroStats_API.git
6
6
  Author: JasonWang@Neurowatt
@@ -118,9 +118,10 @@ data = stats_fetcher.query_data()
118
118
 
119
119
  ### 回傳月營收表
120
120
  ``` Python
121
- from neurostats_API.utils import StatsFetcher
121
+ from neurostats_API.utils import StatsFetcher, DBClient
122
+ db_client = DBClient("<連接的DB位置>").get_client()
122
123
  ticker = 2330 # 換成tw50內任意ticker
123
- fetcher = StatsFetcher()
124
+ fetcher = StatsFetcher(db_client)
124
125
  data = stats_fetcher.get_month_revenue_sheet(ticker)
125
126
  ```
126
127
 
@@ -170,9 +171,10 @@ YoY_10 None None ... None None
170
171
  ### 財務分析: 重要指標
171
172
  對應https://ifa.ai/tw-stock/2330/finance-overview
172
173
  ```Python
173
- from neurostats_API.fetchers import FinanceOverviewFetcher
174
+ from neurostats_API.utils import StatsFetcher, DBClient
175
+ db_client = DBClient("<連接的DB位置>").get_client()
174
176
  ticker = "2330"
175
- fetcher = FinanceOverviewFetcher(ticker = "2330")
177
+ fetcher = FinanceOverviewFetcher(ticker = "2330", db_client = db_client)
176
178
  data = fetcher.query_data()
177
179
  ```
178
180
 
@@ -253,8 +255,9 @@ markdown
253
255
 
254
256
  ### 損益表
255
257
  ```Python
256
- from neurostats_API.utils import StatsFetcher
257
- fetcher = StatsFetcher()
258
+ from neurostats_API.utils import StatsFetcher, DBClient
259
+ db_client = DBClient("<連接的DB位置>").get_client()
260
+ fetcher = StatsFetcher(db_client)
258
261
  ticker = 2330 # 換成tw50內任意ticker
259
262
  data = fetcher.get_profit_lose(ticker)
260
263
  ```
@@ -301,8 +304,9 @@ data = fetcher.get_profit_lose(ticker)
301
304
 
302
305
  ### 資產負債表
303
306
  ``` Python
304
- from neurostats_API.utils import StatsFetcher
305
- fetcher = StatsFetcher()
307
+ from neurostats_API.utils import StatsFetcher, DBClient
308
+ db_client = DBClient("<連接的DB位置>").get_client()
309
+ fetcher = StatsFetcher(db_client)
306
310
  ticker = 2330 # 換成tw50內任意ticker
307
311
  stats_fetcher.get_balance_sheet(ticker)
308
312
  ```
@@ -360,8 +364,9 @@ equity 1.094370e+09 53.3 ... 3.390706e+09 56.68
360
364
 
361
365
  ### 現金流量表
362
366
  ``` Python
363
- from neurostats_API.utils import StatsFetcher
364
- fetcher = StatsFetcher()
367
+ from neurostats_API.utils import StatsFetcher, DBClient
368
+ db_client = DBClient("<連接的DB位置>").get_client()
369
+ fetcher = StatsFetcher(db_client)
365
370
  ticker = 2330 # 換成tw50內任意ticker
366
371
  stats_fetcher.get_cash_flow(ticker)
367
372
  ```
@@ -1,23 +1,23 @@
1
- neurostats_API/__init__.py,sha256=NPQFEcbIrOIy8ny94U7Q-qMa0Plu6CXlbLuNwykqxyk,19
1
+ neurostats_API/__init__.py,sha256=zzMTjJY407ibU6_ATOPO8KibRVB3tyW9yO0tRYzjTqw,19
2
2
  neurostats_API/cli.py,sha256=UJSWLIw03P24p-gkBb6JSEI5dW5U12UvLf1L8HjQD-o,873
3
3
  neurostats_API/main.py,sha256=QcsfmWivg2Dnqw3MTJWiI0QvEiRs0VuH-BjwQHFCv00,677
4
4
  neurostats_API/fetchers/__init__.py,sha256=k-pPWen3gQNr6d6DPFEXP1Q6SPC6TGIuIFf8w6r75YQ,137
5
5
  neurostats_API/fetchers/balance_sheet.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
- neurostats_API/fetchers/base.py,sha256=OxSCzvr9k-VS1n62skcjkSuGaeTBEQ2wNWlSPfXVSGE,1692
7
- neurostats_API/fetchers/finance_overview.py,sha256=1D0k-beaXBZmBdSDgsZobLYvnMs1WtboGe_pW_38Atc,18287
6
+ neurostats_API/fetchers/base.py,sha256=NW2SFzrimyAIrdJx1LVmTazelyZOAtcj54kJKHc4Vaw,1662
7
+ neurostats_API/fetchers/finance_overview.py,sha256=_w5OzFQpzC7eL_S5iMtgrIhx5gcov9gKzc6XzFutEFU,18309
8
8
  neurostats_API/fetchers/month_revenue.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
9
  neurostats_API/fetchers/profit_lose.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
10
- neurostats_API/fetchers/tech.py,sha256=5XlIkiQvquRMpA-cFNlnb5_fDxVd8Hj3-ttZzbyZwuY,11396
11
- neurostats_API/fetchers/value_invest.py,sha256=o0ZliV5ZwMPTtDV5oBSoZC_pZgcT7CsKVM39HznZYR4,2864
10
+ neurostats_API/fetchers/tech.py,sha256=wH1kkqiETQhF0HAhk-UIiucnZ3EiL85Q-yMWCcVOiFM,11395
11
+ neurostats_API/fetchers/value_invest.py,sha256=tg8yELbVnTFTEclrwgXnCRW377KkcoLiP-Gk2pyM-9Y,2886
12
12
  neurostats_API/tools/finance_overview_dict.yaml,sha256=Vvf8bv23NwJP8Yyw8DPS8c0_jjT_Wctnnz51SHS4AeI,2335
13
13
  neurostats_API/tools/profit_lose.yaml,sha256=f8balMTcK9elMW0k1PtbZ_6kEobTQ51fcBzqpbMObkk,2086
14
14
  neurostats_API/tools/seasonal_data_field_dict.txt,sha256=KlIIdTTdbvUd9TSDE9-gpzk2jt2ck_LdisX8cnrWMD4,7869
15
- neurostats_API/utils/__init__.py,sha256=4av4zVMgUfsKY1Nb0TKOjOABt3gvgSRWsXaU-_PWttU,147
15
+ neurostats_API/utils/__init__.py,sha256=FTYKRFzW2XVXdnSHXnS3mQQaHlKF9xGqrMsgZZ2kroc,142
16
16
  neurostats_API/utils/data_process.py,sha256=AeDWS9eHlHRqzfDKph-14GXERtHLSMKijsIrzZ0pPPo,595
17
17
  neurostats_API/utils/datetime.py,sha256=I9CIgZdE5OMzUciOS5wvapOVEIrXG_0Qb6iDKfIod6c,574
18
- neurostats_API/utils/db_client.py,sha256=Q3oDIhUdVY8S9-Jd7KcZ5X8fj2kz90Yv4e0w3uo77Tw,249
19
- neurostats_API/utils/fetcher.py,sha256=EW7yA9LddX_fekYTCcfKB96URaetjzvqtE9aMLP8SPw,40957
20
- neurostats_API-0.0.4.dist-info/METADATA,sha256=bzpZPqN4jrCw6UE-C090nCaCvOgjYDlEEvQOq6gNrjY,20285
21
- neurostats_API-0.0.4.dist-info/WHEEL,sha256=bFJAMchF8aTQGUgMZzHJyDDMPTO3ToJ7x23SLJa1SVo,92
22
- neurostats_API-0.0.4.dist-info/top_level.txt,sha256=nSlQPMG0VtXivJyedp4Bkf86EOy2TpW10VGxolXrqnU,15
23
- neurostats_API-0.0.4.dist-info/RECORD,,
18
+ neurostats_API/utils/db_client.py,sha256=OYe6yazcR4Aa6jYmy47JrryUeh2NnKGqY2K_lSZe6i8,455
19
+ neurostats_API/utils/fetcher.py,sha256=VbrUhjA-GG5AyjPX2SHtFIbZM4dm3jo0RgZzuCbb_Io,40927
20
+ neurostats_API-0.0.6.dist-info/METADATA,sha256=cOomXaKrsCOt1V9ZRTuPgfLCzdWnw0fzWd7PkGKlo8U,20666
21
+ neurostats_API-0.0.6.dist-info/WHEEL,sha256=bFJAMchF8aTQGUgMZzHJyDDMPTO3ToJ7x23SLJa1SVo,92
22
+ neurostats_API-0.0.6.dist-info/top_level.txt,sha256=nSlQPMG0VtXivJyedp4Bkf86EOy2TpW10VGxolXrqnU,15
23
+ neurostats_API-0.0.6.dist-info/RECORD,,