Merge branch 'main' into with_cites
This commit is contained in:
commit
09fd313a89
9 changed files with 124 additions and 118 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -9,3 +9,4 @@ test.py
|
||||||
.idea
|
.idea
|
||||||
cardiffnlp
|
cardiffnlp
|
||||||
venv
|
venv
|
||||||
|
logs.txt
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
from DbSetup import engine, session, databaseUrl
|
from DbSetup import connection, engine, session, databaseUrl
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
from sqlalchemy import desc, select
|
from sqlalchemy import desc, select, sql
|
||||||
from Tables import Toots
|
from Tables import Toots
|
||||||
|
|
||||||
def calculateSentimentCount():
|
def calculateSentimentCount():
|
||||||
|
|
@ -11,8 +11,8 @@ def calculateSentimentCount():
|
||||||
HAVING datetime >= DATE("now","-1 day")
|
HAVING datetime >= DATE("now","-1 day")
|
||||||
AND datetime < DATE("now")'''
|
AND datetime < DATE("now")'''
|
||||||
return pd.read_sql(
|
return pd.read_sql(
|
||||||
query,
|
sql.text(query),
|
||||||
databaseUrl,
|
connection,
|
||||||
parse_dates=["datetime"]
|
parse_dates=["datetime"]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -51,7 +51,7 @@ class CRUDManager():
|
||||||
print(f'Could not save data to {table}!')
|
print(f'Could not save data to {table}!')
|
||||||
|
|
||||||
def loadFromDatabase(self, table:str, indexColumn=None):
|
def loadFromDatabase(self, table:str, indexColumn=None):
|
||||||
return pd.read_sql_table(table, databaseUrl, index_col=indexColumn)
|
return pd.read_sql_table(table, connection, index_col=indexColumn)
|
||||||
|
|
||||||
def getLastToot(self):
|
def getLastToot(self):
|
||||||
stmt = select(Toots.tootId).order_by(desc('datetime'))
|
stmt = select(Toots.tootId).order_by(desc('datetime'))
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ from sqlalchemy.ext.declarative import declarative_base
|
||||||
|
|
||||||
databaseUrl = 'sqlite:///database.db'
|
databaseUrl = 'sqlite:///database.db'
|
||||||
engine = create_engine(databaseUrl, future=True)
|
engine = create_engine(databaseUrl, future=True)
|
||||||
|
connection = engine.connect()
|
||||||
session = Session(engine)
|
session = Session(engine)
|
||||||
Base = declarative_base()
|
Base = declarative_base()
|
||||||
|
|
||||||
|
|
|
||||||
4
Main.py
4
Main.py
|
|
@ -7,7 +7,7 @@ import matplotlib.pyplot as plt
|
||||||
import matplotlib.dates as mdates
|
import matplotlib.dates as mdates
|
||||||
from TootCrawler import TootCrawler
|
from TootCrawler import TootCrawler
|
||||||
|
|
||||||
locale.setlocale(locale.LC_TIME, "en_EN.UTF-8")
|
locale.setlocale(locale.LC_TIME, "en_US.UTF-8")
|
||||||
init_db()
|
init_db()
|
||||||
|
|
||||||
mastodonAccountManager = MastodonAccountManager()
|
mastodonAccountManager = MastodonAccountManager()
|
||||||
|
|
@ -84,7 +84,7 @@ axes[0].legend(pieChartlabels, loc='upper right', bbox_to_anchor=(0.9, 0.9))
|
||||||
# Line chart.
|
# Line chart.
|
||||||
lineChart = dataframe4LineChart.plot.line(
|
lineChart = dataframe4LineChart.plot.line(
|
||||||
ax=axes[1],
|
ax=axes[1],
|
||||||
title='Mean of all sentiments from max positive (1) to min negative (-1)'
|
title='"Mean" of sentiments, calculated from nominal values, pos(1), neu (0), neg (-1)!'
|
||||||
)
|
)
|
||||||
axes[1].grid(True)
|
axes[1].grid(True)
|
||||||
axes[1].set_xlim([date(2023, 1, 1), date(2023, 12, 31)])
|
axes[1].set_xlim([date(2023, 1, 1), date(2023, 12, 31)])
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,10 @@ class TootCrawler():
|
||||||
timelinePagination = self.mastodonInstance.fetch_previous(timelinePagination)
|
timelinePagination = self.mastodonInstance.fetch_previous(timelinePagination)
|
||||||
for i in allTimelineResults:
|
for i in allTimelineResults:
|
||||||
content = self.cleanhtml(i.content)
|
content = self.cleanhtml(i.content)
|
||||||
language = detect(content)
|
try:
|
||||||
|
language = detect(content)
|
||||||
|
except:
|
||||||
|
language = None
|
||||||
sentiment = self.sentiTooter.analyze(language, content)
|
sentiment = self.sentiTooter.analyze(language, content)
|
||||||
toot = {
|
toot = {
|
||||||
"sentiment": sentiment[0],
|
"sentiment": sentiment[0],
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,10 @@ matplotlib
|
||||||
pandas
|
pandas
|
||||||
sqlalchemy
|
sqlalchemy
|
||||||
vader-multi
|
vader-multi
|
||||||
|
langdetect
|
||||||
numpy
|
numpy
|
||||||
pytz
|
pytz
|
||||||
transformers
|
transformers
|
||||||
langdetect
|
wheel
|
||||||
germansentiment
|
germansentiment
|
||||||
scipy
|
scipy
|
||||||
Loading…
Add table
Add a link
Reference in a new issue