analyser_hj3415 2.3.0__py2.py3-none-any.whl → 2.4.0__py2.py3-none-any.whl

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.
analyser_hj3415/cli.py CHANGED
@@ -1,109 +1,24 @@
1
1
  import argparse
2
- from utils_hj3415 import utils
3
- from .db import chk_db, mongo
4
- from . import eval, report
5
- from scraper2_hj3415.nfscrapy import run as nfsrun
2
+ from utils_hj3415 import noti
6
3
 
7
4
 
8
- def dbmanager():
9
- cmd = ['repair', 'sync', 'eval', 'update']
5
+ def analyser():
6
+ from analyser_hj3415.myredis import red_ranking
7
+ commands = {
8
+ 'ranking': red_ranking
9
+ }
10
10
  parser = argparse.ArgumentParser()
11
- parser.add_argument('cmd', help=f"Command - {cmd}")
12
- parser.add_argument('target', help="Target for scraping (type 6digit code or 'all' or 'parts')")
13
- parser.add_argument('-d', '--db_path', help="Set mongo database path")
11
+ parser.add_argument('command', help=f"Commands - {commands.keys()}")
12
+ parser.add_argument('--noti', action='store_true', help='작업완료후 메시지 전송여부')
14
13
 
15
14
  args = parser.parse_args()
16
15
 
17
- db_path = args.db_path if args.db_path else "mongodb://192.168.0.173:27017"
18
- client = mongo.connect_mongo(db_path)
19
-
20
- if args.cmd in cmd:
21
- if args.cmd == 'repair':
22
- if args.target == 'all' or utils.is_6digit(args.target):
23
- need_for_repair_codes = chk_db.chk_integrity_corps(client, args.target)
24
- # repair dict 예시 - {'343510': ['c106', 'c104', 'c103'], '298000': ['c104'], '091810': ['c104']}
25
- print(f"Need for repairing codes :{need_for_repair_codes}")
26
- if need_for_repair_codes:
27
- # x = input("Do you want to try to repair db by scraping? (y/N)")
28
- # if x == 'y' or x == 'Y':
29
- for code, failed_page_list in need_for_repair_codes.items():
30
- for page in failed_page_list:
31
- if page == 'c101':
32
- nfsrun.c101([code, ], db_path)
33
- elif page == 'c103':
34
- nfsrun.c103([code, ], db_path)
35
- elif page == 'c104':
36
- nfsrun.c104([code, ], db_path)
37
- elif page == 'c106':
38
- nfsrun.c106([code, ], db_path)
39
- recheck_result = chk_db.chk_integrity_corps(client, code)
40
- if recheck_result:
41
- # 다시 스크랩해도 오류가 지속되는 경우
42
- print(f"The db integrity failure persists..{recheck_result}")
43
- # x = input(f"Do you want to delete {code} on DB? (y/N)")
44
- # if x == 'y' or x == 'Y':
45
- # mongo.Corps.del_db(client, code)
46
- # else:
47
- # print("Canceled.")
48
- mongo.Corps.del_db(client, code)
49
- # else:
50
- # print("Done.")
51
- else:
52
- print("Done.")
53
- else:
54
- print(f"Invalid target option : {args.target}")
55
- elif args.cmd == 'update':
56
- if args.target == 'all' or utils.is_6digit(args.target):
57
- need_for_update_codes = list(chk_db.chk_modifying_corps(client, args.target).keys())
58
- # need_for_update_codes 예시 - [codes....]
59
- print(f"Need for updating codes :{need_for_update_codes}")
60
- if need_for_update_codes:
61
- nfsrun.c103(need_for_update_codes, db_path)
62
- nfsrun.c104(need_for_update_codes, db_path)
63
- nfsrun.c106(need_for_update_codes, db_path)
64
- elif args.target == 'parts':
65
- pass
66
- else:
67
- print(f"Invalid target option : {args.target}")
68
- elif args.cmd == 'sync':
69
- if args.target == 'all':
70
- chk_db.sync_mongo_with_krx(client)
71
- else:
72
- print(f"The target should be 'all' in sync command.")
73
- elif args.cmd == 'eval':
74
- if args.target == 'all':
75
- # eval을 평가해서 데이터베이스에 저장한다.
76
- eval.make_today_eval_df(client, refresh=True)
77
- else:
78
- print(f"The target should be 'all' in sync command.")
79
- else:
80
- print(f"The command should be in {cmd}")
81
-
82
- client.close()
83
-
84
-
85
- def evalmanager():
86
- cmd = ['report', ]
87
- parser = argparse.ArgumentParser()
88
- parser.add_argument('cmd', help=f"Command - {cmd}")
89
- parser.add_argument('target', help="Target for scraping (type 6digit code or 'all' or 'parts')")
90
- parser.add_argument('-d', '--db_path', help="Set mongo database path")
91
-
92
- args = parser.parse_args()
93
-
94
- db_path = args.db_path if args.db_path else "mongodb://192.168.0.173:27017"
95
- client = mongo.connect_mongo(db_path)
96
-
97
- if args.cmd in cmd:
98
- if args.cmd == 'report':
99
- if utils.is_6digit(args.target):
100
- print(report.Report(client, args.target))
101
- else:
102
- print(f"Invalid target option : {args.target}")
16
+ if args.command in commands.keys():
17
+ if args.command == 'ranking':
18
+ print(commands['ranking']())
19
+ if args.noti:
20
+ noti.telegram_to('manager', "오늘의 red ranking을 저장했습니다.(유효 12시간)")
103
21
  else:
104
- print(f"The command should be in {cmd}")
22
+ print(f"The command should be in {list(commands.keys())}")
105
23
 
106
24
 
107
- if __name__ == "__main__":
108
- # dbmanager()
109
- evalmanager()
@@ -1,10 +1,52 @@
1
1
  from analyser_hj3415.analysers import eval, score
2
2
  from db_hj3415.myredis import Base
3
3
  import json
4
+ from collections import OrderedDict
5
+ from db_hj3415 import myredis as db_myredis
6
+
4
7
 
5
8
  page = '.analyser'
6
9
 
7
10
 
11
+ def red_ranking() -> OrderedDict:
12
+ """
13
+ redis를 사용하며 red score를 계산해서 0이상의 값을 가지는 종목을 순서대로 저장하여 반환한다.
14
+ :return: OrderedDict([('023590', 101),
15
+ ('009970', 99),
16
+ ('010060', 91),...])
17
+ """
18
+ redis_name = 'red_ranking'
19
+
20
+ try:
21
+ cached_data = Base.redis_client.get(redis_name).decode('utf-8')
22
+ except AttributeError:
23
+ # redis에 해당하는 값이 없는 경우
24
+ data = {}
25
+ for i, code in enumerate(db_myredis.Corps.list_all_codes()):
26
+ s = score.red(code)
27
+ if s <= 0:
28
+ continue
29
+ data[code] = s
30
+ # print(i, code, s)
31
+
32
+ # print(data)
33
+ if data:
34
+ # 데이터를 Redis에 캐싱
35
+ Base.redis_client.set(redis_name, json.dumps(data))
36
+ # 12시간 후 키가 자동으로 제거됨
37
+ Base.redis_client.expire(redis_name, 3600 * 12)
38
+ print("analysers.eval 데이터 계산하기 - myredis.red_ranking")
39
+ # ordereddict를 이용해서 딕셔너리의 값을 기준으로 내림차순 정렬함.
40
+ return OrderedDict(sorted(data.items(), key=lambda item: item[1], reverse=True))
41
+ else:
42
+ print(f"Redis 캐시에서 데이터 가져오기(남은시간:{round(Base.redis_client.ttl(redis_name)/3600,1)}시간) - myredis.red_ranking")
43
+ # ordereddict를 이용해서 딕셔너리의 값을 기준으로 내림차순 정렬함.
44
+ return OrderedDict(sorted(json.loads(cached_data).items(), key=lambda item: item[1], reverse=True))
45
+
46
+
47
+
48
+
49
+
8
50
  def red_n_score(code: str) -> dict:
9
51
  """
10
52
  redis 사용 - 소멸타이머 사용
analyser_hj3415/trash.py CHANGED
@@ -207,4 +207,83 @@ def mil(code: str) -> Tuple[int, int, int, int]:
207
207
  p = 0
208
208
  score4 = 0 if 0 > p else p
209
209
 
210
- return score1, score2, score3, score4
210
+ return score1, score2, score3, score4
211
+
212
+
213
+
214
+
215
+ def dbmanager():
216
+ cmd = ['repair', 'sync', 'eval', 'update']
217
+ parser = argparse.ArgumentParser()
218
+ parser.add_argument('cmd', help=f"Command - {cmd}")
219
+ parser.add_argument('target', help="Target for scraping (type 6digit code or 'all' or 'parts')")
220
+ parser.add_argument('-d', '--db_path', help="Set mongo database path")
221
+
222
+ args = parser.parse_args()
223
+
224
+ db_path = args.db_path if args.db_path else "mongodb://192.168.0.173:27017"
225
+ client = mongo.connect_mongo(db_path)
226
+
227
+ if args.cmd in cmd:
228
+ if args.cmd == 'repair':
229
+ if args.target == 'all' or utils.is_6digit(args.target):
230
+ need_for_repair_codes = chk_db.chk_integrity_corps(client, args.target)
231
+ # repair dict 예시 - {'343510': ['c106', 'c104', 'c103'], '298000': ['c104'], '091810': ['c104']}
232
+ print(f"Need for repairing codes :{need_for_repair_codes}")
233
+ if need_for_repair_codes:
234
+ # x = input("Do you want to try to repair db by scraping? (y/N)")
235
+ # if x == 'y' or x == 'Y':
236
+ for code, failed_page_list in need_for_repair_codes.items():
237
+ for page in failed_page_list:
238
+ if page == 'c101':
239
+ nfsrun.c101([code, ], db_path)
240
+ elif page == 'c103':
241
+ nfsrun.c103([code, ], db_path)
242
+ elif page == 'c104':
243
+ nfsrun.c104([code, ], db_path)
244
+ elif page == 'c106':
245
+ nfsrun.c106([code, ], db_path)
246
+ recheck_result = chk_db.chk_integrity_corps(client, code)
247
+ if recheck_result:
248
+ # 다시 스크랩해도 오류가 지속되는 경우
249
+ print(f"The db integrity failure persists..{recheck_result}")
250
+ # x = input(f"Do you want to delete {code} on DB? (y/N)")
251
+ # if x == 'y' or x == 'Y':
252
+ # mongo.Corps.del_db(client, code)
253
+ # else:
254
+ # print("Canceled.")
255
+ mongo.Corps.del_db(client, code)
256
+ # else:
257
+ # print("Done.")
258
+ else:
259
+ print("Done.")
260
+ else:
261
+ print(f"Invalid target option : {args.target}")
262
+ elif args.cmd == 'update':
263
+ if args.target == 'all' or utils.is_6digit(args.target):
264
+ need_for_update_codes = list(chk_db.chk_modifying_corps(client, args.target).keys())
265
+ # need_for_update_codes 예시 - [codes....]
266
+ print(f"Need for updating codes :{need_for_update_codes}")
267
+ if need_for_update_codes:
268
+ nfsrun.c103(need_for_update_codes, db_path)
269
+ nfsrun.c104(need_for_update_codes, db_path)
270
+ nfsrun.c106(need_for_update_codes, db_path)
271
+ elif args.target == 'parts':
272
+ pass
273
+ else:
274
+ print(f"Invalid target option : {args.target}")
275
+ elif args.cmd == 'sync':
276
+ if args.target == 'all':
277
+ chk_db.sync_mongo_with_krx(client)
278
+ else:
279
+ print(f"The target should be 'all' in sync command.")
280
+ elif args.cmd == 'eval':
281
+ if args.target == 'all':
282
+ # eval을 평가해서 데이터베이스에 저장한다.
283
+ eval.make_today_eval_df(client, refresh=True)
284
+ else:
285
+ print(f"The target should be 'all' in sync command.")
286
+ else:
287
+ print(f"The command should be in {cmd}")
288
+
289
+ client.close()
@@ -1,12 +1,12 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: analyser_hj3415
3
- Version: 2.3.0
3
+ Version: 2.4.0
4
4
  Summary: Stock analyser and database processing programs
5
5
  Author-email: Hyungjin Kim <hj3415@gmail.com>
6
6
  Description-Content-Type: text/markdown
7
7
  Classifier: License :: OSI Approved :: MIT License
8
- Requires-Dist: utils-hj3415>=2.6.0
9
- Requires-Dist: db-hj3415>=3.3.2
8
+ Requires-Dist: utils-hj3415>=2.6.1
9
+ Requires-Dist: db-hj3415>=3.4.0
10
10
  Project-URL: Home, https://www.hyungjin.kr
11
11
 
12
12
  ### analyser-hj3415
@@ -0,0 +1,14 @@
1
+ analyser_hj3415/.DS_Store,sha256=OQfTSOHL-zjUtnNyBpNRVUJUstR4j6I7jihKDFQQmME,6148
2
+ analyser_hj3415/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
+ analyser_hj3415/cli.py,sha256=fDLGwz5x_5Gy4yCkz1cNbhC3BhkYNZ1IqKglcGRvsu4,750
4
+ analyser_hj3415/myredis.py,sha256=i6o61be2qv41boVEM1mQG5QNCELr5zSq9mH1csVfUx8,10628
5
+ analyser_hj3415/tools.py,sha256=SNsrnL5CKmKAdFkmlwgREMIkWDRi6N9LngCdhhhop3Y,13606
6
+ analyser_hj3415/trash.py,sha256=zF-W0piqkGr66UP6-iybo9EXh2gO0RP6R1FnIpsGkl8,12262
7
+ analyser_hj3415/analysers/eval.py,sha256=mlHi6EPc8l8O6vKnWyX4Cz1BaeGhUpWM8gVZRNhm-JU,13299
8
+ analyser_hj3415/analysers/report.py,sha256=whggmLXl7yF-BjQ6JKgxmhILT2T4uFP-rit_BSes9xM,9189
9
+ analyser_hj3415/analysers/score.py,sha256=j5bH_r2-Sc53JWgmdBmL7pJk9cc8oQ7iZkYRPPOA-so,16217
10
+ analyser_hj3415-2.4.0.dist-info/entry_points.txt,sha256=vBiMpIhNh39VC3UPwgxQNPb54N8vMlr4g0zRcCOjPyo,57
11
+ analyser_hj3415-2.4.0.dist-info/LICENSE,sha256=QVKTp0dTnB5xG8RLgG17LwSWCKNEzYoVVM6KjoCPKc0,1079
12
+ analyser_hj3415-2.4.0.dist-info/WHEEL,sha256=Sgu64hAMa6g5FdzHxXv9Xdse9yxpGGMeagVtPMWpJQY,99
13
+ analyser_hj3415-2.4.0.dist-info/METADATA,sha256=UiSrI8LK1WK8WWhrIqxcY6tAC0B4_ks-7eg3HI3m498,6417
14
+ analyser_hj3415-2.4.0.dist-info/RECORD,,
@@ -0,0 +1,3 @@
1
+ [console_scripts]
2
+ analyser=analyser_hj3415.cli:analyser
3
+
analyser_hj3415/run.py DELETED
File without changes
@@ -1,15 +0,0 @@
1
- analyser_hj3415/.DS_Store,sha256=OQfTSOHL-zjUtnNyBpNRVUJUstR4j6I7jihKDFQQmME,6148
2
- analyser_hj3415/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
- analyser_hj3415/cli.py,sha256=qzRnpDRJvQnQevSKHBpKbTsBjmSWllZjzTV4z_alg2A,4891
4
- analyser_hj3415/myredis.py,sha256=mSAELRPfiahhD_0yPeKtOhVEiOotOjYZv-T-JNG8kOU,8941
5
- analyser_hj3415/run.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
- analyser_hj3415/tools.py,sha256=SNsrnL5CKmKAdFkmlwgREMIkWDRi6N9LngCdhhhop3Y,13606
7
- analyser_hj3415/trash.py,sha256=vHrv8Q61QOkcwhmWfrj_yVdsdd5MoAxs9gXMOJEjMHM,8360
8
- analyser_hj3415/analysers/eval.py,sha256=mlHi6EPc8l8O6vKnWyX4Cz1BaeGhUpWM8gVZRNhm-JU,13299
9
- analyser_hj3415/analysers/report.py,sha256=whggmLXl7yF-BjQ6JKgxmhILT2T4uFP-rit_BSes9xM,9189
10
- analyser_hj3415/analysers/score.py,sha256=j5bH_r2-Sc53JWgmdBmL7pJk9cc8oQ7iZkYRPPOA-so,16217
11
- analyser_hj3415-2.3.0.dist-info/entry_points.txt,sha256=dHaCM3eOAGONmxTWuRVqo9Zyq2C7J5TZmpH0PD6FW5k,103
12
- analyser_hj3415-2.3.0.dist-info/LICENSE,sha256=QVKTp0dTnB5xG8RLgG17LwSWCKNEzYoVVM6KjoCPKc0,1079
13
- analyser_hj3415-2.3.0.dist-info/WHEEL,sha256=Sgu64hAMa6g5FdzHxXv9Xdse9yxpGGMeagVtPMWpJQY,99
14
- analyser_hj3415-2.3.0.dist-info/METADATA,sha256=S1sYBsG7yZg3-ngZckbo4EABYBYD93wTE4MFWwiaG2s,6417
15
- analyser_hj3415-2.3.0.dist-info/RECORD,,
@@ -1,4 +0,0 @@
1
- [console_scripts]
2
- dbmanager=analyser_hj3415.cli:dbmanager
3
- evalmanager=analyser_hj3415.cli:evalmanager
4
-