-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.py
75 lines (61 loc) · 2.65 KB
/
Main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
from Calc import *
from Tools import getCompanyDict, get_now_price, get_company_type, check_if_black_list
import requests
from bs4 import BeautifulSoup
import time
from DB import *
class Main:
def __init__(self):
company = getCompanyDict()
codes = list(company.keys())
contents = list(company.values())
self.db = DB()
count = 1
for code, content in zip(codes, contents):
print(str(count) + '/' + str(len(codes)), code, *content)
count += 1
try:
self.process(code, *content, "연결")
time.sleep(0.1)
except ZeroDivisionError:
try:
self.process(code, *content, "별도")
time.sleep(0.1)
except IndexError:
pass
except IndexError:
pass
self.db.saveData()
def process(self, code, name, category, product, linked):
fn_web = None
if linked == "연결":
time.sleep(0.1)
while fn_web is None:
try:
fn_web = requests.get(
"http://comp.fnguide.com/SVO2/ASP/SVD_Finance.asp?pGB=1&gicode=A" + code + "&cID=&MenuYn=Y&ReportGB=D&NewMenuID=103&stkGb=701")
except:
pass
else:
time.sleep(0.1)
while fn_web is None:
try:
fn_web = requests.get(
"http://comp.fnguide.com/SVO2/ASP/SVD_Finance.asp?pGB=1&gicode=A" + code + "&cID=&MenuYn=Y&ReportGB=B&NewMenuID=103&stkGb=701")
except:
pass
fn_soup = BeautifulSoup(fn_web.content, "html.parser")
# data-> 0: 포괄손익계산서, 1: 재무상태표, 2: 현금흐름표
data = fn_soup.findAll(class_="ul_co1_c pd_t1")
calc = Calc(data, code, linked)
company_type = get_company_type(*calc.get_prices(), get_now_price(code), calc.get_ROA())
# if calc.get_ROA() >= 0.1 and calc.get_allocation() >= 1:
if not check_if_black_list(calc.get_category()):
if company_type == "low":
self.db.addCompany("low", code, name, *calc.get_prices(), get_now_price(code), category, product,
round(calc.get_ROA(), 2), round(calc.get_ROA_trend(), 2))
elif company_type == "between":
self.db.addCompany("between", code, name, *calc.get_prices(), get_now_price(code), category, product,
round(calc.get_ROA(), 2), round(calc.get_ROA_trend(), 2))
if __name__ == '__main__':
main = Main()