Showing
1 changed file
with
17 additions
and
3 deletions
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 | + | ||
4 | # -*- coding: utf-8 -*- | 6 | # -*- coding: utf-8 -*- |
7 | + | ||
8 | +def get_matches(query, choices, limit=3): | ||
9 | + result = process.extract(query, choices, limit=limit) | ||
10 | + return result | ||
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', 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,5 @@ def basicinform(input): | ... | @@ -25,7 +41,5 @@ def basicinform(input): |
25 | return value | 41 | return value |
26 | 42 | ||
27 | 43 | ||
28 | -#print(basicinform('삼성전자')) | ||
29 | - | ||
30 | args = sys.argv | 44 | args = sys.argv |
31 | -print(basicinform(args[1])) | 45 | +print(basicinform(args[0])) | ... | ... |
-
Please register or login to post a comment