analyser_hj3415 2.2.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.
@@ -7,7 +7,6 @@ from typing import Tuple
7
7
  from db_hj3415 import myredis, mymongo
8
8
  from analyser_hj3415.analysers import eval
9
9
  from utils_hj3415 import utils
10
- from analyser_hj3415 import myredis as analyser_redis
11
10
 
12
11
  import logging
13
12
 
@@ -45,7 +44,7 @@ def red(code: str) -> int:
45
44
  recent_price = float('nan')
46
45
  return 0
47
46
 
48
- red_price = analyser_redis.red(code)['red_price']
47
+ red_price = eval.red(code)['red_price']
49
48
  deviation = cal_deviation(recent_price, red_price)
50
49
  if red_price < 0 or (recent_price >= red_price):
51
50
  score = 0
@@ -86,9 +85,9 @@ def mil(code: str) -> Tuple[int, int, int, int]:
86
85
  Returns:
87
86
  tuple: 주주수익률, 이익지표, 투자수익률, PFCF포인트
88
87
  """
89
- mil_dict = analyser_redis.mil(code)
88
+ mil_dict = eval.mil(code)
90
89
 
91
- print(pprint.pformat(mil_dict, width=200))
90
+ # print(pprint.pformat(mil_dict, width=200))
92
91
 
93
92
  # 주주수익률 평가
94
93
  if math.isnan(mil_dict['주주수익률']):
@@ -179,9 +178,9 @@ def blue(code: str) -> Tuple[int, int, int, int, int]:
179
178
 
180
179
  c104y = myredis.C104(code, 'c104y')
181
180
 
182
- blue_dict = analyser_redis.blue(code)
181
+ blue_dict = eval.blue(code)
183
182
 
184
- print(pprint.pformat(blue_dict, width=200))
183
+ # print(pprint.pformat(blue_dict, width=200))
185
184
 
186
185
  def 유동비율평가(유동비율: float) -> int:
187
186
  # 채점은 0을 기준으로 마이너스 해간다. 즉 0이 제일 좋은 상태임.
@@ -276,7 +275,7 @@ def growth(code: str) -> Tuple[int, int]:
276
275
  Returns:
277
276
  tuple : 매출액증가율, 영업이익률 평가 포인트
278
277
  """
279
- growth_dict = analyser_redis.growth(code)
278
+ growth_dict = eval.growth(code)
280
279
 
281
280
  logger.debug(pprint.pformat(growth_dict, width=200))
282
281
 
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,11 +1,53 @@
1
- from analyser_hj3415.analysers import eval
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
 
8
- def red(code: str) -> dict:
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
+
50
+ def red_n_score(code: str) -> dict:
9
51
  """
10
52
  redis 사용 - 소멸타이머 사용
11
53
  리턴값
@@ -24,6 +66,7 @@ def red(code: str) -> dict:
24
66
  except AttributeError:
25
67
  # redis에 해당하는 값이 없는 경우
26
68
  data = eval.red(code)
69
+ data['score'] = score.red(code)
27
70
  # print(data)
28
71
  if data:
29
72
  # 데이터를 Redis에 캐싱
@@ -37,7 +80,7 @@ def red(code: str) -> dict:
37
80
  return json.loads(cached_data)
38
81
 
39
82
 
40
- def mil(code: str) -> dict:
83
+ def mil_n_score(code: str) -> dict:
41
84
  """
42
85
  redis 사용 - 소멸타이머 사용
43
86
  리턴값
@@ -79,6 +122,7 @@ def mil(code: str) -> dict:
79
122
  except AttributeError:
80
123
  # redis에 해당하는 값이 없는 경우
81
124
  data = eval.mil(code)
125
+ data['score'] = score.mil(code)
82
126
  # print(data)
83
127
  if data:
84
128
  # 데이터를 Redis에 캐싱
@@ -92,7 +136,7 @@ def mil(code: str) -> dict:
92
136
  return json.loads(cached_data)
93
137
 
94
138
 
95
- def blue(code: str) -> dict:
139
+ def blue_n_score(code: str) -> dict:
96
140
  """
97
141
  redis 사용 - 소멸타이머 사용
98
142
  리턴값
@@ -130,6 +174,7 @@ def blue(code: str) -> dict:
130
174
  except AttributeError:
131
175
  # redis에 해당하는 값이 없는 경우
132
176
  data = eval.blue(code)
177
+ data['score'] = score.blue(code)
133
178
  # print(data)
134
179
  if data:
135
180
  # 데이터를 Redis에 캐싱
@@ -143,7 +188,7 @@ def blue(code: str) -> dict:
143
188
  return json.loads(cached_data)
144
189
 
145
190
 
146
- def growth(code: str) -> dict:
191
+ def growth_n_score(code: str) -> dict:
147
192
  """
148
193
  redis 사용 - 소멸타이머 사용
149
194
  리턴값
@@ -162,6 +207,7 @@ def growth(code: str) -> dict:
162
207
  except AttributeError:
163
208
  # redis에 해당하는 값이 없는 경우
164
209
  data = eval.growth(code)
210
+ data['score'] = score.growth(code)
165
211
  # print(data)
166
212
  if data:
167
213
  # 데이터를 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.2.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=zgsXO4G2VsXt4LID4VF-Y7AqkPjV8Th66a2czuma_bM,8738
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=C_Xiqo44o2OAXHaHiHYLa60HwKwpUt_H18uO5Iff1TM,16308
11
- analyser_hj3415-2.2.0.dist-info/entry_points.txt,sha256=dHaCM3eOAGONmxTWuRVqo9Zyq2C7J5TZmpH0PD6FW5k,103
12
- analyser_hj3415-2.2.0.dist-info/LICENSE,sha256=QVKTp0dTnB5xG8RLgG17LwSWCKNEzYoVVM6KjoCPKc0,1079
13
- analyser_hj3415-2.2.0.dist-info/WHEEL,sha256=Sgu64hAMa6g5FdzHxXv9Xdse9yxpGGMeagVtPMWpJQY,99
14
- analyser_hj3415-2.2.0.dist-info/METADATA,sha256=OJhj-1acjb5Ht817i0tzqYdLUkA94NpGVZ-dclMstKo,6417
15
- analyser_hj3415-2.2.0.dist-info/RECORD,,
@@ -1,4 +0,0 @@
1
- [console_scripts]
2
- dbmanager=analyser_hj3415.cli:dbmanager
3
- evalmanager=analyser_hj3415.cli:evalmanager
4
-