neurostats-API 0.0.4__tar.gz → 0.0.5__tar.gz

Sign up to get free protection for your applications and to get access to all the features.
Files changed (31) hide show
  1. {neurostats_API-0.0.4 → neurostats_api-0.0.5}/PKG-INFO +1 -1
  2. neurostats_api-0.0.5/neurostats_API/__init__.py +1 -0
  3. {neurostats_API-0.0.4 → neurostats_api-0.0.5}/neurostats_API/fetchers/base.py +2 -5
  4. {neurostats_API-0.0.4 → neurostats_api-0.0.5}/neurostats_API/fetchers/finance_overview.py +2 -2
  5. {neurostats_API-0.0.4 → neurostats_api-0.0.5}/neurostats_API/fetchers/tech.py +2 -3
  6. {neurostats_API-0.0.4 → neurostats_api-0.0.5}/neurostats_API/fetchers/value_invest.py +2 -2
  7. {neurostats_API-0.0.4 → neurostats_api-0.0.5}/neurostats_API/utils/__init__.py +1 -1
  8. neurostats_api-0.0.5/neurostats_API/utils/db_client.py +16 -0
  9. {neurostats_API-0.0.4 → neurostats_api-0.0.5}/neurostats_API/utils/fetcher.py +2 -3
  10. {neurostats_API-0.0.4 → neurostats_api-0.0.5}/neurostats_API.egg-info/PKG-INFO +2 -2
  11. {neurostats_API-0.0.4 → neurostats_api-0.0.5}/setup.py +1 -1
  12. {neurostats_API-0.0.4 → neurostats_api-0.0.5}/test/test_fetchers.py +8 -7
  13. neurostats_API-0.0.4/neurostats_API/__init__.py +0 -1
  14. neurostats_API-0.0.4/neurostats_API/utils/db_client.py +0 -10
  15. {neurostats_API-0.0.4 → neurostats_api-0.0.5}/MANIFEST.in +0 -0
  16. {neurostats_API-0.0.4 → neurostats_api-0.0.5}/README.md +0 -0
  17. {neurostats_API-0.0.4 → neurostats_api-0.0.5}/neurostats_API/cli.py +0 -0
  18. {neurostats_API-0.0.4 → neurostats_api-0.0.5}/neurostats_API/fetchers/__init__.py +0 -0
  19. {neurostats_API-0.0.4 → neurostats_api-0.0.5}/neurostats_API/fetchers/balance_sheet.py +0 -0
  20. {neurostats_API-0.0.4 → neurostats_api-0.0.5}/neurostats_API/fetchers/month_revenue.py +0 -0
  21. {neurostats_API-0.0.4 → neurostats_api-0.0.5}/neurostats_API/fetchers/profit_lose.py +0 -0
  22. {neurostats_API-0.0.4 → neurostats_api-0.0.5}/neurostats_API/main.py +0 -0
  23. {neurostats_API-0.0.4 → neurostats_api-0.0.5}/neurostats_API/tools/finance_overview_dict.yaml +0 -0
  24. {neurostats_API-0.0.4 → neurostats_api-0.0.5}/neurostats_API/tools/profit_lose.yaml +0 -0
  25. {neurostats_API-0.0.4 → neurostats_api-0.0.5}/neurostats_API/tools/seasonal_data_field_dict.txt +0 -0
  26. {neurostats_API-0.0.4 → neurostats_api-0.0.5}/neurostats_API/utils/data_process.py +0 -0
  27. {neurostats_API-0.0.4 → neurostats_api-0.0.5}/neurostats_API/utils/datetime.py +0 -0
  28. {neurostats_API-0.0.4 → neurostats_api-0.0.5}/neurostats_API.egg-info/SOURCES.txt +0 -0
  29. {neurostats_API-0.0.4 → neurostats_api-0.0.5}/neurostats_API.egg-info/dependency_links.txt +0 -0
  30. {neurostats_API-0.0.4 → neurostats_api-0.0.5}/neurostats_API.egg-info/top_level.txt +0 -0
  31. {neurostats_API-0.0.4 → neurostats_api-0.0.5}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: neurostats_API
3
- Version: 0.0.4
3
+ Version: 0.0.5
4
4
  Summary: The service of NeuroStats website
5
5
  Home-page: https://github.com/NeurowattStats/NeuroStats_API.git
6
6
  Author: JasonWang@Neurowatt
@@ -0,0 +1 @@
1
+ __version__='0.0.5'
@@ -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
@@ -0,0 +1,16 @@
1
+ import os
2
+ from pymongo import MongoClient
3
+ from dotenv import load_dotenv
4
+
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
13
+
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
- Name: neurostats-API
3
- Version: 0.0.4
2
+ Name: neurostats_API
3
+ Version: 0.0.5
4
4
  Summary: The service of NeuroStats website
5
5
  Home-page: https://github.com/NeurowattStats/NeuroStats_API.git
6
6
  Author: JasonWang@Neurowatt
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
2
2
 
3
3
  setup(
4
4
  name='neurostats_API',
5
- version='0.0.4',
5
+ version='0.0.5',
6
6
  long_description=open('README.md', 'r', encoding='utf-8').read(),
7
7
  long_description_content_type='text/markdown',
8
8
  install_requires=[
@@ -1,12 +1,13 @@
1
1
  import pytest
2
2
  import pandas as pd
3
3
  import yaml
4
- from neurostats_API.utils import StatsProcessor
4
+ from neurostats_API.utils import StatsProcessor, DBClient
5
5
 
6
+ db_client = DBClient("mongodb://neurowatt:neurodb123@db.neurowatt.ai:27017/neurowatt").get_client()
6
7
 
7
8
  def test_value():
8
9
  from neurostats_API.fetchers import ValueFetcher
9
- fetcher = ValueFetcher(ticker='2330')
10
+ fetcher = ValueFetcher(ticker='2330', db_client=db_client)
10
11
 
11
12
  fetched_data = fetcher.query_data()
12
13
 
@@ -19,7 +20,7 @@ def test_value():
19
20
  def test_profit_lose():
20
21
  from neurostats_API.utils import StatsFetcher
21
22
 
22
- fetcher = StatsFetcher()
23
+ fetcher = StatsFetcher(db_client)
23
24
 
24
25
  data = fetcher.get_profit_lose("2330")
25
26
 
@@ -31,7 +32,7 @@ def test_profit_lose():
31
32
  def test_cash_flow():
32
33
  from neurostats_API.utils import StatsFetcher
33
34
 
34
- fetcher = StatsFetcher()
35
+ fetcher = StatsFetcher(db_client)
35
36
  data = fetcher.get_cash_flow("2330")
36
37
 
37
38
  assert("cash_flow" in data.keys())
@@ -39,7 +40,7 @@ def test_cash_flow():
39
40
  def test_month_revenue():
40
41
  from neurostats_API.utils import StatsFetcher
41
42
 
42
- fetcher = StatsFetcher()
43
+ fetcher = StatsFetcher(db_client)
43
44
  data = fetcher.get_month_revenue_sheet("2330")
44
45
 
45
46
  assert("month_revenue" in data.keys())
@@ -47,7 +48,7 @@ def test_month_revenue():
47
48
  def test_balance_sheet():
48
49
  from neurostats_API.utils import StatsFetcher
49
50
 
50
- fetcher = StatsFetcher()
51
+ fetcher = StatsFetcher(db_client)
51
52
 
52
53
  data = fetcher.get_balance_sheet("2330")
53
54
 
@@ -57,7 +58,7 @@ def test_balance_sheet():
57
58
 
58
59
  def test_finance_overview():
59
60
  from neurostats_API.fetchers import FinanceOverviewFetcher
60
- fetcher = FinanceOverviewFetcher(ticker='2330')
61
+ fetcher = FinanceOverviewFetcher(ticker='2330', db_client=db_client)
61
62
  fetched_data = fetcher.query_data()
62
63
 
63
64
  expected_keys = [
@@ -1 +0,0 @@
1
- __version__='0.0.4'
@@ -1,10 +0,0 @@
1
- import os
2
- from pymongo import MongoClient
3
- from dotenv import load_dotenv
4
-
5
- # 載入 .env 檔案
6
- load_dotenv()
7
-
8
- # 創建並共享 MongoClient 連線
9
- mongo_uri = os.getenv('MONGO_URI', 'mongodb://localhost:27017')
10
- shared_client = MongoClient(mongo_uri)
File without changes
File without changes