Ejemplo n.º 1
0
def save_is():
    today = setting.get_today_str()
    for num, code in enumerate(code_data['종목코드']):
        try:
            print(num, code)
            time.sleep(0.1)
            try:
                fs_df = make_is_dataframe(code)
            except requests.exceptions.Timeout:
                time.sleep(60)
                fs_df = make_is_dataframe(code)
                print('TimeoutError')
            except requests.exceptions.ConnectionError:
                time.sleep(30)
                fs_df = make_is_dataframe(code)
                print('ConnetError')
            fs_df_changed = change_df(code, fs_df)
            if num == 0:
                total_iv = fs_df_changed
            else:
                total_iv = pd.concat([total_iv, fs_df_changed])
        except ValueError:
            continue
        except KeyError:
            continue

    total_iv.to_excel(setting.DATAPATH.format(today, '상장주식수', today))
Ejemplo n.º 2
0
def make_dir():
    today = setting.get_today_str()
    try:
        if not (os.path.isdir(r'.\data\{}'.format(today))):
            os.makedirs(os.path.join(r'.\data\{}'.format(today)))
    except OSError as e:
        if e.errno != errno.EEXIST:
            print("Failed to create directory!!!!!")
            raise
Ejemplo n.º 3
0
    def btnExcel_clicked(self):

        today = setting.get_today_str()

        df = setting.read_mongo('new', {'Update': {'$eq': False}})
        df.drop(['_id', 'Update'], axis=1, inplace=True)

        if os.path.exists(setting.NEWPATH.format(today)):
            df_old = pd.read_excel(setting.NEWPATH.format(today))
            df = df_old[['날짜', '코드', '종목명', '시간',
                         '특이사항']].append(df[['날짜', '코드', '종목명', '시간', '특이사항']])

        print(df)
        df = df.sort_values(by=['종목명', '시간'], axis=0)

        df.to_excel(setting.NEWPATH.format(today), index=False)

        # df.to_excel()
        setting.update_mongo('new', {'Update': False},
                             {"$set": {
                                 'Update': True
                             }})
        return
Ejemplo n.º 4
0
def save_fr_year():
    today = setting.get_today_str()
    for num, code in enumerate(code_data['종목코드']):
        try:
            print(num, code)
            time.sleep(0.1)
            try:
                fs_ds_y = make_fr_dataframe_year(code)
            except requests.exceptions.Timeout:
                time.sleep(60)
                fs_ds_y = make_fs_dataframe_year(code)
            except requests.exceptions.ConnectionError:
                time.sleep(30)
                fs_ds_y = make_fs_dataframe_year(code)
            fs_df_changed = change_df(code, fs_ds_y)
            if num == 0:
                total_fs = fs_df_changed
            else:
                total_fs = pd.concat([total_fs, fs_df_changed])
        except ValueError:
            continue
        except KeyError:
            continue
    total_fs.to_excel(setting.DATAPATH.format(today, '재무비율_년', today))
Ejemplo n.º 5
0
import requests
import bs4
import pandas as pd
import time

# [코드 3.25] 다운받은 종목 엑셀파일 읽어오기 (CH3. 데이터 수집하기.ipynb)
import os

from daishin import setting

path = r'.\종목코드.xlsx'
code_data = pd.read_excel(path)
code_data = code_data[['종목코드']]

# [코드 3.26] 종목코드 컬럼 개선 (CH3. 데이터 수집하기.ipynb)
today = setting.get_today_str()

def make_code(x):
    x = str(x)
    return 'A' + '0' * (6-len(x)) + x

def delete_code(x):
    return x[1:]


# [코드 3.15] 재무제표 데이터를 가져와 데이터프레임으로 만드는 함수 (CH3. 데이터 수집하기.ipynb)

def make_fs_dataframe_year(firm_code):
    fs_url = 'https://comp.fnguide.com/SVO2/asp/SVD_Finance.asp?pGB=1&gicode={}&cID=&MenuYn=Y&ReportGB=&NewMenuID=103&stkGb=701'.format(
        firm_code)
    fs_page = requests.get(fs_url)
Ejemplo n.º 6
0
from daishin import setting

DATAPATH = r'.\data\{}\{}{}.xlsm'

print(
    DATAPATH.format(setting.get_today_str(), 'lowcap_sorted',
                    setting.get_today_str()))