django - Firestore 文档不包含任何数据
问题描述
我有一个 Django 应用程序,可以使用 OCR pytesseract 从他们的盒子中识别药物。获得名称后,我从该网站http://www.dpm.tn/dpm_pharm/medicament/listmedicspec.php抓取数据。最后,在获得具有该药物名称的所有必要数据后,我将其存储在 Firestore 中,但它显示“此文档不包含任何数据”,这是 OCR 的代码:
def ocr_title(im):
image = cv2.imread(im, 0)
img = cv2.resize(image, (500, 500))
img = cv2.GaussianBlur(img, (5, 5), 0)
img = cv2.adaptiveThreshold(img, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY, 21, 4)
himg, wimg = img.shape
maxw = 0
text = ''
title = pytesseract.image_to_data(img, config='--psm 6 --oem 3')
for x, b in enumerate(title.splitlines()):
if x != 0:
b = b.split()
if len(b) == 12 and len(b[11]) >= 4:
if (int(b[8]) > maxw):
maxh = int(b[9])
maxx = int(b[6])
maxy = int(b[7])
maxw = int(b[8])
text = b[11]
text = re.sub(r'[^\w]', '', text)
text = str(text)
return (text)
这是我在抓取后存储数据的代码(ps:它在 Beautifulsoup 中):
for i in range(1, len(names)):
try:
name = names[i]
dosage = dosages[i]
url_product = links[i-1]
response = requests.post(url_product)
soup = BeautifulSoup(response.content, 'lxml')
detail_table = soup.find("table")
trs = detail_table.find_all('tr')
detail = soup.find("font", {"color": "#006699"}).text
form = forms[i]
data= {
"name": name,
"dosage": dosage,
"form": form,
"detail": detail
}
med_dosage = dosage.replace(" ", "")
med_dosage = medecine.lower()+' '+med_dosage.lower()
med_form = form.replace(" ", "")
med_form = form.lower()
#database.child(medecine).child(med_form).child(med_dosage).set(data)
#db.collection('medecine').collection(medecine).collection(med_form).document(med_dosage).add({
# "name": name,
# "dosage": dosage,
# "form": form,
# "detail": detail
#})
dbmedecine = db.collection('medecine')
namemedecine = dbmedecine.document(medecine.lower())
store = namemedecine.get()
store.collection(med_form).document(med_dosage).set(data)
#.collection(med_form).document(med_dosage).set(data)
print('savee')
except:
print("errooooooooooooor")
print(i)
解决方案
推荐阅读
- ios - iOS 13 中使用 Quickblox 和 CallKit 的来电视频通话问题
- python - 删除坐标列表中的重叠值
- c# - 为什么我可以手动组合变量来创建 Const 字符串,但不能使用 Concat 或字符串插值?
- java - 如何在 JAVA 中检查 Object 的变量是 Empty 还是 NULL?
- cypress - 柏。获取打开的标签列表
- postgresql - PostgreSQL 用 typeorm 设置运行时变量,如何确保会话是隔离的?
- xcode - 模拟器的Xcode 12构建目标顺序错误?
- android-studio - 你可以通过 Flutter 中的多个小部件传递相机吗
- google-cloud-platform - 触发警报 BigQuery
- javascript - 在反应js中更改具有相同ID的多个输入字段的值