Skip to content

Menu

  • database acties
  • Maak blogpost met AI
  • raspiBlog code bibliotheek
  • Verzamelen data
  • welkom

Copyright 2024 - 2025 renegeilings.nl

database acties

Gedetailleerde Uitleg van de Database Acties in pgdbActions.py

Deze pagina biedt een gedetailleerde uitleg van alle databasefuncties in pgdbActions.py.

add_new_row(start_datetime, type)

Voegt een nieuwe rij toe aan de tabel rb_runs en retourneert de gegenereerde ID.

def add_new_row(start_datetime, type):
    cur.execute("INSERT INTO rb_runs (start_datetime, status, type) VALUES (%s, %s, %s) RETURNING id", (start_datetime, 'S', type))
    new_id = cur.fetchone()[0]
    conn.commit()
    return new_id

add_new_row_rb_runs(start_datetime, type, action)

Zelfde als add_new_row, maar voegt ook een actie toe.

def add_new_row_rb_runs(start_datetime, type, action):
    cur.execute("INSERT INTO rb_runs (start_datetime, status, type, action) VALUES (%s, %s, %s, %s) RETURNING id", (start_datetime, 'S', type, action))
    new_id = cur.fetchone()[0]
    conn.commit()
    return new_id

update_row_rb_runs(id, end_datetime, status, action, ai_provider)

Werkt een rij bij in de rb_runs tabel.

def update_row_rb_runs(id, end_datetime, status, action, ai_provider):
    cur.execute("UPDATE rb_runs SET end_datetime = %s, status = %s, action = %s, ai_provider = %s WHERE id = %s", (end_datetime, status, action, ai_provider, id))
    conn.commit()

insert_article(row)

Voegt een nieuw artikel toe aan de rb_articles tabel en retourneert de ID.

def insert_article(row):
    cur.execute("""
        INSERT INTO rb_articles (run_id, url, topic, summary, text, pub_date, title, supply_channel)
        VALUES (%s, %s, %s, %s, %s, %s, %s, %s) RETURNING id
    """, (row["run_id"], row["full_url"], row["topic"], row["summary"], row["text"], row["pub_date"], row["title"], row["supply_channel"]))
    row_id = cur.fetchone()[0]
    conn.commit()
    return row_id

url_exists(url)

Controleert of een artikel-URL al in de database bestaat.

def url_exists(url):
    cur.execute("SELECT 1 FROM rb_articles WHERE url = %s", (url,))
    return cur.fetchone() is not None

get_article_text_by_id(id)

Haalt de tekst van een artikel op basis van een ID.

def get_article_text_by_id(id):
    with connect(database=database, user=username, password=password, host=host, port=port) as conn:
        with conn.cursor(cursor_factory=RealDictCursor) as cursor:
            cursor.execute("SELECT text FROM rb_articles WHERE id = %s", (id,))
            return cursor.fetchall()

get_summaries_by_run_id(run_id)

Haalt samenvattingen op voor een bepaalde run.

def get_summaries_by_run_id(run_id):
    with connect(database=database, user=username, password=password, host=host, port=port) as conn:
        with conn.cursor(cursor_factory=RealDictCursor) as cursor:
            cursor.execute("""
                SELECT t.trend_text, a.summary 
                FROM rb_articles a
                JOIN rb_trends t ON t.id = a.run_id
                JOIN rb_runs r ON t.run_id = r.id
                WHERE a.summary IS NOT NULL
                  AND r.id = %s;
            """, (run_id,))
            return cursor.fetchall()

get_trending_articles(where_clause)

Haalt trending artikelen op gebaseerd op een opgegeven WHERE-clausule.

def get_trending_articles(where_clause):
    with connect(database=database, user=username, password=password, host=host, port=port) as conn:
        with conn.cursor(cursor_factory=RealDictCursor) as cursor:
            cursor.execute(f"SELECT trend_text, text FROM rb_v_trending_articles {where_clause}")
            return cursor.fetchall()

get_trending_summaries(where_clause)

Haalt trending samenvattingen op op basis van een opgegeven WHERE-clausule.

def get_trending_summaries(where_clause):
    with connect(database=database, user=username, password=password, host=host, port=port) as conn:
        with conn.cursor(cursor_factory=RealDictCursor) as cursor:
            cursor.execute(f"SELECT trend_text, summary FROM rb_v_trending_summaries {where_clause}")
            return cursor.fetchall()

Deze pagina bevat een gedetailleerde uitleg van alle databasefuncties in pgdbActions.py.

 

Welkom

  • welkom

Technische beschrijving

  • raspiBlog code bibliotheek
  • Verzamelen data
  • Maak blogpost met AI
  • database acties
juli 2025
M D W D V Z Z
 123456
78910111213
14151617181920
21222324252627
28293031  
« jun    

Copyright 2024 - 2025 renegeilings.nl