I am trying to extract some information from Wikipedia. and I want to save those information in google firebase Real time data base.
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
But when the variable changes It value then the previous tag and value of firebase real time data base got deleted. Please help me to solve this.
Since you're calling:
ref.set({name:page})
The set
operation (as its name implies) sets the value you pass on that path in the database. And since ref
is always the same path, each page you read overwrites the previous page in the database.
If you want to save a list of data, use the push
operation:
new_page_ref = ref.push()
new_page_ref.set({name:page})