박하늘

basic.py : fuzzy string

1 import FinanceDataReader as fdr 1 import FinanceDataReader as fdr
2 import pandas as pd 2 import pandas as pd
3 import sys 3 import sys
4 +from fuzzywuzzy import process
5 +
6 +
7 +def get_matches(query, choices, limit=3):
8 + result = process.extract(query, choices, limit=limit)
9 + return result
4 10
5 11
6 def basicinform(input): 12 def basicinform(input):
7 - stocks = pd.read_csv('stockcodename.csv', index_col=0) 13 + stocks = pd.read_csv('stockcodename.csv', names=['Symbol', 'Market', 'Name', 'Sector', 'Industry', 'ListingDate', 'SettleMonth', 'Represetitive', 'HomePage', 'Region'], index_col=0)
8 symbol = '' 14 symbol = ''
15 +
9 for i in enumerate(stocks.Name): 16 for i in enumerate(stocks.Name):
10 if i[1] == input: 17 if i[1] == input:
11 symbol = (stocks.iloc[i[0]].Symbol) 18 symbol = (stocks.iloc[i[0]].Symbol)
12 break 19 break
13 20
21 + if(symbol == ''):
22 + fuzzy = get_matches(input, stocks['Name'])
23 + cand = ''
24 + for i in fuzzy:
25 + cand += i[0]
26 + cand += " "
27 + cand += "중 찾는게 있으신가요? \n다시 입력해주세요."
28 + return cand
29 +
14 df = fdr.DataReader(symbol) 30 df = fdr.DataReader(symbol)
15 ror_df = df.Close.pct_change() 31 ror_df = df.Close.pct_change()
16 volume = df.Volume.iloc[-1] 32 volume = df.Volume.iloc[-1]
...@@ -25,7 +41,7 @@ def basicinform(input): ...@@ -25,7 +41,7 @@ def basicinform(input):
25 return value 41 return value
26 42
27 43
28 -# print(basicinform('삼성전자')) 44 +# print(basicinform('신라호텔'))
29 45
30 args = sys.argv 46 args = sys.argv
31 print(basicinform(args[1])) 47 print(basicinform(args[1]))
......