|
@@ -0,0 +1,531 @@
|
|
|
|
|
+# encoding: utf-8
|
|
|
|
|
+import re
|
|
|
|
|
+
|
|
|
|
|
+from django.core.cache import cache
|
|
|
|
|
+from aip import AipOcr
|
|
|
|
|
+
|
|
|
|
|
+import common.models as cm
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+class StockCache(object):
|
|
|
|
|
+ """
|
|
|
|
|
+ stock cache, key=name, value=code, ttl=3600s.
|
|
|
|
|
+ """
|
|
|
|
|
+
|
|
|
|
|
+ def __init__(self):
|
|
|
|
|
+ self.key_prefix = 'djwzb:stock_cache_name_code'
|
|
|
|
|
+ self.ttl = 3600
|
|
|
|
|
+ self.empty_str = '#'
|
|
|
|
|
+
|
|
|
|
|
+ def make_key(self, name):
|
|
|
|
|
+ return '%s:%s' % (self.key_prefix, name)
|
|
|
|
|
+
|
|
|
|
|
+ def get_code_by_name(self, name):
|
|
|
|
|
+ key = self.make_key(name)
|
|
|
|
|
+ code = cache.get(key)
|
|
|
|
|
+ if code is None:
|
|
|
|
|
+ stock = cm.Stock.objects.filter(name=name).first()
|
|
|
|
|
+ if stock is None:
|
|
|
|
|
+ cache.set(key, self.empty_str, self.ttl)
|
|
|
|
|
+ return
|
|
|
|
|
+ cache.set(key, stock.code, self.ttl)
|
|
|
|
|
+ return stock.code
|
|
|
|
|
+ elif code == self.empty_str:
|
|
|
|
|
+ return
|
|
|
|
|
+ else:
|
|
|
|
|
+ return code
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+stock_cache = StockCache()
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+class OcrManage:
|
|
|
|
|
+
|
|
|
|
|
+ def __init__(self):
|
|
|
|
|
+ pass
|
|
|
|
|
+
|
|
|
|
|
+ @classmethod
|
|
|
|
|
+ def loadOcr(self,url,source):
|
|
|
|
|
+ app_id = '35386340'
|
|
|
|
|
+ api_key = 'EeFUPsy7L10UaaClXl3uy2ie'
|
|
|
|
|
+ secret_key = 'QSWGGtGfGLkmZwc8AaRXgkloCAlSdNGB'
|
|
|
|
|
+ aip_ocr = AipOcr(
|
|
|
|
|
+ appId=app_id,
|
|
|
|
|
+ apiKey=api_key,
|
|
|
|
|
+ secretKey=secret_key)
|
|
|
|
|
+
|
|
|
|
|
+ res_url = aip_ocr.generalUrl(url)
|
|
|
|
|
+
|
|
|
|
|
+ return self.parse(res_url,source)
|
|
|
|
|
+
|
|
|
|
|
+ @classmethod
|
|
|
|
|
+ def parse(self,result,source):
|
|
|
|
|
+ list = result['words_result']
|
|
|
|
|
+ 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)
|
|
|
|
|
+
|
|
|
|
|
+ @classmethod
|
|
|
|
|
+ def lookAsset(self,list):
|
|
|
|
|
+ dic = {}
|
|
|
|
|
+ asset = ''
|
|
|
|
|
+ if self.indexObject('净资产',list) > 0:
|
|
|
|
|
+ asset = self.caculateAsset(list,'净资产')
|
|
|
|
|
+ else:
|
|
|
|
|
+ asset = self.caculateAsset(list,'总资产')
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ if self.floatValue(asset) >= 0:
|
|
|
|
|
+ today = 0
|
|
|
|
|
+ if '万' in asset:
|
|
|
|
|
+ today = self.floatValue(asset)
|
|
|
|
|
+ else:
|
|
|
|
|
+ today = self.floatValue(asset)/10000.0
|
|
|
|
|
+
|
|
|
|
|
+ dic['today'] = round(today,2)
|
|
|
|
|
+ else:
|
|
|
|
|
+ dic['today'] = 0
|
|
|
|
|
+
|
|
|
|
|
+ dic['list'] = self.lookMarket(list)
|
|
|
|
|
+
|
|
|
|
|
+ print(dic)
|
|
|
|
|
+ return dic
|
|
|
|
|
+ @classmethod
|
|
|
|
|
+ def lookMarket(self,list):
|
|
|
|
|
+ flist = []
|
|
|
|
|
+ index = self.indexObject('市值',list)
|
|
|
|
|
+ i = index
|
|
|
|
|
+ for i in range(len(list)):
|
|
|
|
|
+ dic = list[i]
|
|
|
|
|
+ words = dic['words']
|
|
|
|
|
+ codeName = self.codeName(words)
|
|
|
|
|
+ if len(codeName['name']) > 0:
|
|
|
|
|
+ fund = 0
|
|
|
|
|
+ market = '0'
|
|
|
|
|
+ for m in range(i+1,len(list)):
|
|
|
|
|
+ mdic = list[m]
|
|
|
|
|
+ mloc = mdic['location']
|
|
|
|
|
+ loc = dic['location']
|
|
|
|
|
+ nstr = mdic['words']
|
|
|
|
|
+ if len(nstr) == 6 and ((',' not in nstr) or ('.' not in nstr)):
|
|
|
|
|
+ continue
|
|
|
|
|
+ if float(mloc['left']) < (float(loc['left']) + float(loc['width'])):
|
|
|
|
|
+ market = mdic['words']
|
|
|
|
|
+ break
|
|
|
|
|
+
|
|
|
|
|
+ if '万' in market:
|
|
|
|
|
+ fund = self.floatValue(market)
|
|
|
|
|
+ else:
|
|
|
|
|
+ fund = self.floatValue(market)/10000.0
|
|
|
|
|
+
|
|
|
|
|
+ if fund > 0:
|
|
|
|
|
+ ndic = {}
|
|
|
|
|
+ ndic['name'] = codeName['name']
|
|
|
|
|
+ ndic['code'] = codeName['code']
|
|
|
|
|
+ ndic['fund'] = str(round(fund,2))
|
|
|
|
|
+ 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
|
|
|
|
|
+ dic['today'] = round(today,2)
|
|
|
|
|
+
|
|
|
|
|
+ dic['list'] = self.lookCPMarket(list)
|
|
|
|
|
+
|
|
|
|
|
+ print(str(dic))
|
|
|
|
|
+
|
|
|
|
|
+ return dic
|
|
|
|
|
+
|
|
|
|
|
+ @classmethod
|
|
|
|
|
+ def lookCPMarket(self,list):
|
|
|
|
|
+ flist = []
|
|
|
|
|
+ index = self.indexEquel('市值',list)
|
|
|
|
|
+ if index == 0:
|
|
|
|
|
+ index = self.indexEquel('最新市值',list)
|
|
|
|
|
+
|
|
|
|
|
+ if index == 0:
|
|
|
|
|
+ index = self.indexEquel('最新沛值',list)
|
|
|
|
|
+
|
|
|
|
|
+ before = 0.0
|
|
|
|
|
+
|
|
|
|
|
+ if index - 1 > 0:
|
|
|
|
|
+ sdic = list[index-1]
|
|
|
|
|
+ sloc = sdic['location']
|
|
|
|
|
+
|
|
|
|
|
+ before = float(sloc['left']) + float(sloc['width'])
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ for i in range(index,len(list)):
|
|
|
|
|
+ dic = list[i]
|
|
|
|
|
+ words = dic['words']
|
|
|
|
|
+ words = self.replaceWords(words)
|
|
|
|
|
+ codeName = ''
|
|
|
|
|
+ clist = self.seperateChinense(words)
|
|
|
|
|
+ for sword in clist:
|
|
|
|
|
+ codeName = self.codeName(sword)
|
|
|
|
|
+ if len(codeName['name']) > 0:
|
|
|
|
|
+ break
|
|
|
|
|
+ if len(codeName['name']) > 0:
|
|
|
|
|
+ fund = 0
|
|
|
|
|
+ market = '0'
|
|
|
|
|
+ for m in range(i+1,len(list)):
|
|
|
|
|
+ mdic = list[m]
|
|
|
|
|
+ mloc = mdic['location']
|
|
|
|
|
+
|
|
|
|
|
+ if float((mloc['left'])) > before:
|
|
|
|
|
+ market = mdic['words']
|
|
|
|
|
+ # print('market:' + str(mdic))
|
|
|
|
|
+ break
|
|
|
|
|
+
|
|
|
|
|
+ if '万' in market:
|
|
|
|
|
+ fund = self.floatValue(market)
|
|
|
|
|
+ else:
|
|
|
|
|
+ fund = self.floatValue(market)/10000.0
|
|
|
|
|
+
|
|
|
|
|
+ if fund > 0:
|
|
|
|
|
+ ndic = {}
|
|
|
|
|
+ ndic['name'] = codeName['name']
|
|
|
|
|
+ ndic['code'] = codeName['code']
|
|
|
|
|
+ ndic['fund'] = str(round(fund,2))
|
|
|
|
|
+ flist.append(ndic)
|
|
|
|
|
+
|
|
|
|
|
+ return flist
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ @classmethod
|
|
|
|
|
+ def caculateAsset(self,list,word):
|
|
|
|
|
+ strAsset = '0'
|
|
|
|
|
+ i = 0
|
|
|
|
|
+ for i in range(len(list)):
|
|
|
|
|
+ dic = list[i]
|
|
|
|
|
+ words = dic['words']
|
|
|
|
|
+ if word in words:
|
|
|
|
|
+ for j in range(i+1,len(list)):
|
|
|
|
|
+ ndic = list[j]
|
|
|
|
|
+ idic = dic['location']
|
|
|
|
|
+ jdic = ndic['location']
|
|
|
|
|
+ ix = float(idic['left'])
|
|
|
|
|
+ jx = float(jdic['left']) - 30
|
|
|
|
|
+ width = float(jdic['width'])
|
|
|
|
|
+ if jx < ix and ix < (jx + width):
|
|
|
|
|
+ strAsset = ndic['words']
|
|
|
|
|
+ break
|
|
|
|
|
+
|
|
|
|
|
+ return strAsset
|
|
|
|
|
+
|
|
|
|
|
+ @classmethod
|
|
|
|
|
+ def deleteWords(self,words):
|
|
|
|
|
+ words = words.replace('⊙','')
|
|
|
|
|
+ words = words.replace('¥','')
|
|
|
|
|
+ words = words.replace('¥','')
|
|
|
|
|
+ words = words.replace(' ','')
|
|
|
|
|
+
|
|
|
|
|
+ return words
|
|
|
|
|
+
|
|
|
|
|
+ @classmethod
|
|
|
|
|
+ def wordsSeperate(self,words):
|
|
|
|
|
+ list = []
|
|
|
|
|
+ for word in words:
|
|
|
|
|
+ nlist = self.seperateChinense(word)
|
|
|
|
|
+ if len(nlist) > 0:
|
|
|
|
|
+ list.extend(nlist)
|
|
|
|
|
+
|
|
|
|
|
+ return list
|
|
|
|
|
+
|
|
|
|
|
+ @classmethod
|
|
|
|
|
+ def seperateChinense(self,word):
|
|
|
|
|
+ list = []
|
|
|
|
|
+ cword = ''
|
|
|
|
|
+ nword = ''
|
|
|
|
|
+ for strw in word:
|
|
|
|
|
+ if self.isChinese(strw) or strw == '(' or strw == ')':
|
|
|
|
|
+ if len(cword) == 0:
|
|
|
|
|
+ if len(nword) > 0:
|
|
|
|
|
+ list.append(nword)
|
|
|
|
|
+ nword = ''
|
|
|
|
|
+
|
|
|
|
|
+ cword += strw
|
|
|
|
|
+
|
|
|
|
|
+ else:
|
|
|
|
|
+ if len(nword) == 0:
|
|
|
|
|
+ if len(cword) > 0:
|
|
|
|
|
+ list.append(cword)
|
|
|
|
|
+ cword = ''
|
|
|
|
|
+ if strw == '-' or strw == ':':
|
|
|
|
|
+ if len(nword) > 0:
|
|
|
|
|
+ list.append(nword)
|
|
|
|
|
+ nword = ''
|
|
|
|
|
+ else:
|
|
|
|
|
+ nword += strw
|
|
|
|
|
+
|
|
|
|
|
+ if self.isChinese(word[0]):
|
|
|
|
|
+ if len(cword) > 0:
|
|
|
|
|
+ list.append(cword)
|
|
|
|
|
+ cword = ''
|
|
|
|
|
+
|
|
|
|
|
+ if len(nword) > 0:
|
|
|
|
|
+ if nword.find('+') >= 0:
|
|
|
|
|
+ jlist = nword.split('+')
|
|
|
|
|
+ for jstr in jlist:
|
|
|
|
|
+ if len(jstr) > 0:
|
|
|
|
|
+ list.append(jstr)
|
|
|
|
|
+
|
|
|
|
|
+ if nword.find('-') >= 0:
|
|
|
|
|
+ jlist = nword.split('-')
|
|
|
|
|
+ for jstr in jlist:
|
|
|
|
|
+ if len(jstr) > 0:
|
|
|
|
|
+ list.append(jstr)
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ if nword.find('+') < 0 and nword.find('-'):
|
|
|
|
|
+ list.append(nword)
|
|
|
|
|
+
|
|
|
|
|
+ nword = ''
|
|
|
|
|
+ else:
|
|
|
|
|
+
|
|
|
|
|
+ if len(nword) > 0:
|
|
|
|
|
+ if nword.find('+') >= 0:
|
|
|
|
|
+ jlist = nword.split('+')
|
|
|
|
|
+ for jstr in jlist:
|
|
|
|
|
+ if len(jstr) > 0:
|
|
|
|
|
+ list.append(jstr)
|
|
|
|
|
+
|
|
|
|
|
+ if nword.find('-') >= 0:
|
|
|
|
|
+ jlist = nword.split('-')
|
|
|
|
|
+ for jstr in jlist:
|
|
|
|
|
+ if len(jstr) > 0:
|
|
|
|
|
+ list.append(jstr)
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ if nword.find('+') < 0 and nword.find('-'):
|
|
|
|
|
+ list.append(nword)
|
|
|
|
|
+
|
|
|
|
|
+ nword = ''
|
|
|
|
|
+
|
|
|
|
|
+ if len(cword) > 0:
|
|
|
|
|
+ list.append(cword)
|
|
|
|
|
+ cword = ''
|
|
|
|
|
+
|
|
|
|
|
+ return list
|
|
|
|
|
+
|
|
|
|
|
+ @classmethod
|
|
|
|
|
+ def codeName(self,words):
|
|
|
|
|
+ codeName = ''
|
|
|
|
|
+ code = None
|
|
|
|
|
+ if len(words) >= 3:
|
|
|
|
|
+ nstr = words[:3]
|
|
|
|
|
+ code = stock_cache.get_code_by_name(nstr)
|
|
|
|
|
+ if code is not None:
|
|
|
|
|
+ codeName = nstr
|
|
|
|
|
+
|
|
|
|
|
+ if len(words) >= 4:
|
|
|
|
|
+ nstr = words[:4]
|
|
|
|
|
+ code = stock_cache.get_code_by_name(nstr)
|
|
|
|
|
+ if code is not None:
|
|
|
|
|
+ codeName = nstr
|
|
|
|
|
+
|
|
|
|
|
+ if len(words) >= 5:
|
|
|
|
|
+ nstr = words[:2]
|
|
|
|
|
+ code = stock_cache.get_code_by_name(nstr)
|
|
|
|
|
+ if code is not None:
|
|
|
|
|
+ codeName = nstr
|
|
|
|
|
+
|
|
|
|
|
+ dic = {}
|
|
|
|
|
+ dic['name'] = codeName
|
|
|
|
|
+ dic['code'] = code or ''
|
|
|
|
|
+
|
|
|
|
|
+ return dic
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ @classmethod
|
|
|
|
|
+ def isChinese(self,word):
|
|
|
|
|
+ for ch in word:
|
|
|
|
|
+ if u'\u4e00' <= ch <= u'\u9fff':
|
|
|
|
|
+ return True
|
|
|
|
|
+
|
|
|
|
|
+ return False
|
|
|
|
|
+
|
|
|
|
|
+ @classmethod
|
|
|
|
|
+ def assetWords(self,words):
|
|
|
|
|
+ asset = ''
|
|
|
|
|
+ index = self.indexWords('净资产',words)
|
|
|
|
|
+ if index >= 0:
|
|
|
|
|
+ asset = self.maxWords(words,asset,'净资产')
|
|
|
|
|
+ else:
|
|
|
|
|
+ asset = self.maxWords(words,asset,'总资产')
|
|
|
|
|
+ asset = self.maxWords(words,asset,'人民币')
|
|
|
|
|
+ asset = self.maxWords(words,asset,'CNY')
|
|
|
|
|
+ asset = self.maxWords(words,asset,'当日参考盈亏')
|
|
|
|
|
+ asset = self.maxWords(words,asset,'资产')
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ if self.floatValue(asset) > 0:
|
|
|
|
|
+ location = asset.find('.')
|
|
|
|
|
+ if self.isChinese(asset):
|
|
|
|
|
+ if location >= 0 and len(asset) >= location + 3:
|
|
|
|
|
+ asset = asset[:location+3]
|
|
|
|
|
+ if location >= 0 and len(asset) >= location + 3:
|
|
|
|
|
+ asset = asset[:location+3]
|
|
|
|
|
+ elif location < 0:
|
|
|
|
|
+ asset = str(self.floatValue(asset)/100.0)
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ return asset
|
|
|
|
|
+
|
|
|
|
|
+ @classmethod
|
|
|
|
|
+ def maxWords(self,words,strWord,contain):
|
|
|
|
|
+ strMax = '0'
|
|
|
|
|
+ for i in range(len(words)):
|
|
|
|
|
+ word = words[i]
|
|
|
|
|
+ if word.find('证券持仓') >= 0 or word.find('证券代码') >= 0 :
|
|
|
|
|
+ break
|
|
|
|
|
+
|
|
|
|
|
+ if word.find(contain) >= 0:
|
|
|
|
|
+ for j in range(i+1,len(words)):
|
|
|
|
|
+ nword = words[j]
|
|
|
|
|
+ nword = self.replaceWords(nword)
|
|
|
|
|
+ nword = self.replaceDot(nword)
|
|
|
|
|
+
|
|
|
|
|
+ if self.floatValue(nword) > self.floatValue(strMax):
|
|
|
|
|
+ strMax = nword
|
|
|
|
|
+ if j+1 < len(words):
|
|
|
|
|
+ w = words[j+1]
|
|
|
|
|
+ w = w.replace(',','')
|
|
|
|
|
+
|
|
|
|
|
+ if w == '万':
|
|
|
|
|
+ strMax = str(self.floatValue(strMax)*10000)
|
|
|
|
|
+
|
|
|
|
|
+ break
|
|
|
|
|
+
|
|
|
|
|
+ if self.floatValue(strMax) > 0:
|
|
|
|
|
+ break
|
|
|
|
|
+
|
|
|
|
|
+ if self.floatValue(strMax) > self.floatValue(strWord):
|
|
|
|
|
+ return strMax
|
|
|
|
|
+
|
|
|
|
|
+ return strWord
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ @classmethod
|
|
|
|
|
+ def replaceWords(self,words):
|
|
|
|
|
+ words = words.replace(' ','')
|
|
|
|
|
+ words = words.replace('\n','')
|
|
|
|
|
+ words = words.replace(',','')
|
|
|
|
|
+ words = words.replace('%','')
|
|
|
|
|
+ words = words.replace(',','')
|
|
|
|
|
+ words = words.replace(':','')
|
|
|
|
|
+ words = words.replace(':','')
|
|
|
|
|
+ words = words.replace('A','')
|
|
|
|
|
+ words = words.upper()
|
|
|
|
|
+
|
|
|
|
|
+ return words
|
|
|
|
|
+
|
|
|
|
|
+ @classmethod
|
|
|
|
|
+ def replaceDot(self,words):
|
|
|
|
|
+ list = words.split('.')
|
|
|
|
|
+ if len(list) <= 2:
|
|
|
|
|
+ return words
|
|
|
|
|
+
|
|
|
|
|
+ strWords = ''
|
|
|
|
|
+ i = 0
|
|
|
|
|
+ for i in range(len(list)):
|
|
|
|
|
+ strWords += list[i]
|
|
|
|
|
+ if i == len(list) - 2:
|
|
|
|
|
+ strWords += '.'
|
|
|
|
|
+
|
|
|
|
|
+ return strWords
|
|
|
|
|
+
|
|
|
|
|
+ @classmethod
|
|
|
|
|
+ def indexWords(self,words,list):
|
|
|
|
|
+ index = -1
|
|
|
|
|
+ i = 0
|
|
|
|
|
+ for i in range(len(list)):
|
|
|
|
|
+ if words == list[i]:
|
|
|
|
|
+ index = i
|
|
|
|
|
+ break
|
|
|
|
|
+
|
|
|
|
|
+ return index
|
|
|
|
|
+
|
|
|
|
|
+ @classmethod
|
|
|
|
|
+ def indexObject(self,words,list):
|
|
|
|
|
+ index = -1
|
|
|
|
|
+ i=0
|
|
|
|
|
+ for i in range(len(list)):
|
|
|
|
|
+ dic = list[i]
|
|
|
|
|
+ nword = dic['words']
|
|
|
|
|
+ if words in nword:
|
|
|
|
|
+ index = i
|
|
|
|
|
+ break
|
|
|
|
|
+
|
|
|
|
|
+ return index
|
|
|
|
|
+
|
|
|
|
|
+ @classmethod
|
|
|
|
|
+ def indexEquel(self,words,list):
|
|
|
|
|
+ index = -1
|
|
|
|
|
+ i=0
|
|
|
|
|
+ for i in range(len(list)):
|
|
|
|
|
+ dic = list[i]
|
|
|
|
|
+ nword = dic['words']
|
|
|
|
|
+ if words == nword:
|
|
|
|
|
+ index = i
|
|
|
|
|
+ break
|
|
|
|
|
+
|
|
|
|
|
+ return index
|
|
|
|
|
+
|
|
|
|
|
+ @classmethod
|
|
|
|
|
+ def isNumber(self,number):
|
|
|
|
|
+ number = number.replace(',','')
|
|
|
|
|
+ if self.isChinese(number):
|
|
|
|
|
+ # print('ischinese:' + number)
|
|
|
|
|
+ return False
|
|
|
|
|
+
|
|
|
|
|
+ zhengshu = r'^([1-9][\d]*|0)(\.[\d]+)?$'
|
|
|
|
|
+ if re.match(zhengshu, str(number)):
|
|
|
|
|
+ return True
|
|
|
|
|
+ else:
|
|
|
|
|
+ return False
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ # pattern = r'^[0-9]+\.[0-9]+$' # 匹配小数的正则表达式
|
|
|
|
|
+ # if re.match(pattern, str(number)):
|
|
|
|
|
+ # return True
|
|
|
|
|
+ # else:
|
|
|
|
|
+ # return False
|
|
|
|
|
+
|
|
|
|
|
+ @classmethod
|
|
|
|
|
+ def floatValue(self,word):
|
|
|
|
|
+ word = self.replaceWords(word)
|
|
|
|
|
+ word = self.replaceDot(word)
|
|
|
|
|
+
|
|
|
|
|
+ if not self.isNumber(word):
|
|
|
|
|
+ return 0
|
|
|
|
|
+
|
|
|
|
|
+ if word == '':
|
|
|
|
|
+ return 0
|
|
|
|
|
+
|
|
|
|
|
+ # print('floatValue:' + word)
|
|
|
|
|
+
|
|
|
|
|
+ return float(word)
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+if __name__ == '__main__':
|
|
|
|
|
+ print('ocr')
|
|
|
|
|
+
|