1
0
Fork 0
mirror of https://github.com/Lynnesbian/FediBooks/ synced 2024-11-25 16:48:58 +00:00

display posts in DB on /bot/accounts

This commit is contained in:
Lynne Megido 2019-09-06 12:47:39 +10:00
parent fc45f4c4c0
commit c38f01b07a
3 changed files with 10 additions and 2 deletions

View file

@ -100,3 +100,5 @@ accounts = cursor.fetchall()
cursor.close() cursor.close()
with Pool(8) as p: with Pool(8) as p:
p.map(scrape_posts, accounts) p.map(scrape_posts, accounts)
#TODO: other cron tasks should be done here, like updating profile pictures

View file

@ -23,7 +23,7 @@
<div class="panel-text"> <div class="panel-text">
{% set handle_list = user['fedi_id'].split('@') %} {% set handle_list = user['fedi_id'].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>
<div class="panel-status">{{ "Active" if user['enabled'] else "Inactive" }}</div> <div class="panel-status">{{ "Active" if user['enabled'] else "Inactive" }}, {{ post_count[user['fedi_id']] }} posts in database</div>
</div> </div>
<div class="panel-actions"> <div class="panel-actions">
<a class="button btn-secondary" href="/bot/accounts/toggle/{{ user['fedi_id'] }}" title="Turn on/off"><i class="fas fa-power-off"></i></a><a class="button btn-dangerous" href="/bot/accounts/delete/{{ user['fedi_id'] }}" title="Delete"><i class="fas fa-trash"></i></a> <a class="button btn-secondary" href="/bot/accounts/toggle/{{ user['fedi_id'] }}" title="Turn on/off"><i class="fas fa-power-off"></i></a><a class="button btn-dangerous" href="/bot/accounts/delete/{{ user['fedi_id'] }}" title="Delete"><i class="fas fa-trash"></i></a>

View file

@ -128,6 +128,7 @@ def bot_accounts(id):
c.execute("SELECT COUNT(*) FROM `bot_learned_accounts` WHERE `bot_id` = %s", (id,)) c.execute("SELECT COUNT(*) FROM `bot_learned_accounts` WHERE `bot_id` = %s", (id,))
user_count = c.fetchone()[0] user_count = c.fetchone()[0]
users = {} users = {}
post_count = {}
if user_count > 0: if user_count > 0:
dc = mysql.connection.cursor(MySQLdb.cursors.DictCursor) dc = mysql.connection.cursor(MySQLdb.cursors.DictCursor)
@ -135,9 +136,14 @@ def bot_accounts(id):
users = dc.fetchall() users = dc.fetchall()
dc.close() dc.close()
post_count = {}
for user in users:
c.execute("SELECT COUNT(*) FROM `posts` WHERE `fedi_id` = %s", (user['fedi_id'],))
post_count[user['fedi_id']] = c.fetchone()[0]
c.close() c.close()
return render_template("bot_accounts.html", users = users) return render_template("bot_accounts.html", users = users, post_count = post_count)
@app.route("/bot/accounts/add", methods = ['GET', 'POST']) @app.route("/bot/accounts/add", methods = ['GET', 'POST'])
def bot_accounts_add(): def bot_accounts_add():