This demonstrates how to write to Firebase using the pyrebase library.
Insert %run 'firebasePush.ipynb' after your import statement.
s
After that, all you have to do is call sendToFirebase to upload the article data to Firebase.
firebasePush(title, url, authors, date, summary, polarity, subjectivity, keywords, images, videos, text)
In [1]:
import pyrebase
from urllib.parse import urlparse
config = {
"apiKey": "/////",
"authDomain": "fakenewsmustdie.firebaseapp.com",
"databaseURL": "https://fakenewsmustdie.firebaseio.com",
"storageBucket": "fakenewsmustdie.appspot.com"
}
In [2]:
firebase = pyrebase.initialize_app(config)
auth = firebase.auth()
uid = "////"
password = "////"
user = auth.sign_in_with_email_and_password(uid, password)
db = firebase.database() # reference to the database service
def firebaseRefresh():
global user
user = auth.refresh(user['refreshToken'])
In [3]:
def firebasePush(title, url, authors, date, summary, polarity, subjectivity, keywords, images, videos, text):
domain = urlparse(url).netloc
domain = domain.replace(".","")
date = str(date)
link = url
url = url.replace("/","")
url = url.replace(".","")
url = url.replace("http:","")
url = url.replace("https:","")
url = url.replace(domain,"")
url = url.split("?",1)[0]
url = url.split("#",1)[0]
text = text.replace("\n","")
data = {
"title": title,
"authors": authors,
"summary": summary,
"date": date,
"polarity": polarity,
"subjectivity": subjectivity,
"keywords": keywords,
"images": images,
"videos": videos,
"article": text,
"url": link
}
results = db.child("articles").child(domain).child(url).set(data, user['idToken'])
In [ ]:
In [ ]: