CoderSupreme
CoderSupreme@programming.dev
Joined
9 posts • 13 comments
def get_admin_ids(domain: str) -> List[str]:
url = f"https://{domain}/api/v3/site"
response = requests.get(url)
try:
data = response.json()
except json.JSONDecodeError:
print(f"Error: Invalid or empty JSON response for domain {domain}")
return []
admin_ids = [
item["person"]["id"] for item in data["admins"] if item["person"].get("admin")
]
return admin_ids
I use Perplexity.ai, it uses ChatGPT + search and improves accuracy a lot. It only has 5 free uses of GPT-4 every 4 hours, but the normal ChatGPT + search is still better than any of the other LLMs I’ve tried.
@AutoTLDR
Deleted by creator
Couldn’t this be made private too? That way there wouldn’t be so much bot spam. Also I would like to be able to upvote a public remindme comment to be reminded too in private.
import json
import sqlite3
from config import *
from pythorhead import Lemmy
# Connect to the database
conn = sqlite3.connect('lemmy_github.db')
cursor = conn.cursor()
def import_missing_posts(posts_list):
for post in posts_list:
post = post['post']
try:
cursor.execute('SELECT * FROM posts WHERE issue_number = ?', (issue_number(post['url']),))
result = cursor.fetchone()
if result is None:
cursor.execute('INSERT INTO posts (issue_number, lemmy_post_id, issue_title, issue_body) VALUES (?, ?, ?, ?)',
(issue_number(post['url']), post['id'], post['name'], post['body']))
conn.commit()
except sqlite3.Error as e:
print(f"SQLite error occurred: {e}")
except KeyError as e:
print(f"KeyError occurred: {e}. Check if the input dictionary has all the required keys.")
except Exception as e:
print(f"An error occurred: {e}")
def issue_number(url) -> int:
return int(url.split("/")[-1])
def load_json(filename):
with open(filename) as f:
return json.load(f)
def process_posts(lemmy, username):
page = 1
while True:
posts = lemmy.user.get(username=username, page=page)['posts']
if not posts:
break
import_missing_posts(posts)
page += 1
lemmy = Lemmy(LEMMY_INSTANCE_URL)
lemmy.log_in(LEMMY_USERNAME, LEMMY_PASSWORD)
process_posts(lemmy, LEMMY_USERNAME)
# Close the connection
conn.close()