basic.py
1.42 KB
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
import FinanceDataReader as fdr
import pandas as pd
import sys
from fuzzywuzzy import process
def get_matches(query, choices, limit=3):
result = process.extract(query, choices, limit=limit)
return result
def basicinform(input):
stocks = pd.read_csv('stockcodename.csv', names=['Symbol', 'Market', 'Name'
, 'Sector', 'Industry', 'ListingDate', 'SettleMonth', 'Represetitive', 'HomePage', 'Region'], index_col=0)
symbol = ''
for i in enumerate(stocks.Name):
if i[1] == input:
symbol = (stocks.iloc[i[0]].Symbol)
break
if(symbol == ''):
fuzzy = get_matches(input, stocks['Name'])
cand = ''
for i in fuzzy:
cand += i[0]
cand += "\n"
cand += "중 찾는게 있으신가요? 다시 입력해주세요."
return cand
df = fdr.DataReader(symbol)
ror_df = df.Close.pct_change()
volume = df.Volume.iloc[-1]
price = df.Close.iloc[-1]
ror = ror_df[-1]
ror = round(ror, 4)
ror = ror * 100
value = ''
value = "1현재가: " + str(price) + "원\n거래랑: " + str(volume) + "건\n전일대비: " + str(ror) + "%"
# value = {
# "현재가": price,
# "거래랑": volume,
# "전일 대비 수익률:": ror
# }
return value
# print(basicinform('호텔신라'))
args = sys.argv
print(basicinform(args[1]))