Exemplo n.º 1
0
def insert_new_categories(categories):
    cats = [(cat, ) for cat in categories]
    db = PostgresConn()
    db.insert_multiple(fields=["categoria"],
                       values=cats,
                       schema="noticias",
                       table="categorias")
    db.close()
Exemplo n.º 2
0
def map_subs_ids(subs_names, subs_titles):
    db = PostgresConn()
    subs_ids = {
        name: db.get_id_or_create("nome", [name], ["id"], "reddit", "subreddits", ["nome", "titulo"], [name, title])
        for name, title in zip(subs_names, subs_titles)
    }
    db.close()
    return subs_ids
Exemplo n.º 3
0
def query_categories_ids(categories):
    db = PostgresConn()
    res = db.filter(filter_field="categoria",
                    filter_values=categories,
                    fields=["id", "categoria"],
                    schema="noticias",
                    table="categorias")
    db.close()
    return res
Exemplo n.º 4
0
def query_page_id(page):
    db = PostgresConn()
    res = db.filter(filter_field="nome",
                    filter_values=[page],
                    fields=["id", "nome"],
                    schema="noticias",
                    table="paginas")
    db.close()
    return res[0][0]
Exemplo n.º 5
0
def select_all_urls():
    db = PostgresConn()
    res = db.select(["url"], "noticias", "noticias")
    db.close()
    return set(url[0] for url in res)
Exemplo n.º 6
0
def map_users_ids(users):
    db = PostgresConn()
    users_ids = db.filter("name", users, ["id", "name"], "reddit", "users")
    db.close()
    return {name: _id for _id, name in users_ids}
Exemplo n.º 7
0
def query_all_users(users):
    db = PostgresConn()
    _ids = db.filter("reddit_id", users, ["id", "reddit_id"], "reddit",
                     "users")
    db.close()
    return _ids