зеркало из
https://github.com/viginum-datalab/twscrape.git
synced 2025-10-30 05:26:20 +02:00
fix sqlite 3.34
Этот коммит содержится в:
родитель
2265a92f0d
Коммит
99695dc24d
26
Dockerfile-test
Обычный файл
26
Dockerfile-test
Обычный файл
@ -0,0 +1,26 @@
|
|||||||
|
FROM python:3.10-alpine
|
||||||
|
ARG SQLITE_Y=2021
|
||||||
|
ARG SQLITE_V=3340100
|
||||||
|
|
||||||
|
RUN pip install --upgrade pip
|
||||||
|
RUN python -c "import sqlite3;print(sqlite3.sqlite_version)"
|
||||||
|
|
||||||
|
# https://www.sqlite.org/chronology.html
|
||||||
|
RUN apk add build-base
|
||||||
|
RUN wget https://sqlite.org/${SQLITE_Y}/sqlite-autoconf-${SQLITE_V}.tar.gz -O sqlite.tar.gz \
|
||||||
|
&& tar xvfz sqlite.tar.gz \
|
||||||
|
&& cd sqlite-autoconf-${SQLITE_V} \
|
||||||
|
&& ./configure --prefix=/usr/local --build=aarch64-unknown-linux-gnu \
|
||||||
|
&& make \
|
||||||
|
&& make install \
|
||||||
|
&& cd .. \
|
||||||
|
&& rm -rf sqlite*
|
||||||
|
|
||||||
|
RUN sqlite3 --version
|
||||||
|
RUN python -c "import sqlite3;print(sqlite3.sqlite_version)"
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
COPY pyproject.toml readme.md /app/
|
||||||
|
RUN pip install -e .[dev]
|
||||||
|
COPY . /app
|
||||||
|
RUN pytest tests/
|
||||||
5
Makefile
5
Makefile
@ -37,4 +37,7 @@ act:
|
|||||||
|
|
||||||
changelog:
|
changelog:
|
||||||
@git pull origin --tags > /dev/null
|
@git pull origin --tags > /dev/null
|
||||||
@git log $(shell git describe --tags --abbrev=0 HEAD)^..HEAD --pretty=format:'- %s'
|
@git log $(shell git describe --tags --abbrev=0 HEAD)^..HEAD --pretty=format:'- %s'
|
||||||
|
|
||||||
|
test34:
|
||||||
|
docker build -f Dockerfile-test .
|
||||||
|
|||||||
@ -25,6 +25,7 @@ class Account(JSONTrait):
|
|||||||
proxy: str | None = None
|
proxy: str | None = None
|
||||||
error_msg: str | None = None
|
error_msg: str | None = None
|
||||||
last_used: datetime | None = None
|
last_used: datetime | None = None
|
||||||
|
_tx: str | None = None
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def from_rs(rs: sqlite3.Row):
|
def from_rs(rs: sqlite3.Row):
|
||||||
|
|||||||
@ -1,5 +1,7 @@
|
|||||||
# ruff: noqa: E501
|
# ruff: noqa: E501
|
||||||
import asyncio
|
import asyncio
|
||||||
|
import sqlite3
|
||||||
|
import uuid
|
||||||
from datetime import datetime, timezone
|
from datetime import datetime, timezone
|
||||||
|
|
||||||
from fake_useragent import UserAgent
|
from fake_useragent import UserAgent
|
||||||
@ -148,13 +150,25 @@ class AccountsPool:
|
|||||||
LIMIT 1
|
LIMIT 1
|
||||||
"""
|
"""
|
||||||
|
|
||||||
q2 = f"""
|
if int(sqlite3.sqlite_version_info[1]) >= 35:
|
||||||
UPDATE accounts SET locks = json_set(locks, '$.{queue}', datetime('now', '+15 minutes'))
|
qs = f"""
|
||||||
WHERE username = ({q1})
|
UPDATE accounts SET locks = json_set(locks, '$.{queue}', datetime('now', '+15 minutes'))
|
||||||
RETURNING *
|
WHERE username = ({q1})
|
||||||
"""
|
RETURNING *
|
||||||
|
"""
|
||||||
|
rs = await fetchone(self._db_file, qs)
|
||||||
|
else:
|
||||||
|
tx = uuid.uuid4().hex
|
||||||
|
qs = f"""
|
||||||
|
UPDATE accounts
|
||||||
|
SET locks = json_set(locks, '$.{queue}', datetime('now', '+15 minutes')), _tx = '{tx}'
|
||||||
|
WHERE username = ({q1})
|
||||||
|
"""
|
||||||
|
await execute(self._db_file, qs)
|
||||||
|
|
||||||
|
qs = f"SELECT * FROM accounts WHERE _tx = '{tx}'"
|
||||||
|
rs = await fetchone(self._db_file, qs)
|
||||||
|
|
||||||
rs = await fetchone(self._db_file, q2)
|
|
||||||
return Account.from_rs(rs) if rs else None
|
return Account.from_rs(rs) if rs else None
|
||||||
|
|
||||||
async def get_for_queue_or_wait(self, queue: str) -> Account:
|
async def get_for_queue_or_wait(self, queue: str) -> Account:
|
||||||
|
|||||||
@ -33,8 +33,8 @@ async def main(args):
|
|||||||
|
|
||||||
if args.command == "version":
|
if args.command == "version":
|
||||||
print(f"twscrape: {version('twscrape')}")
|
print(f"twscrape: {version('twscrape')}")
|
||||||
print(f"SQlite client: {sqlite3.version}")
|
print(f"SQLite client: {sqlite3.version}")
|
||||||
print(f"SQlite runtime: {sqlite3.sqlite_version} ({await get_sqlite_version()})")
|
print(f"SQLite runtime: {sqlite3.sqlite_version} ({await get_sqlite_version()})")
|
||||||
return
|
return
|
||||||
|
|
||||||
logger.debug(f"Using database: {args.db}")
|
logger.debug(f"Using database: {args.db}")
|
||||||
|
|||||||
@ -69,9 +69,13 @@ async def migrate(db: aiosqlite.Connection):
|
|||||||
await db.execute("ALTER TABLE accounts ADD COLUMN stats TEXT DEFAULT '{}' NOT NULL")
|
await db.execute("ALTER TABLE accounts ADD COLUMN stats TEXT DEFAULT '{}' NOT NULL")
|
||||||
await db.execute("ALTER TABLE accounts ADD COLUMN last_used TEXT DEFAULT NULL")
|
await db.execute("ALTER TABLE accounts ADD COLUMN last_used TEXT DEFAULT NULL")
|
||||||
|
|
||||||
|
async def v3():
|
||||||
|
await db.execute("ALTER TABLE accounts ADD COLUMN _tx TEXT DEFAULT NULL")
|
||||||
|
|
||||||
migrations = {
|
migrations = {
|
||||||
1: v1,
|
1: v1,
|
||||||
2: v2,
|
2: v2,
|
||||||
|
3: v3,
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.debug(f"Current migration v{uv} (latest v{len(migrations)})")
|
logger.debug(f"Current migration v{uv} (latest v{len(migrations)})")
|
||||||
|
|||||||
Загрузка…
x
Ссылка в новой задаче
Block a user