db2_hj3415 0.1.10__tar.gz → 0.1.11__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.
- {db2_hj3415-0.1.10 → db2_hj3415-0.1.11}/PKG-INFO +1 -1
- {db2_hj3415-0.1.10 → db2_hj3415-0.1.11}/db2_hj3415/nfs/c108.py +18 -9
- {db2_hj3415-0.1.10 → db2_hj3415-0.1.11}/pyproject.toml +1 -1
- {db2_hj3415-0.1.10 → db2_hj3415-0.1.11}/README.md +0 -0
- {db2_hj3415-0.1.10 → db2_hj3415-0.1.11}/db2_hj3415/__init__.py +0 -0
- {db2_hj3415-0.1.10 → db2_hj3415-0.1.11}/db2_hj3415/cli/__init__.py +0 -0
- {db2_hj3415-0.1.10 → db2_hj3415-0.1.11}/db2_hj3415/cli/db.py +0 -0
- {db2_hj3415-0.1.10 → db2_hj3415-0.1.11}/db2_hj3415/common/__init__.py +0 -0
- {db2_hj3415-0.1.10 → db2_hj3415-0.1.11}/db2_hj3415/common/connection.py +0 -0
- {db2_hj3415-0.1.10 → db2_hj3415-0.1.11}/db2_hj3415/common/db_ops.py +0 -0
- {db2_hj3415-0.1.10 → db2_hj3415-0.1.11}/db2_hj3415/common/utils.py +0 -0
- {db2_hj3415-0.1.10 → db2_hj3415-0.1.11}/db2_hj3415/mi/__init__.py +0 -0
- {db2_hj3415-0.1.10 → db2_hj3415-0.1.11}/db2_hj3415/mi/_ops.py +0 -0
- {db2_hj3415-0.1.10 → db2_hj3415-0.1.11}/db2_hj3415/mi/aud.py +0 -0
- {db2_hj3415-0.1.10 → db2_hj3415-0.1.11}/db2_hj3415/mi/chf.py +0 -0
- {db2_hj3415-0.1.10 → db2_hj3415-0.1.11}/db2_hj3415/mi/gbond3y.py +0 -0
- {db2_hj3415-0.1.10 → db2_hj3415-0.1.11}/db2_hj3415/mi/gold.py +0 -0
- {db2_hj3415-0.1.10 → db2_hj3415-0.1.11}/db2_hj3415/mi/kosdaq.py +0 -0
- {db2_hj3415-0.1.10 → db2_hj3415-0.1.11}/db2_hj3415/mi/kospi.py +0 -0
- {db2_hj3415-0.1.10 → db2_hj3415-0.1.11}/db2_hj3415/mi/silver.py +0 -0
- {db2_hj3415-0.1.10 → db2_hj3415-0.1.11}/db2_hj3415/mi/sp500.py +0 -0
- {db2_hj3415-0.1.10 → db2_hj3415-0.1.11}/db2_hj3415/mi/usdidx.py +0 -0
- {db2_hj3415-0.1.10 → db2_hj3415-0.1.11}/db2_hj3415/mi/usdkrw.py +0 -0
- {db2_hj3415-0.1.10 → db2_hj3415-0.1.11}/db2_hj3415/mi/wti.py +0 -0
- {db2_hj3415-0.1.10 → db2_hj3415-0.1.11}/db2_hj3415/nfs/__init__.py +0 -0
- {db2_hj3415-0.1.10 → db2_hj3415-0.1.11}/db2_hj3415/nfs/_c10346.py +0 -0
- {db2_hj3415-0.1.10 → db2_hj3415-0.1.11}/db2_hj3415/nfs/_ops.py +0 -0
- {db2_hj3415-0.1.10 → db2_hj3415-0.1.11}/db2_hj3415/nfs/c101.py +0 -0
- {db2_hj3415-0.1.10 → db2_hj3415-0.1.11}/db2_hj3415/nfs/c103.py +0 -0
- {db2_hj3415-0.1.10 → db2_hj3415-0.1.11}/db2_hj3415/nfs/c104.py +0 -0
- {db2_hj3415-0.1.10 → db2_hj3415-0.1.11}/db2_hj3415/nfs/c106.py +0 -0
- {db2_hj3415-0.1.10 → db2_hj3415-0.1.11}/db2_hj3415/nfs/dart.py +0 -0
- {db2_hj3415-0.1.10 → db2_hj3415-0.1.11}/db2_hj3415/nfs/models.py +0 -0
- {db2_hj3415-0.1.10 → db2_hj3415-0.1.11}/db2_hj3415/valuation/__init__.py +0 -0
- {db2_hj3415-0.1.10 → db2_hj3415-0.1.11}/db2_hj3415/valuation/_ops.py +0 -0
- {db2_hj3415-0.1.10 → db2_hj3415-0.1.11}/db2_hj3415/valuation/blue.py +0 -0
- {db2_hj3415-0.1.10 → db2_hj3415-0.1.11}/db2_hj3415/valuation/growth.py +0 -0
- {db2_hj3415-0.1.10 → db2_hj3415-0.1.11}/db2_hj3415/valuation/mil.py +0 -0
- {db2_hj3415-0.1.10 → db2_hj3415-0.1.11}/db2_hj3415/valuation/models.py +0 -0
- {db2_hj3415-0.1.10 → db2_hj3415-0.1.11}/db2_hj3415/valuation/red.py +0 -0
@@ -1,4 +1,6 @@
|
|
1
1
|
from motor.motor_asyncio import AsyncIOMotorClient
|
2
|
+
from typing import Any
|
3
|
+
import math
|
2
4
|
from pymongo import ASCENDING, UpdateOne, DESCENDING
|
3
5
|
import pandas as pd
|
4
6
|
from datetime import datetime, timezone, timedelta
|
@@ -12,36 +14,43 @@ mylogger = setup_logger(__name__, 'WARNING')
|
|
12
14
|
COL_NAME = 'c108'
|
13
15
|
|
14
16
|
|
15
|
-
async def save(code: str, data: pd.DataFrame, client:
|
17
|
+
async def save(code: str, data: pd.DataFrame, client, db_name: str = DB_NAME, col_name: str = COL_NAME) -> dict:
|
16
18
|
if data is None or data.empty:
|
17
19
|
print("데이터 없음 - 저장 생략")
|
18
20
|
return {"status": "unchanged"}
|
19
21
|
|
20
|
-
collection = get_collection(client,
|
22
|
+
collection = get_collection(client, db_name, col_name)
|
21
23
|
|
22
24
|
await collection.create_index(
|
23
25
|
[("코드", ASCENDING), ("날짜", ASCENDING), ("제목", ASCENDING)],
|
24
26
|
unique=True
|
25
27
|
)
|
26
28
|
|
27
|
-
|
28
|
-
|
29
|
+
def convert_nan_to_none(x: Any) -> Any:
|
30
|
+
if isinstance(x, float) and (math.isnan(x) or math.isinf(x)):
|
31
|
+
return None
|
32
|
+
return x
|
33
|
+
|
34
|
+
# DataFrame의 각 열에 대해 map 적용 (applymap 대체)
|
35
|
+
df = data.apply(lambda col: col.map(convert_nan_to_none))
|
36
|
+
|
29
37
|
operations = []
|
30
|
-
inserted, updated
|
38
|
+
inserted, updated = 0, 0
|
31
39
|
|
32
40
|
for _, row in df.iterrows():
|
33
41
|
try:
|
34
|
-
|
42
|
+
doc = row.to_dict()
|
43
|
+
|
44
|
+
date_str = str(doc["날짜"])
|
35
45
|
date_obj = datetime.strptime(date_str, DATE_FORMAT).replace(tzinfo=timezone.utc)
|
36
46
|
|
37
|
-
doc = row.to_dict()
|
38
47
|
doc["코드"] = code
|
39
48
|
doc["날짜"] = date_obj
|
40
49
|
|
41
|
-
filter_ = {"코드": code, "날짜": date_obj, "제목": doc
|
50
|
+
filter_ = {"코드": code, "날짜": date_obj, "제목": doc.get("제목")}
|
42
51
|
operations.append(UpdateOne(filter_, {"$set": doc}, upsert=True))
|
43
52
|
except Exception as e:
|
44
|
-
print(f"변환 에러 - {
|
53
|
+
print(f"[{code}] 변환 에러 - {doc.get('제목', '제목 없음')}: {e}")
|
45
54
|
continue
|
46
55
|
|
47
56
|
if operations:
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|