Firebase 数据不可用

Firebase data is not going

我正在尝试从维基百科中提取一些信息。我想将这些信息保存在 google firebase 实时数据库中。

import openpyxl  
import firebase_admin
from firebase_admin import credentials
from firebase_admin import db
from openpyxl import Workbook 
import wikipedia
numberrow = 0
links = ["Xanthomonas campestris","Corynespora cassiicola","Myrothecium roridum","Phytophthora nicotianae var. parasitica","Phytophthora parasitica","Rhizoctonia solani","Thanatephorus cucumeris","Sclerotium rolfsii","Athelia rolfsii","Nectriella pironii","Cucumber mosaic virus","Bidens mottle virus","Tomato spotted wilt virus","Ralstonia solanacearum","Ascochyta doronici","Alternaria alternata","Alternaria dauci","Alternaria gerberae","Thielaviopsis basicola","Botrytis cinerea","Cercospora gerberae","Plasmopara","Fusarium solani","Fusarium oxysporum","Fungi ContigugliI","Phyllosticta","Phytophthora cryptogea","Erysiphe cichoracearum","Sphaerotheca","Pythium","Rhizopus stolonifer","Septoria","Verticillium albo-atrum"]
test=[]
name =""
cred = credentials.Certificate('plant-diseases-expert-firebase-adminsdk-k2fn6-ab397a7bdb.json')
firebase_admin.initialize_app(cred, {
    'databaseURL': 'https://plant-diseases-expert-default-rtdb.firebaseio.com/'
}) 
#workbook = Workbook() 

#workbook.save(filename="sample.xlsx")
ref = db.reference('/')

for link in links:
    try:
        #try to load the wikipedia page
        numberrow = numberrow +1
        print(numberrow)
        page=wikipedia.summary(link, sentences = 3, auto_suggest=False)
        test.append(page)
        name = link.lower()
        
        ref.set({name:page})
        print (name)
        #wb = openpyxl.Workbook()  
        #sheet = wb.active 
        #c1 = sheet.cell(row = numberrow, column = 1)  
        #c1.value = name
        #c2 = sheet.cell(row= numberrow, column = 2)  
        #c2.value = page
        #wb.save("sample.xlsx")

        print(page)
        empty_str(name)
        empty_str(page)
        
        
    except Exception:
        continue

但是当变量改变它的值时,firebase 实时数据库的先前标记和值被删除。 请帮我解决这个问题。

因为你打电话:

ref.set({name:page})

set 操作(顾名思义)设置您在数据库中该路径上传递的值。由于 ref 始终是同一路径,因此您读取的每一页都会覆盖数据库中的前一页。

如果要save a list of data,使用push操作:

new_page_ref = ref.push()
new_page_ref.set({name:page})