neurostats-API 0.0.22__tar.gz → 0.0.23b1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. {neurostats_api-0.0.22 → neurostats_api-0.0.23b1}/PKG-INFO +2 -2
  2. {neurostats_api-0.0.22 → neurostats_api-0.0.23b1}/README.md +1 -1
  3. {neurostats_api-0.0.22 → neurostats_api-0.0.23b1}/neurostats_API/__init__.py +1 -1
  4. {neurostats_api-0.0.22 → neurostats_api-0.0.23b1}/neurostats_API/fetchers/tech.py +63 -26
  5. {neurostats_api-0.0.22 → neurostats_api-0.0.23b1}/neurostats_API/fetchers/tej_finance_report.py +5 -2
  6. {neurostats_api-0.0.22 → neurostats_api-0.0.23b1}/neurostats_API/tools/tej_db/tej_db_skip_index.yaml +12 -1
  7. {neurostats_api-0.0.22 → neurostats_api-0.0.23b1}/neurostats_API/tools/tej_db/tej_db_thousand_index.yaml +0 -4
  8. {neurostats_api-0.0.22 → neurostats_api-0.0.23b1}/neurostats_API.egg-info/PKG-INFO +2 -2
  9. {neurostats_api-0.0.22 → neurostats_api-0.0.23b1}/setup.py +1 -1
  10. {neurostats_api-0.0.22 → neurostats_api-0.0.23b1}/test/test_fetchers.py +2 -5
  11. {neurostats_api-0.0.22 → neurostats_api-0.0.23b1}/test/test_tej.py +2 -2
  12. {neurostats_api-0.0.22 → neurostats_api-0.0.23b1}/MANIFEST.in +0 -0
  13. {neurostats_api-0.0.22 → neurostats_api-0.0.23b1}/neurostats_API/cli.py +0 -0
  14. {neurostats_api-0.0.22 → neurostats_api-0.0.23b1}/neurostats_API/fetchers/__init__.py +0 -0
  15. {neurostats_api-0.0.22 → neurostats_api-0.0.23b1}/neurostats_API/fetchers/balance_sheet.py +0 -0
  16. {neurostats_api-0.0.22 → neurostats_api-0.0.23b1}/neurostats_API/fetchers/base.py +0 -0
  17. {neurostats_api-0.0.22 → neurostats_api-0.0.23b1}/neurostats_API/fetchers/cash_flow.py +0 -0
  18. {neurostats_api-0.0.22 → neurostats_api-0.0.23b1}/neurostats_API/fetchers/finance_overview.py +0 -0
  19. {neurostats_api-0.0.22 → neurostats_api-0.0.23b1}/neurostats_API/fetchers/institution.py +0 -0
  20. {neurostats_api-0.0.22 → neurostats_api-0.0.23b1}/neurostats_API/fetchers/margin_trading.py +0 -0
  21. {neurostats_api-0.0.22 → neurostats_api-0.0.23b1}/neurostats_API/fetchers/month_revenue.py +0 -0
  22. {neurostats_api-0.0.22 → neurostats_api-0.0.23b1}/neurostats_API/fetchers/profit_lose.py +0 -0
  23. {neurostats_api-0.0.22 → neurostats_api-0.0.23b1}/neurostats_API/fetchers/value_invest.py +0 -0
  24. {neurostats_api-0.0.22 → neurostats_api-0.0.23b1}/neurostats_API/main.py +0 -0
  25. {neurostats_api-0.0.22 → neurostats_api-0.0.23b1}/neurostats_API/tools/company_list/tw.json +0 -0
  26. {neurostats_api-0.0.22 → neurostats_api-0.0.23b1}/neurostats_API/tools/tej_db/tej_db_index.yaml +0 -0
  27. {neurostats_api-0.0.22 → neurostats_api-0.0.23b1}/neurostats_API/tools/tej_db/tej_db_percent_index.yaml +0 -0
  28. {neurostats_api-0.0.22 → neurostats_api-0.0.23b1}/neurostats_API/tools/twse/balance_sheet.yaml +0 -0
  29. {neurostats_api-0.0.22 → neurostats_api-0.0.23b1}/neurostats_API/tools/twse/cash_flow_percentage.yaml +0 -0
  30. {neurostats_api-0.0.22 → neurostats_api-0.0.23b1}/neurostats_API/tools/twse/finance_overview_dict.yaml +0 -0
  31. {neurostats_api-0.0.22 → neurostats_api-0.0.23b1}/neurostats_API/tools/twse/profit_lose.yaml +0 -0
  32. {neurostats_api-0.0.22 → neurostats_api-0.0.23b1}/neurostats_API/tools/twse/seasonal_data_field_dict.txt +0 -0
  33. {neurostats_api-0.0.22 → neurostats_api-0.0.23b1}/neurostats_API/utils/__init__.py +0 -0
  34. {neurostats_api-0.0.22 → neurostats_api-0.0.23b1}/neurostats_API/utils/calculate_value.py +0 -0
  35. {neurostats_api-0.0.22 → neurostats_api-0.0.23b1}/neurostats_API/utils/data_process.py +0 -0
  36. {neurostats_api-0.0.22 → neurostats_api-0.0.23b1}/neurostats_API/utils/datetime.py +0 -0
  37. {neurostats_api-0.0.22 → neurostats_api-0.0.23b1}/neurostats_API/utils/db_client.py +0 -0
  38. {neurostats_api-0.0.22 → neurostats_api-0.0.23b1}/neurostats_API.egg-info/SOURCES.txt +0 -0
  39. {neurostats_api-0.0.22 → neurostats_api-0.0.23b1}/neurostats_API.egg-info/dependency_links.txt +0 -0
  40. {neurostats_api-0.0.22 → neurostats_api-0.0.23b1}/neurostats_API.egg-info/requires.txt +0 -0
  41. {neurostats_api-0.0.22 → neurostats_api-0.0.23b1}/neurostats_API.egg-info/top_level.txt +0 -0
  42. {neurostats_api-0.0.22 → neurostats_api-0.0.23b1}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: neurostats_API
3
- Version: 0.0.22
3
+ Version: 0.0.23b1
4
4
  Summary: The service of NeuroStats website
5
5
  Home-page: https://github.com/NeurowattStats/NeuroStats_API.git
6
6
  Author: JasonWang@Neurowatt
@@ -89,7 +89,7 @@ pip install neurostats-API
89
89
  ```Python
90
90
  >>> import neurostats_API
91
91
  >>> print(neurostats_API.__version__)
92
- 0.0.22
92
+ 0.0.23b
93
93
  ```
94
94
 
95
95
  ### 得到最新一期的評價資料與歷年評價
@@ -73,7 +73,7 @@ pip install neurostats-API
73
73
  ```Python
74
74
  >>> import neurostats_API
75
75
  >>> print(neurostats_API.__version__)
76
- 0.0.22
76
+ 0.0.23b
77
77
  ```
78
78
 
79
79
  ### 得到最新一期的評價資料與歷年評價
@@ -1,4 +1,4 @@
1
- __version__='0.0.22'
1
+ __version__='0.0.23b'
2
2
 
3
3
  from .fetchers import (
4
4
  BalanceSheetFetcher,
@@ -13,7 +13,8 @@ class TechFetcher(StatsFetcher):
13
13
 
14
14
  super().__init__(ticker, db_client)
15
15
  if (ticker in self.tw_company_list.keys()):
16
- self.collection = self.db["TWN/APIPRCD"]
16
+ self.twse_collection = self.db['twse_stats']
17
+ self.tej_collection = self.db["TWN/APIPRCD"]
17
18
 
18
19
  self.full_ohlcv = self._get_ohlcv()
19
20
  self.basic_indexes = [
@@ -53,35 +54,47 @@ class TechFetcher(StatsFetcher):
53
54
 
54
55
  required_cols = ['date', 'open', 'high', 'low', 'close', 'volume']
55
56
 
56
- try:
57
- # 先對yf search
58
- if self.ticker in ['GSPC', 'IXIC', 'DJI', 'TWII']:
59
- full_tick = f'^{self.ticker}'
60
- elif(self.ticker in self.tw_company_list.keys()):
61
- full_tick = f'{self.ticker}.tw'
62
- else:
63
- full_tick = f"{self.ticker}"
64
-
57
+ if self.ticker in ['GSPC', 'IXIC', 'DJI', 'TWII']:
58
+ full_tick = f'^{self.ticker}'
65
59
  df = self.conduct_yf_search(full_tick)
66
60
 
67
- if (
68
- self.ticker in self.tw_company_list.keys() and
69
- not self.has_required_columns(df, required_cols)
70
- ):
71
- full_tick = f'{self.ticker}.two'
61
+ return df[required_cols]
72
62
 
73
- df = self.conduct_yf_search(full_tick)
63
+ elif(self.ticker in self.tw_company_list.keys()):
64
+ search_fns = [
65
+ self.conduct_db_search_twse,
66
+ self.conduct_db_search_tej,
67
+ lambda: self.conduct_yf_search(f'{self.ticker}.tw'),
68
+ lambda: self.conduct_yf_search(f'{self.ticker}.two')
69
+ ]
70
+
71
+ for search_method in search_fns:
72
+ try:
73
+ df = search_method()
74
+ break
75
+ except (KeyError, ValueError, TypeError):
76
+ continue
77
+ else:
78
+ return pd.DataFrame(columns=required_cols)
74
79
 
75
- if (df.empty):
76
- raise ValueError(f"No data found for ticker: {self.ticker}")\
77
-
80
+ # break跳出後
78
81
  return df[required_cols]
82
+ else: # 美股
83
+ search_fns = [
84
+ self.conduct_db_search_us,
85
+ lambda : self.conduct_yf_search(f"{self.ticker}")
86
+ ]
87
+ for search_method in search_fns:
88
+ try:
89
+ df = search_method()
90
+ break
91
+ except (KeyError, ValueError, TypeError):
92
+ continue
93
+ else:
94
+ df = pd.DataFrame()
79
95
 
80
- except (KeyError, ValueError, TypeError) as e:
81
- if (self.collection_name in ['TWN/APIPRCD']):
82
- return self.conduct_db_search_tej()
83
- elif (self.collection_name == 'us_stats'):
84
- return self.conduct_db_search_us()
96
+ return df
97
+
85
98
 
86
99
  def get_daily(self):
87
100
 
@@ -125,6 +138,31 @@ class TechFetcher(StatsFetcher):
125
138
  )
126
139
 
127
140
  return df
141
+
142
+
143
+ def conduct_db_search_twse(self):
144
+ required_cols = ['date', 'open', 'high', 'low', 'close', 'volume']
145
+ match_query = {"ticker" : self.ticker}
146
+ proj_query = {"_id": 0, "daily_data": 1}
147
+
148
+ full_data = self.twse_collection.find_one(match_query, proj_query)
149
+
150
+ if (not full_data):
151
+ raise ValueError("No ticker found in database twse_stats")
152
+
153
+ daily_data = full_data.get("daily_data", [])
154
+
155
+ if (not isinstance(daily_data, list)):
156
+ raise ValueError("No ticker found in database twse_stats")
157
+
158
+ df = pd.DataFrame(daily_data)
159
+ if not self.has_required_columns(df, required_cols):
160
+ raise KeyError(f"Missing required columns")
161
+
162
+ df = df[required_cols]
163
+ df = df.sort_values(by = 'date').drop_duplicates(subset=['date'])
164
+
165
+ return df
128
166
 
129
167
  def conduct_db_search_tej(self):
130
168
  # 再對TEJ search
@@ -139,7 +177,7 @@ class TechFetcher(StatsFetcher):
139
177
  }
140
178
 
141
179
  query = {'ticker': self.ticker}
142
- ticker_full = self.collection.find_one(query)
180
+ ticker_full = self.tej_collection.find_one(query)
143
181
 
144
182
  if not ticker_full:
145
183
  raise ValueError("No ticker found in database")
@@ -175,7 +213,6 @@ class TechFetcher(StatsFetcher):
175
213
  if not self.has_required_columns(df, required_cols):
176
214
  missing_cols = [col for col in required_cols if col not in df.columns]
177
215
  missing_cols = ",".join(missing_cols)
178
- print(Warning(f"{missing_cols} not in columns"))
179
216
  for col in missing_cols:
180
217
  df[col] = pd.NA
181
218
  # raise KeyError(f"Missing required columns")
@@ -176,7 +176,10 @@ class FinanceReportFetcher(BaseTEJFetcher):
176
176
  fetched_data = self.collection.aggregate(pipeline).to_list()
177
177
  data_dict = self.transform_value(
178
178
  StatsProcessor.list_of_dict_to_dict(
179
- fetched_data, ["year", "season"], "Q", report_type
179
+ data_list=fetched_data,
180
+ keys=["year", "season"],
181
+ delimeter="Q",
182
+ data_key=report_type
180
183
  )
181
184
  )
182
185
 
@@ -241,7 +244,7 @@ class FinanceReportFetcher(BaseTEJFetcher):
241
244
  "$gt": start_year,
242
245
  "$lt": end_year
243
246
  },
244
- "data.season": end_season
247
+ "data.season": start_season
245
248
  }
246
249
  else:
247
250
  match_stage = {
@@ -9,6 +9,13 @@ TWN/AINVFQ1:
9
9
  - annd
10
10
  - fin_ind
11
11
  - eps
12
+ - r307
13
+ - r305
14
+ - r306
15
+ - r316
16
+ - r609
17
+ - r614
18
+ - r611
12
19
  TWN/AFESTM1:
13
20
  - coid
14
21
  - mdate
@@ -19,4 +26,8 @@ TWN/AFESTM1:
19
26
  - curr
20
27
  - annd
21
28
  - fin_ind
22
- - eps
29
+ - eps
30
+ - r307
31
+ - r305
32
+ - r306
33
+ - r316
@@ -56,10 +56,6 @@ TWN/AINVFQ1:
56
56
  - person
57
57
  - shares
58
58
  - wavg
59
- - r304
60
- - r305
61
- - r306
62
- - r316
63
59
  - r834
64
60
  TWN/AFESTM1:
65
61
  - ip12
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: neurostats_API
3
- Version: 0.0.22
3
+ Version: 0.0.23b1
4
4
  Summary: The service of NeuroStats website
5
5
  Home-page: https://github.com/NeurowattStats/NeuroStats_API.git
6
6
  Author: JasonWang@Neurowatt
@@ -89,7 +89,7 @@ pip install neurostats-API
89
89
  ```Python
90
90
  >>> import neurostats_API
91
91
  >>> print(neurostats_API.__version__)
92
- 0.0.22
92
+ 0.0.23b
93
93
  ```
94
94
 
95
95
  ### 得到最新一期的評價資料與歷年評價
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
2
2
 
3
3
  setup(
4
4
  name='neurostats_API',
5
- version='0.0.22',
5
+ version='0.0.23b1',
6
6
  long_description=open('README.md', 'r', encoding='utf-8').read(),
7
7
  long_description_content_type='text/markdown',
8
8
  install_requires=[
@@ -12,10 +12,8 @@ pp = PrettyPrinter(
12
12
  indent=2
13
13
  )
14
14
 
15
- company_list = {
16
- "1260": "富味香",
17
- "AAPL": "APPLE.Inc"
18
- }
15
+ with open(f"./tw50_company_list.json") as f:
16
+ company_list = json.load(f)
19
17
  db_client = DBClient("mongodb://neurowatt:neurodb123@db.neurowatt.ai:27017/neurowatt").get_client()
20
18
 
21
19
  def test_value_serie():
@@ -113,7 +111,6 @@ def test_balance_sheet():
113
111
  from neurostats_API.fetchers import BalanceSheetFetcher
114
112
  company_list = {
115
113
  "2330": "台積電",
116
- "AAPL": "APPLE.Inc"
117
114
  }
118
115
  for ticker in company_list.keys():
119
116
 
@@ -23,7 +23,7 @@ def test_QoQ():
23
23
  fetch_mode = mode,
24
24
  start_date="2024-01-01",
25
25
  end_date="2024-12-31",
26
- indexes = ["eps"]
26
+ indexes = []
27
27
  )
28
28
  print(data)
29
29
  if (isinstance(data, dict)):
@@ -40,7 +40,7 @@ def test_YoY():
40
40
  ]
41
41
 
42
42
  for mode in modes:
43
- data = fetcher.get(ticker, mode, indexes = ["r405"])
43
+ data = fetcher.get(ticker, mode, indexes = ['r405'])
44
44
  print (data)
45
45
 
46
46
  def test_stock_price():