mirror of
https://github.com/Lynnesbian/FediBooks/
synced 2024-11-26 00:58:59 +00:00
Compare commits
No commits in common. "001dbadf9e3b63be0d35cef869e2106de6b8940d" and "fc8be5db40ee6bdd4852e20bf62beb81b45b8f7a" have entirely different histories.
001dbadf9e
...
fc8be5db40
8 changed files with 7 additions and 67 deletions
|
@ -1,6 +0,0 @@
|
||||||
__pycache__
|
|
||||||
config.json
|
|
||||||
planning.txt
|
|
||||||
README.md
|
|
||||||
.git
|
|
||||||
.vscode
|
|
|
@ -1,4 +0,0 @@
|
||||||
FROM python:3.7-slim-buster
|
|
||||||
WORKDIR /fedibooks
|
|
||||||
COPY . fedibooks
|
|
||||||
RUN pip install -r requirements.txt
|
|
|
@ -1,15 +0,0 @@
|
||||||
version: '3'
|
|
||||||
services:
|
|
||||||
fedibooks:
|
|
||||||
build: .
|
|
||||||
links:
|
|
||||||
- db
|
|
||||||
ports:
|
|
||||||
5000:5000
|
|
||||||
db:
|
|
||||||
image: mariadb/server:10.4
|
|
||||||
environment:
|
|
||||||
MARIADB_ROOT_PASSWORD: root
|
|
||||||
MARIADB_DATABASE: fedibooks
|
|
||||||
MARIADB_USER: fedibooks
|
|
||||||
MARIADB_PASSWORD: fedibooks
|
|
|
@ -1,6 +1,6 @@
|
||||||
Mastodon.py==1.4.6
|
Mastodon.py==1.4.6
|
||||||
markovify==0.7.2
|
markovify==0.7.1
|
||||||
beautifulsoup4==4.8.0
|
beautifulsoup4==4.7.1
|
||||||
requests==2.22.0
|
requests==2.22.0
|
||||||
Flask==1.1.1
|
Flask==1.1.1
|
||||||
flask-mysqldb==0.2.0
|
flask-mysqldb==0.2.0
|
||||||
|
|
39
service.py
39
service.py
|
@ -1,35 +1,11 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
import MySQLdb
|
import MySQLdb
|
||||||
from mastodon import Mastodon
|
|
||||||
from multiprocessing import Pool
|
from multiprocessing import Pool
|
||||||
import json
|
import json
|
||||||
import functions
|
import functions
|
||||||
|
|
||||||
cfg = json.load(open('config.json'))
|
cfg = json.load(open('config.json'))
|
||||||
|
|
||||||
def update_icon(bot):
|
|
||||||
db = MySQLdb.connect(
|
|
||||||
host = cfg['db_host'],
|
|
||||||
user=cfg['db_user'],
|
|
||||||
passwd=cfg['db_pass'],
|
|
||||||
db=cfg['db_name'],
|
|
||||||
use_unicode=True,
|
|
||||||
charset="utf8mb4"
|
|
||||||
)
|
|
||||||
|
|
||||||
print("Updating cached icon for {}".format(bot['handle']))
|
|
||||||
client = Mastodon(
|
|
||||||
client_id = bot['client_id'],
|
|
||||||
client_secret = bot['client_secret'],
|
|
||||||
access_token = bot['secret'],
|
|
||||||
api_base_url = "https://{}".format(bot['handle'].split("@")[2])
|
|
||||||
)
|
|
||||||
|
|
||||||
avatar = client.account_verify_credentials()['avatar']
|
|
||||||
c = db.cursor()
|
|
||||||
c.execute("UPDATE bots SET icon = %s, icon_update_time = CURRENT_TIMESTAMP() WHERE handle = %s", (avatar, bot['handle']))
|
|
||||||
db.commit()
|
|
||||||
|
|
||||||
print("Establishing DB connection")
|
print("Establishing DB connection")
|
||||||
db = MySQLdb.connect(
|
db = MySQLdb.connect(
|
||||||
host = cfg['db_host'],
|
host = cfg['db_host'],
|
||||||
|
@ -47,23 +23,12 @@ cursor.execute("DELETE FROM fedi_accounts WHERE handle NOT IN (SELECT fedi_id FR
|
||||||
db.commit()
|
db.commit()
|
||||||
|
|
||||||
print("Generating posts")
|
print("Generating posts")
|
||||||
cursor.execute("SELECT handle FROM bots WHERE enabled = TRUE AND TIMESTAMPDIFF(MINUTE, last_post, CURRENT_TIMESTAMP()) >= post_frequency")
|
cursor.execute("SELECT handle FROM bots WHERE enabled = TRUE AND TIMESTAMPDIFF(MINUTE, last_post, CURRENT_TIMESTAMP()) > post_frequency")
|
||||||
bots = cursor.fetchall()
|
bots = cursor.fetchall()
|
||||||
|
|
||||||
with Pool(cfg['service_threads']) as p:
|
with Pool(cfg['service_threads']) as p:
|
||||||
p.map(functions.make_post, bots)
|
p.map(functions.make_post, bots)
|
||||||
|
|
||||||
print("Updating cached icons")
|
#TODO: other cron tasks should be done here, like updating profile pictures
|
||||||
dc = db.cursor(MySQLdb.cursors.DictCursor)
|
|
||||||
dc.execute("""
|
|
||||||
SELECT handle, instance_type, client_id, client_secret, secret
|
|
||||||
FROM bots
|
|
||||||
INNER JOIN credentials
|
|
||||||
ON bots.credentials_id = credentials.id
|
|
||||||
WHERE TIMESTAMPDIFF(HOUR, icon_update_time, CURRENT_TIMESTAMP()) > 2""")
|
|
||||||
bots = dc.fetchall()
|
|
||||||
|
|
||||||
with Pool(cfg['service_threads']) as p:
|
|
||||||
p.map(update_icon, bots)
|
|
||||||
|
|
||||||
db.commit()
|
db.commit()
|
||||||
|
|
|
@ -75,7 +75,7 @@ body {
|
||||||
}
|
}
|
||||||
.panel-text {
|
.panel-text {
|
||||||
flex-grow: 1;
|
flex-grow: 1;
|
||||||
margin: 0 0 10px 15px;
|
margin: 0 0 10px 10px;
|
||||||
}
|
}
|
||||||
.panel-name {
|
.panel-name {
|
||||||
font-size: 1.8em;
|
font-size: 1.8em;
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
<div class="container" style="min-height: 300px;">
|
<div class="container" style="min-height: 300px;">
|
||||||
{% for bot in bots %}
|
{% for bot in bots %}
|
||||||
<div class="row light">
|
<div class="row light">
|
||||||
<div class="panel-icon {{ "online" if bot['enabled'] else "offline"}}" style="{{ "background-image: url('" + bot['icon'] + "')" if bot['icon'] else "" }}"></div>
|
<div class="panel-icon {{ "online" if bot['enabled'] else "offline"}}"></div>
|
||||||
<div class="panel-text">
|
<div class="panel-text">
|
||||||
{% set handle_list = bot['handle'].split('@') %}
|
{% set handle_list = bot['handle'].split('@') %}
|
||||||
<div class="panel-name">@{{ handle_list[1] }}<span class="subtle tiny">@{{ handle_list[2] }}</span></div>
|
<div class="panel-name">@{{ handle_list[1] }}<span class="subtle tiny">@{{ handle_list[2] }}</span></div>
|
||||||
|
|
2
webui.py
2
webui.py
|
@ -44,7 +44,7 @@ def home():
|
||||||
c.execute("SELECT COUNT(*) FROM `bots` WHERE user_id = %s AND enabled = TRUE", (session['user_id'],))
|
c.execute("SELECT COUNT(*) FROM `bots` WHERE user_id = %s AND enabled = TRUE", (session['user_id'],))
|
||||||
active_count = c.fetchone()[0]
|
active_count = c.fetchone()[0]
|
||||||
dc = mysql.connection.cursor(MySQLdb.cursors.DictCursor)
|
dc = mysql.connection.cursor(MySQLdb.cursors.DictCursor)
|
||||||
dc.execute("SELECT `handle`, `enabled`, `last_post`, `post_frequency`, `icon` FROM `bots` WHERE user_id = %s", (session['user_id'],))
|
dc.execute("SELECT `handle`, `enabled`, `last_post`, `post_frequency` FROM `bots` WHERE user_id = %s", (session['user_id'],))
|
||||||
bots = dc.fetchall()
|
bots = dc.fetchall()
|
||||||
dc.close()
|
dc.close()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue