api.services.auctions_sync ========================== .. py:module:: api.services.auctions_sync .. autoapi-nested-parse:: Copies the auction price tracker's followed lots into the auctions Airtable base, every minute. The tracker's GET /export gives the lots ever followed that changed since the last run (all of them on the first run), their price history and their auctions. Each table is upserted by its tracker id ("ID enchère", "ID modèle", "ID lot", "ID"), so a repeated or interrupted run creates no duplicate; Redis remembers what was last sent per row (only changed rows are written), the Airtable record ids (for the links) and the photos already copied. Photos are downloaded here and uploaded as files: the base keeps its own copies, even after the auction site removes them. Nothing is ever deleted from the base. Attributes ---------- .. autoapisummary:: api.services.auctions_sync.logger api.services.auctions_sync.PROVIDERS api.services.auctions_sync.PHOTO_BUDGET api.services.auctions_sync.MAX_PHOTO_BYTES api.services.auctions_sync.PHOTO_RETRY_FIRST api.services.auctions_sync.PHOTO_RETRY_MAX api.services.auctions_sync.OVERLAP api.services.auctions_sync.KEY api.services.auctions_sync.USER_AGENT Classes ------- .. autoapisummary:: api.services.auctions_sync.Sync Functions --------- .. autoapisummary:: api.services.auctions_sync.auction_fields api.services.auctions_sync.lot_fields api.services.auctions_sync.history_fields Module Contents --------------- .. py:data:: logger .. py:data:: PROVIDERS .. py:data:: PHOTO_BUDGET :value: 150 .. py:data:: MAX_PHOTO_BYTES :value: 5242880 .. py:data:: PHOTO_RETRY_FIRST :value: 600 .. py:data:: PHOTO_RETRY_MAX :value: 21600 .. py:data:: OVERLAP .. py:data:: KEY :value: 'auctions:airtable' .. py:data:: USER_AGENT :value: 'Mozilla/5.0 (X11; Linux x86_64) RewakeAPI auctions sync' .. py:class:: Sync(base: pyairtable.Base, tracker_url: str, tracker_token: str, redis: redis.Redis) .. py:attribute:: base .. py:attribute:: tracker_url .. py:attribute:: tracker_headers .. py:attribute:: redis .. py:method:: upsert_changed(table: str, rows: dict[str, dict[str, Any]], merge_on: str) -> dict[str, str] Writes the rows (tracker id -> fields) that changed since they were last sent; returns every row's Airtable record id. .. py:method:: copy_photos(lots: list[dict[str, Any]], lot_ids: dict[str, str]) -> tuple[int, int] Uploads the photos not copied yet, PHOTO_BUDGET at most; returns (copied, still to copy). .. py:method:: run() -> dict[str, Any] .. py:method:: retry_photos() -> int Queues again the photos of every lot whose Airtable record has none (e.g. refused by the site before refusals were retried); the next runs copy them. Returns the lots queued. .. py:method:: resend() -> None The next run reads every followed lot again and writes those whose fields differ (e.g. after a new field), keeping the photos already copied, unlike reset(). .. py:method:: reset() -> None Forgets what was sent: the next run sends everything again (upserts, so no duplicate). .. py:function:: auction_fields(a: dict[str, Any]) -> dict[str, Any] .. py:function:: lot_fields(lot: dict[str, Any], auctions: dict[str, str], models: dict[str, str]) -> dict[str, Any] .. py:function:: history_fields(h: dict[str, Any], lots: dict[str, str]) -> dict[str, Any]