starting scraper development
This commit is contained in:
@ -3,13 +3,15 @@ import json
|
||||
import psycopg2.extras
|
||||
from psycopg2._psycopg import connection
|
||||
|
||||
from api.models import Account
|
||||
|
||||
# account create and delete
|
||||
|
||||
def create_account(
|
||||
conn: connection,
|
||||
platform: str,
|
||||
login: str,
|
||||
password: int,
|
||||
password: str,
|
||||
metadata: dict
|
||||
):
|
||||
with conn.cursor() as cur:
|
||||
@ -44,28 +46,10 @@ def delete_account(
|
||||
|
||||
# account checks
|
||||
|
||||
def check_account_existence_by_id(
|
||||
conn: connection,
|
||||
account_id: str
|
||||
):
|
||||
with conn.cursor() as cur:
|
||||
cur.execute(
|
||||
"""
|
||||
select exists(
|
||||
select 1
|
||||
from picrinth.accounts
|
||||
where account_id = %s
|
||||
);
|
||||
""",
|
||||
(account_id),
|
||||
)
|
||||
return cur.fetchone()[0] # type: ignore
|
||||
|
||||
def check_account_existence(
|
||||
conn: connection,
|
||||
platform: str,
|
||||
login: str,
|
||||
password: str
|
||||
groupname: str,
|
||||
platform: str
|
||||
):
|
||||
with conn.cursor() as cur:
|
||||
cur.execute(
|
||||
@ -73,10 +57,10 @@ def check_account_existence(
|
||||
select exists(
|
||||
select 1
|
||||
from picrinth.accounts
|
||||
where platform = %s, login = %s, password = %s
|
||||
where groupname = %s and platform = %s
|
||||
);
|
||||
""",
|
||||
(platform, login, password),
|
||||
(groupname, platform),
|
||||
)
|
||||
return cur.fetchone()[0] # type: ignore
|
||||
|
||||
@ -85,10 +69,11 @@ def check_account_existence(
|
||||
|
||||
def update_account(
|
||||
conn: connection,
|
||||
account_id: str,
|
||||
groupname: str,
|
||||
author: str,
|
||||
platform: str,
|
||||
login: str,
|
||||
password: int,
|
||||
password: str,
|
||||
metadata: dict
|
||||
):
|
||||
with conn.cursor() as cur:
|
||||
@ -96,12 +81,13 @@ def update_account(
|
||||
"""
|
||||
update picrinth.accounts
|
||||
SET platform = %s,
|
||||
author = %s,
|
||||
login = %s,
|
||||
password = %s,
|
||||
metadata = %s
|
||||
where account_id = %s
|
||||
where groupname = %s
|
||||
""",
|
||||
(platform, login, password, json.dumps(metadata), account_id),
|
||||
(platform, author, login, password, json.dumps(metadata), groupname),
|
||||
)
|
||||
conn.commit()
|
||||
return cur.rowcount > 0
|
||||
@ -109,19 +95,37 @@ def update_account(
|
||||
|
||||
# account receiving
|
||||
|
||||
def get_account(
|
||||
# TODO: fix list comprehension
|
||||
def get_accounts_by_group(
|
||||
conn: connection,
|
||||
account_id: str
|
||||
groupname: str
|
||||
) -> list[Account]:
|
||||
with conn.cursor() as cur:
|
||||
cur.execute(
|
||||
"""
|
||||
select *
|
||||
from picrinth.accounts
|
||||
where groupname = %s
|
||||
""",
|
||||
(groupname,),
|
||||
)
|
||||
return [Account().fill(account_data) for (account_data,) in cur.fetchall()]
|
||||
|
||||
|
||||
def get_accounts_by_group_platform(
|
||||
conn: connection,
|
||||
groupname: str,
|
||||
platform: str
|
||||
):
|
||||
with conn.cursor(cursor_factory=psycopg2.extras.DictCursor) as cur:
|
||||
cur.execute(
|
||||
"""
|
||||
select username,
|
||||
account_id, platform, login,
|
||||
password, metadata, created_at
|
||||
select groupname, author,
|
||||
platform, login, password,
|
||||
metadata, created_at
|
||||
from picrinth.accounts
|
||||
where account_id = %s
|
||||
where groupname = %s and platform = %s
|
||||
""",
|
||||
(account_id),
|
||||
(groupname, platform),
|
||||
)
|
||||
return cur.fetchone()
|
||||
|
||||
Reference in New Issue
Block a user