Skip to content

Commit

Permalink
code style adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
inflac committed Aug 26, 2024
1 parent 654f984 commit ee97163
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 19 deletions.
10 changes: 5 additions & 5 deletions html/extensions/cms/CMSConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def init_table(conn):
active BOOLEAN NOT NULL
);
"""

sql_add_config_entries = """
INSERT INTO CMSConfig (name, active)
VALUES (?, ?)
Expand Down Expand Up @@ -69,18 +69,18 @@ def activate(self):
UPDATE CMSConfig
SET active = ?
WHERE id = ?
""", (True, self.id))
""", (True, self.id))
conn.commit()
conn.close()

def deactivate(self):
conn = get_conn()
cur = conn.cursor()
cur.execute("""
UPDATE CMSConfig
SET active = ?
WHERE id = ?
""", (False, self.id))
""", (False, self.id))
conn.commit()
conn.close()

Expand Down Expand Up @@ -108,4 +108,4 @@ def get_setting_from_config(name:str):

setting = CMSConfig(row[0], row[1], row[2])

return setting
return setting
5 changes: 2 additions & 3 deletions html/extensions/mastodon/db_extension_mastodon_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ def get_mastodon_tag_by_name(tag_name: str):
if row:
tag = Tag(row[0], row[1], row[2])
return tag
else:
return None
return None

def get_all_mastodon_tags():
""" Query all tags from the Tags table """
Expand Down Expand Up @@ -93,7 +92,7 @@ def add_mastodon_tag(tag_name: str, tag_limit: int):
cur = conn.cursor()
cur.execute("INSERT INTO Tags (name, tag_limit) VALUES (?, ?)", (tag_name, tag_limit))
conn.commit()
except sqlite3.Error as e:
except sqlite3.Error:
return False
return True

Expand Down
6 changes: 3 additions & 3 deletions html/extensions/mastodon/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def create_slides(hashtag:str, limit:int):

URL = f'https://mastodon.social/api/v1/timelines/tag/{hashtag}'

r = requests.get(URL, params={'limit': limit})
r = requests.get(URL, params={'limit': limit}, timeout=10)
toots = json.loads(r.text)

# Create pandas data frames from toots
Expand All @@ -24,8 +24,8 @@ def create_slides(hashtag:str, limit:int):
one_hour_ago = pd.Timestamp.now(tz='Europe/Berlin') - pd.Timedelta(hours=3)
filtered_toots_df = post_filter(toots_df, one_hour_ago)

for index, row in filtered_toots_df.iterrows():
if type(row['account']) == float: continue
for _, row in filtered_toots_df.iterrows():
if isinstance(row['account'], float): continue
slide_creator(row, "static/uploads/")

def remove_old_images():
Expand Down
6 changes: 3 additions & 3 deletions html/extensions/mastodon/post_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ def adjust_content(content: str):
content = content[:247] + "..."

content = emoji.emojize(content, language='alias')

content = content.encode('unicode-escape').decode('unicode-escape')
return content


def post_filter(toots_df, not_older_then):
def post_filter(toots_df, not_older_then):
# Filter toots that are not older than one hour
toots_df = toots_df[toots_df['created_at'] >= not_older_then]

Expand All @@ -39,7 +39,7 @@ def post_filter(toots_df, not_older_then):
if row['in_reply_to_id'] or row['in_reply_to_account_id']:
print("Removed toot because it's a reply")
toots_df.drop(index, inplace=True)

# Filter for polls
if row['poll']:
print("Removed toot because it contains a poll")
Expand Down
2 changes: 1 addition & 1 deletion html/extensions/mastodon/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def index():
user_name = session.get('user_name')
if not check_access(user_name, 9):
return error_page("You are not allowed to access this page")

tags = get_all_mastodon_tags()

return render_template('mastodon.html', tags=tags)
Expand Down
6 changes: 3 additions & 3 deletions html/extensions/mastodon/slide_creator.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import requests
import os

from io import BytesIO

import requests
from PIL import Image, ImageDraw, ImageFont

def split_string_into_chunks(text, chunk_size=35):
Expand Down Expand Up @@ -66,4 +66,4 @@ def slide_creator(toot, destination_path:str):
pp = fetch_and_resize_image(toot['account']['avatar'], (400,400))
image = place_pp(image, pp, (300, 300))

image.save(os.path.join(destination_path,f"mastodon_{toot['id']}.png"))
image.save(os.path.join(destination_path,f"mastodon_{toot['id']}.png"))
2 changes: 1 addition & 1 deletion services/runner/main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import argparse
import requests
import time

import requests
from bs4 import BeautifulSoup

from infobeamer import infobeamer_main
Expand Down

0 comments on commit ee97163

Please sign in to comment.