implemented most of the pixiv scraper
This commit is contained in:
@ -9,6 +9,8 @@ from api.models import Account
|
||||
|
||||
def create_account(
|
||||
conn: connection,
|
||||
groupname: str,
|
||||
author: str,
|
||||
platform: str,
|
||||
login: str,
|
||||
password: str,
|
||||
@ -18,14 +20,18 @@ def create_account(
|
||||
cur.execute(
|
||||
"""
|
||||
insert into picrinth.accounts
|
||||
(platform, login, password,
|
||||
metadata, created_at)
|
||||
(groupname, author, platform, login,
|
||||
password, metadata, created_at)
|
||||
values (%s, %s, %s, %s, now())
|
||||
returning id
|
||||
""",
|
||||
(platform, login, password, json.dumps(metadata)),
|
||||
(groupname, author, platform, login, password, json.dumps(metadata)),
|
||||
)
|
||||
return conn.commit()
|
||||
result = cur.fetchone()
|
||||
conn.commit()
|
||||
if result is None:
|
||||
return None
|
||||
return result[0]
|
||||
|
||||
|
||||
def delete_account(
|
||||
@ -80,14 +86,32 @@ def update_account(
|
||||
cur.execute(
|
||||
"""
|
||||
update picrinth.accounts
|
||||
SET platform = %s,
|
||||
author = %s,
|
||||
SET author = %s,
|
||||
login = %s,
|
||||
password = %s,
|
||||
metadata = %s
|
||||
where groupname = %s
|
||||
where groupname = %s and platform = %s
|
||||
""",
|
||||
(platform, author, login, password, json.dumps(metadata), groupname),
|
||||
(author, login, password, json.dumps(metadata), groupname, platform),
|
||||
)
|
||||
conn.commit()
|
||||
return cur.rowcount > 0
|
||||
|
||||
|
||||
def update_account_metadata(
|
||||
conn: connection,
|
||||
groupname: str,
|
||||
platform: str,
|
||||
metadata: dict
|
||||
):
|
||||
with conn.cursor() as cur:
|
||||
cur.execute(
|
||||
"""
|
||||
update picrinth.accounts
|
||||
SET metadata = %s
|
||||
where groupname = %s and platform = %s
|
||||
""",
|
||||
(json.dumps(metadata), groupname, platform),
|
||||
)
|
||||
conn.commit()
|
||||
return cur.rowcount > 0
|
||||
@ -95,7 +119,6 @@ def update_account(
|
||||
|
||||
# account receiving
|
||||
|
||||
# TODO: fix list comprehension
|
||||
def get_accounts_by_group(
|
||||
conn: connection,
|
||||
groupname: str
|
||||
|
||||
Reference in New Issue
Block a user