|
@@ -61,28 +61,31 @@ class OcrManage:
|
|
|
@classmethod
|
|
|
def parse(self,result,source):
|
|
|
list = result['words_result']
|
|
|
+ words = []
|
|
|
+ for dic in list:
|
|
|
+ word = dic['words']
|
|
|
+ word = self.deleteWords(word)
|
|
|
+ if len(word) > 0:
|
|
|
+ words.append(word)
|
|
|
+ wlist = self.wordsSeperate(words)
|
|
|
+
|
|
|
if source == 'pc': #电脑截图
|
|
|
- words = []
|
|
|
- for dic in list:
|
|
|
- word = dic['words']
|
|
|
- word = self.deleteWords(word)
|
|
|
- if len(word) > 0:
|
|
|
- words.append(word)
|
|
|
- wlist = self.wordsSeperate(words)
|
|
|
return self.lookCPAsset(wlist,list)
|
|
|
else:
|
|
|
- return self.lookAsset(list)
|
|
|
+ return self.lookAsset(wlist,list)
|
|
|
|
|
|
@classmethod
|
|
|
- def lookAsset(self,list):
|
|
|
+ def lookAsset(self,wlist,list):
|
|
|
dic = {}
|
|
|
asset = ''
|
|
|
if self.indexObject('净资产',list) > 0:
|
|
|
asset = self.caculateAsset(list,'净资产')
|
|
|
else:
|
|
|
asset = self.caculateAsset(list,'总资产')
|
|
|
-
|
|
|
-
|
|
|
+ if(self.floatValue(asset) == 0):
|
|
|
+ asset = self.caculateAsset(list,'账户资产')
|
|
|
+ if(self.floatValue(asset) == 0):
|
|
|
+ asset = self.assetWords(wlist)
|
|
|
|
|
|
dic['today'] = self.wangWord(asset)
|
|
|
dic['list'] = self.lookMarket(list)
|
|
@@ -93,14 +96,44 @@ class OcrManage:
|
|
|
def lookMarket(self,list):
|
|
|
flist = []
|
|
|
index = self.indexObject('市值',list)
|
|
|
- i = index
|
|
|
- for i in range(len(list)):
|
|
|
+ beforeLoc = 0
|
|
|
+
|
|
|
+ for i in range(index,len(list)):
|
|
|
dic = list[i]
|
|
|
words = dic['words']
|
|
|
codeName = self.codeName(words)
|
|
|
if len(codeName['name']) > 0:
|
|
|
fund = 0
|
|
|
market = '0'
|
|
|
+ money = 0
|
|
|
+
|
|
|
+ if beforeLoc == 0:
|
|
|
+ for n in range(i,index,-1):
|
|
|
+ ndic = list[n]
|
|
|
+ nstr = ndic['words']
|
|
|
+ nstr = self.replaceWords(nstr)
|
|
|
+ if('当日盈亏' in nstr or '比' in nstr):
|
|
|
+ continue
|
|
|
+
|
|
|
+ if '持仓盈' in nstr or '浮动盈亏' in nstr or '参考盈亏' in nstr or '盈亏/盈亏率' in nstr or '总盈亏' in nstr or '盈亏' in nstr:
|
|
|
+ bnloc = list[n-1]['location']
|
|
|
+ beforeLoc = float(bnloc['left']) + float(bnloc['width'])
|
|
|
+ break
|
|
|
+
|
|
|
+ if beforeLoc > 0:
|
|
|
+ for m in range(i+1,len(list)):
|
|
|
+ mdic = list[m]
|
|
|
+ mloc = mdic['location']
|
|
|
+ mstr = mdic['words']
|
|
|
+
|
|
|
+ if mloc['left'] > beforeLoc:
|
|
|
+ mstr = self.replaceWords(mstr)
|
|
|
+ mstr = self.replaceDot(mstr)
|
|
|
+ mstr = self.wangWord(mstr)
|
|
|
+ money = float(mstr)
|
|
|
+
|
|
|
+ break
|
|
|
+
|
|
|
for m in range(i+1,len(list)):
|
|
|
mdic = list[m]
|
|
|
mloc = mdic['location']
|
|
@@ -108,29 +141,25 @@ class OcrManage:
|
|
|
nstr = mdic['words']
|
|
|
if len(nstr) == 6 and ((',' not in nstr) or ('.' not in nstr)) and self.isNumber(nstr):
|
|
|
continue
|
|
|
- if float(mloc['left']) < (float(loc['left']) + float(loc['width'])):
|
|
|
+ if float(mloc['left']) < (float(loc['left']) + float(loc['width'])/2.0):
|
|
|
market = mdic['words']
|
|
|
break
|
|
|
|
|
|
|
|
|
fund = self.wangWord(market)
|
|
|
|
|
|
- if fund > 0:
|
|
|
- ndic = {}
|
|
|
- ndic['name'] = codeName['name']
|
|
|
- ndic['code'] = codeName['code']
|
|
|
- ndic['fund'] = str(round(fund,2))
|
|
|
- flist.append(ndic)
|
|
|
+ ndic = {}
|
|
|
+ ndic['name'] = codeName['name']
|
|
|
+ ndic['code'] = codeName['code']
|
|
|
+ ndic['fund'] = str(round(fund,2))
|
|
|
+ ndic['money'] = str(round(money,3))
|
|
|
+ flist.append(ndic)
|
|
|
|
|
|
return flist
|
|
|
|
|
|
@classmethod
|
|
|
def lookCPAsset(self,wlist,list):
|
|
|
dic = {}
|
|
|
-
|
|
|
- # print(str(wlist))
|
|
|
-
|
|
|
-
|
|
|
asset = self.assetWords(wlist)
|
|
|
if self.floatValue(asset) >= 0:
|
|
|
today = self.floatValue(asset)/10000.0
|
|
@@ -138,29 +167,30 @@ class OcrManage:
|
|
|
|
|
|
dic['list'] = self.lookCPMarket(list)
|
|
|
|
|
|
- print(str(dic))
|
|
|
|
|
|
return dic
|
|
|
|
|
|
@classmethod
|
|
|
def lookCPMarket(self,list):
|
|
|
flist = []
|
|
|
- index = self.indexEquel('市值',list)
|
|
|
+ mindex = self.indexObject('名称',list)
|
|
|
+
|
|
|
+ index = self.indexEquel('市值',list,mindex)
|
|
|
if index == 0:
|
|
|
- index = self.indexEquel('最新市值',list)
|
|
|
+ index = self.indexEquel('最新市值',list,mindex)
|
|
|
|
|
|
if index == 0:
|
|
|
- index = self.indexEquel('最新沛值',list)
|
|
|
+ index = self.indexEquel('最新沛值',list,mindex)
|
|
|
|
|
|
before = 0.0
|
|
|
|
|
|
if index - 1 > 0:
|
|
|
sdic = list[index-1]
|
|
|
sloc = sdic['location']
|
|
|
-
|
|
|
+ print(sdic)
|
|
|
before = float(sloc['left']) + float(sloc['width'])
|
|
|
|
|
|
-
|
|
|
+ beforeLoc = 0
|
|
|
|
|
|
for i in range(index,len(list)):
|
|
|
dic = list[i]
|
|
@@ -175,6 +205,37 @@ class OcrManage:
|
|
|
if len(codeName['name']) > 0:
|
|
|
fund = 0
|
|
|
market = '0'
|
|
|
+ money = 0
|
|
|
+
|
|
|
+ if beforeLoc == 0:
|
|
|
+ for n in range(len(list)-1,-1,-1):
|
|
|
+ ndic = list[n]
|
|
|
+ nstr = ndic['words']
|
|
|
+ nstr = self.replaceWords(nstr)
|
|
|
+ if('当日盈亏' in nstr or '比例' in nstr):
|
|
|
+ continue
|
|
|
+ if '持仓盈亏' == nstr or '浮动盈亏' == nstr or '参考盈亏' == nstr or '盈亏/盈亏率' in nstr or '总盈亏' == nstr or '盈亏' == nstr:
|
|
|
+ bnloc = list[n-1]['location']
|
|
|
+ beforeLoc = float(bnloc['left']) + float(bnloc['width'])
|
|
|
+ break
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if beforeLoc > 0:
|
|
|
+ for m in range(i+1,len(list)):
|
|
|
+ mdic = list[m]
|
|
|
+ mloc = mdic['location']
|
|
|
+ mstr = mdic['words']
|
|
|
+
|
|
|
+ if mloc['left'] > beforeLoc:
|
|
|
+ mstr = self.replaceWords(mstr)
|
|
|
+ mstr = self.replaceDot(mstr)
|
|
|
+ mstr = self.wangWord(mstr)
|
|
|
+ money = float(mstr)
|
|
|
+
|
|
|
+ break
|
|
|
+
|
|
|
+
|
|
|
for m in range(i+1,len(list)):
|
|
|
mdic = list[m]
|
|
|
mloc = mdic['location']
|
|
@@ -186,12 +247,13 @@ class OcrManage:
|
|
|
|
|
|
fund = self.wangWord(market)
|
|
|
|
|
|
- if fund > 0:
|
|
|
- ndic = {}
|
|
|
- ndic['name'] = codeName['name']
|
|
|
- ndic['code'] = codeName['code']
|
|
|
- ndic['fund'] = str(round(fund,2))
|
|
|
- flist.append(ndic)
|
|
|
+
|
|
|
+ ndic = {}
|
|
|
+ ndic['name'] = codeName['name']
|
|
|
+ ndic['code'] = codeName['code']
|
|
|
+ ndic['fund'] = str(round(fund,2))
|
|
|
+ ndic['money'] = str(round(money,3))
|
|
|
+ flist.append(ndic)
|
|
|
|
|
|
return flist
|
|
|
|
|
@@ -213,6 +275,10 @@ class OcrManage:
|
|
|
width = float(jdic['width'])
|
|
|
if jx < ix and ix < (jx + width):
|
|
|
strAsset = ndic['words']
|
|
|
+ if(self.isChinese(strAsset)):
|
|
|
+ if ('万' not in strAsset):
|
|
|
+ clist = self.seperateChinense(strAsset)
|
|
|
+ strAsset = clist[0]
|
|
|
break
|
|
|
|
|
|
if self.wangWord(strAsset) == 0:
|
|
@@ -260,7 +326,7 @@ class OcrManage:
|
|
|
if len(cword) > 0:
|
|
|
list.append(cword)
|
|
|
cword = ''
|
|
|
- if strw == '-' or strw == ':':
|
|
|
+ if strw == ':':
|
|
|
if len(nword) > 0:
|
|
|
list.append(nword)
|
|
|
nword = ''
|
|
@@ -425,6 +491,9 @@ class OcrManage:
|
|
|
words = words.replace(':','')
|
|
|
words = words.replace(':','')
|
|
|
words = words.replace('A','')
|
|
|
+ words = words.replace('▲','')
|
|
|
+ words = words.replace('◆','')
|
|
|
+ words = words.replace('+','')
|
|
|
words = words.upper()
|
|
|
|
|
|
return words
|
|
@@ -462,6 +531,7 @@ class OcrManage:
|
|
|
for i in range(len(list)):
|
|
|
dic = list[i]
|
|
|
nword = dic['words']
|
|
|
+ nword = self.replaceWords(nword)
|
|
|
if words in nword:
|
|
|
index = i
|
|
|
break
|
|
@@ -469,13 +539,14 @@ class OcrManage:
|
|
|
return index
|
|
|
|
|
|
@classmethod
|
|
|
- def indexEquel(self,words,list):
|
|
|
+ def indexEquel(self,words,list,m):
|
|
|
index = -1
|
|
|
i=0
|
|
|
- for i in range(len(list)):
|
|
|
+ for i in range(m,len(list)):
|
|
|
dic = list[i]
|
|
|
nword = dic['words']
|
|
|
- if words == nword:
|
|
|
+ nword = self.replaceWords(nword)
|
|
|
+ if words in nword:
|
|
|
index = i
|
|
|
break
|
|
|
|
|
@@ -488,6 +559,10 @@ class OcrManage:
|
|
|
# print('ischinese:' + number)
|
|
|
return False
|
|
|
|
|
|
+ fushu = r'-\w*'
|
|
|
+ if re.match(fushu, str(number)):
|
|
|
+ return True
|
|
|
+
|
|
|
zhengshu = r'^([1-9][\d]*|0)(\.[\d]+)?$'
|
|
|
if re.match(zhengshu, str(number)):
|
|
|
return True
|
|
@@ -512,14 +587,10 @@ class OcrManage:
|
|
|
if word == '':
|
|
|
return 0
|
|
|
|
|
|
- # print('floatValue:' + word)
|
|
|
-
|
|
|
return float(word)
|
|
|
|
|
|
@classmethod
|
|
|
def wangWord(self,word):
|
|
|
- print(word)
|
|
|
-
|
|
|
isWang = 0
|
|
|
if '万' in word:
|
|
|
wlist = self.seperateChinense(word)
|
|
@@ -528,14 +599,11 @@ class OcrManage:
|
|
|
isWang = 1
|
|
|
|
|
|
|
|
|
- if self.floatValue(word) >= 0:
|
|
|
- if isWang == 1:
|
|
|
- nvalue = self.floatValue(word)
|
|
|
- else:
|
|
|
- nvalue = self.floatValue(word)/10000.0
|
|
|
- word = round(nvalue,2)
|
|
|
+ if isWang == 1:
|
|
|
+ nvalue = self.floatValue(word)
|
|
|
else:
|
|
|
- word = 0
|
|
|
+ nvalue = self.floatValue(word)/10000.0
|
|
|
+ word = round(nvalue,3)
|
|
|
|
|
|
return word
|
|
|
|