8000 GitHub - cusco/cardmarket_prices: Fetch catalog prices cartmarket.com periodically, keeping historical data
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

cusco/cardmarket_prices

Repository files navigation

Cardmarket Prices

A Django project to fetch, store, and analyze Magic: The Gathering card data from Cardmarket. Can be expanded to other Cardmarket products.

Cardmarket publishes its "Product Catalogue" and "Price Guide" daily: Cardmarket News.

Features

  • Fetches card sets, cards, and prices from Cardmarket.
  • Stores historical data in a local database.
  • Analyzes historical price changes.

Setup

This project uses Django with Celery for task scheduling. You will need Python 3.10 or greater.

Local Setup

Follow these steps to set up the project locally:

# Clone the repository and install dependencies
git clone git@github.com:cusco/cardmarket_prices.git
cd cardmarket_prices
pip install -r requirements.txt

# Apply migrations and load initial data
cd src
./manage.py migrate
./manage.py loaddata fixture_01_mtgset.json.gz
./manage.py loaddata fixture_02_mtgcard.json.gz
./manage.py loaddata fixture_03_mtgcardpriceslope.json.gz

Load Historical Data

Some data has been added to the local/catalogs directory. To load this data into the database:

  1. Open the Django Python shell:

    ./manage.py shell_plus
  2. Run the following command:

    from prices.services import update_mtg, update_from_local_files
    update_from_local_files()
    update_mtg()

You may also download some extra data made available on https://ovh.tretas.eu/~cusco/catalogs/ Place it in local/catalogs before running update_from_local_files()

cd local/catalogs
wget -4 -r -A "*.gz" -nd -l 1 https://ovh.tretas.eu/~cusco/catalogs/

Celery Automation

To automate data fetching, you can set up Celery with the following commands or as systemd services:

# Start the Celery worker
celery -A cm_prices worker -l info

# Start the Celery scheduler
celery -A cm_prices beat -l info

Usage

Ensure the database contains historical data. Use update_mtg() to fetch the latest data daily or rely on Celery automation.

Main Functions

  1. show_changes(card_qs=None, days=7, min_price=3)
    Displays price changes over the specified days for a card queryset.

  2. show_stats(days=7, card_qs=None)
    Provides statistical insights for a specified period.

Both functions are in src/lib/utils.py. By default, card_qs filters cards from Pioneer-legal sets, and days specifies the time period for analysis.

Example Usage

qs = MTGCard.objects.filter(expansion_id__in=LEGAL_STANDARD_SETS)
settings.PRICE_FIELD = 'trend'
show_changes(card_qs=qs, days=2)

Sample output:

Name                       | Expansion Code | % Change | Slope  | Price Change
----------------------------------------------------------------------------
Kiora, the Rising Tide     | FDN            |   +5.3%  |  +0.15 | 5.65 -> 5.95 (+0.30€)
Glissa Sunslayer           | ONE            |   +3.3%  |  +0.09 | 5.74 -> 5.93 (+0.19€)
...

Set settings.PRICE_FIELD to adjust the price metric (trend, low, etc.).


Contributing

Pull requests are welcome, but they must pass validation. Run the following script to ensure compliance before submitting:

./scripts/static_validate_backend.sh

About

Fetch catalog prices cartmarket.com periodically, keeping historical data

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published
0