In [1]:
import pyrebase
import time
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]:
import unidecode
import numpy as np
import matplotlib.pyplot as plt
def plot_polarity_subjectivity(listed_name_on_database):
pol = []
sub = []
articles_of_a_newspaper = db.child(str("articles/" + listed_name_on_database)).get()
articles = articles_of_a_newspaper.val()
for article_no in range(len(articles)):
data = list(articles.items())[article_no][1]
pol.append(abs(float(data["polarity"])))
sub.append(float(data["subjectivity"]))
plt.scatter(pol,sub,[80/np.sqrt(len(pol))]*len(sub), alpha=0.7, label = listed_name_on_database)
return np.column_stack((pol, sub))
In [4]:
plt.clf()
plt.figure(figsize=(12, 10))
plt.title("Scatter Plot (Articles)")
websites = ["wwwchannelnewsasiacom","wwwstraitstimescom","wwwtnpsg","wwwtodayonlinecom",
"sgnewsyahoocom","sgfinanceyahoocom","stompstraitstimescom","mothershipsg",
"thehearttruthscom","wwwtremerituscom","yawningbreadwordpresscom",
"wwwtheonlinecitizencom","wwwallsingaporestuffcom","alvinologycom","berthahensonwordpresscom"]
centroid ={}
for website in websites:
data = plot_polarity_subjectivity(website)
time.sleep(0.2)
centroid[website] = np.mean(data, axis=0)
plt.legend(loc=4)
plt.xlabel("Polarity")
plt.ylabel("Subjectivity")
plt.show()
In [5]:
plt.clf()
plt.figure(figsize=(12, 10))
plt.title("Centroids (Sources)")
mothershipsg = centroid["wwwchannelnewsasiacom"]
plt.scatter(mothershipsg[0],mothershipsg[1],label="wwwchannelnewsasiacom")
#plt.annotate("wwwchannelnewsasiacom",(mothershipsg[0],mothershipsg[1]))
mothershipsg = centroid["wwwstraitstimescom"]
plt.scatter(mothershipsg[0],mothershipsg[1],label="wwwstraitstimescom")
#plt.annotate("wwwstraitstimescom",(mothershipsg[0],mothershipsg[1]))
mothershipsg = centroid["wwwtnpsg"]
plt.scatter(mothershipsg[0],mothershipsg[1],label="wwwtnpsg")
#plt.annotate("wwwtnpsg",(mothershipsg[0],mothershipsg[1]))
mothershipsg = centroid["wwwtodayonlinecom"]
plt.scatter(mothershipsg[0],mothershipsg[1],label="wwwtodayonlinecom")
#plt.annotate("wwwtodayonlinecom",(mothershipsg[0],mothershipsg[1]))
mothershipsg = centroid["mothershipsg"]
plt.scatter(mothershipsg[0],mothershipsg[1],label="mothership")
#plt.annotate("mothership",(mothershipsg[0],mothershipsg[1]))
mothershipsg = centroid["sgnewsyahoocom"]
plt.scatter(mothershipsg[0],mothershipsg[1],label="sgnewsyahoocom")
#plt.annotate("sgnewsyahoocom",(mothershipsg[0],mothershipsg[1]))
mothershipsg = centroid["sgfinanceyahoocom"]
plt.scatter(mothershipsg[0],mothershipsg[1],label="sgfinanceyahoocom")
#plt.annotate("sgfinanceyahoocom",(mothershipsg[0],mothershipsg[1]))
mothershipsg = centroid["stompstraitstimescom"]
plt.scatter(mothershipsg[0],mothershipsg[1],label="stompstraitstimescom")
#plt.annotate("stompstraitstimescom",(mothershipsg[0],mothershipsg[1]))
mothershipsg = centroid["alvinologycom"]
plt.scatter(mothershipsg[0],mothershipsg[1],label="alvinologycom")
#plt.annotate("alvinologycom",(mothershipsg[0],mothershipsg[1]))
mothershipsg = centroid["wwwallsingaporestuffcom"]
plt.scatter(mothershipsg[0],mothershipsg[1],label="wwwallsingaporestuffcom")
#plt.annotate("wwwallsingaporestuffcom",(mothershipsg[0],mothershipsg[1]))
mothershipsg = centroid["wwwtheonlinecitizencom"]
plt.scatter(mothershipsg[0],mothershipsg[1],label="wwwtheonlinecitizencom")
#plt.annotate("wwwtheonlinecitizencom",(mothershipsg[0],mothershipsg[1]))
mothershipsg = centroid["wwwtremerituscom"]
plt.scatter(mothershipsg[0],mothershipsg[1],label="wwwtremerituscom")
#plt.annotate("wwwtremerituscom",(mothershipsg[0],mothershipsg[1]))
mothershipsg = centroid["thehearttruthscom"]
plt.scatter(mothershipsg[0],mothershipsg[1],label="thehearttruthscom")
#plt.annotate("thehearttruthscom",(mothershipsg[0],mothershipsg[1]))
mothershipsg = centroid["berthahensonwordpresscom"]
plt.scatter(mothershipsg[0],mothershipsg[1],label="berthahensonwordpresscom")
#plt.annotate("berthahensonwordpresscom",(mothershipsg[0],mothershipsg[1]))
mothershipsg = centroid["yawningbreadwordpresscom"]
plt.scatter(mothershipsg[0],mothershipsg[1],label="yawningbreadwordpresscom")
#plt.annotate("yawningbreadwordpresscom",(mothershipsg[0],mothershipsg[1]))
plt.xlabel("Polarity")
plt.ylabel("Subjectivity")
plt.legend(loc=4)
plt.show()
In [ ]: