slack status without the slack status.zzstoatzz.io
hatk statusphere
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

at 88d7660ccf4a6e6828b3c7e6615972d6a1dc3695 90 lines 2.4 kB view raw
1#!/usr/bin/env python3 2# /// script 3# requires-python = ">=3.11" 4# dependencies = [] 5# /// 6""" 7Register all downloaded emoji images in the database 8""" 9 10import sqlite3 11import time 12from pathlib import Path 13 14 15def main(): 16 # Setup paths 17 script_dir = Path(__file__).parent 18 project_root = script_dir.parent 19 emojis_dir = project_root / "static" / "emojis" 20 db_path = project_root / "statusphere.sqlite3" 21 22 if not db_path.exists(): 23 print(f"Error: Database not found at {db_path}") 24 return 25 26 # Get all image files 27 image_files = [] 28 for ext in ['*.png', '*.gif', '*.jpg', '*.jpeg', '*.webp']: 29 image_files.extend(emojis_dir.glob(ext)) 30 31 print(f"Found {len(image_files)} image files") 32 33 # Connect to database 34 conn = sqlite3.connect(db_path) 35 cursor = conn.cursor() 36 37 # Check what already exists 38 cursor.execute("SELECT name FROM custom_emojis") 39 existing = {row[0] for row in cursor.fetchall()} 40 print(f"Already registered: {len(existing)} emojis") 41 42 # Register new emojis 43 added = 0 44 skipped = 0 45 timestamp = int(time.time()) 46 47 for image_path in image_files: 48 filename = image_path.name 49 # Create a short name from filename 50 name = filename.rsplit('.', 1)[0] 51 # Truncate super long names 52 if len(name) > 50: 53 name = name[:47] + "..." 54 55 if name in existing: 56 skipped += 1 57 continue 58 59 # Determine mime type 60 ext = filename.rsplit('.', 1)[-1].lower() 61 mime_map = { 62 'png': 'image/png', 63 'gif': 'image/gif', 64 'jpg': 'image/jpeg', 65 'jpeg': 'image/jpeg', 66 'webp': 'image/webp' 67 } 68 mime_type = mime_map.get(ext, 'image/png') 69 70 # Create alt text from name 71 alt_text = name.replace('-', ' ').replace('_', ' ') 72 73 cursor.execute( 74 "INSERT INTO custom_emojis (name, filename, alt_text, category, addedAt) VALUES (?, ?, ?, ?, ?)", 75 (name, filename, alt_text, 'bufo', timestamp) 76 ) 77 added += 1 78 79 conn.commit() 80 conn.close() 81 82 print(f"✓ Added {added} new emojis") 83 if skipped: 84 print(f" Skipped {skipped} existing emojis") 85 86 print(f"\nTotal emojis in database now: {len(existing) + added}") 87 88 89if __name__ == "__main__": 90 main()