Skip to content
/ pymkm Public
forked from andli/pymkm

Python wrapper for the cardmarket.com API. Also contains a working app with price updating of your personal stock, csv import etc.

License

Notifications You must be signed in to change notification settings

holbech/pymkm

ย 
ย 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Python application codecov

See the Changelog for what's new. See the Trello board for ongoing work. Hop in on the Discord server if you want help or to discuss development.

ko-fi

๐Ÿ“™ PyMKM

NEW in 2.3.0: Custom price calculator modules.

Python wrapper for the cardmarket.com API (version 2.0, using OAuth1 and the "Dedicated app" option).

The included sample app can update your stock prices to trend, all rounded to nearest configurable value per rarity (default .25 โ‚ฌ). A confirmation step allows you to check the result before uploading the new prices.

The app can import a .csv list of cards to your stock. It can also be used to clear your entire stock. The app also keeps track of how many API requests your have left each day, and can do partial updates if you have more than 5000 articles to update.

NOTE: Use all functionality at your own risk, I take no responsibility for the resulting prices or wiped stock. See 'price calculation' below for more details.

Fetching Cardmarket account data...
Fetching account data took 0s
โ•ญโ”€โ”€โ”€ PyMKM 2.3.0 โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚ 1: Update stock prices (24 items)              โ”‚
โ”‚ 2: Update price for a product                  โ”‚
โ”‚ 3: Find deals from a user                      โ”‚
โ”‚ 4: Show top 10 expensive items in stock        โ”‚
โ”‚ 5: Wantslists cleanup suggestions              โ”‚
โ”‚ 6: Clear partial updates                       โ”‚
โ”‚ 7: Clear entire stock                          โ”‚
โ”‚ 8: Import stock from list.csv                  โ”‚
โ”‚ 9: Track price data to prices.csv              โ”‚
โ”‚ 0: Exit                                        โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ Testa Testerson (testerson123)                 โ”‚
โ”‚ API calls used today: 69/5000                  โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ
Action number: 1
100% (74 of 74) |#########################################| Elapsed Time: 0:00:21 Time:  0:00:21
Total stock value: 49.25
Note: 2 items filtered out because of sticky prices.

Best diffs:

  Count  Name             Foil    Playset      Old price    New price    Diff
-------  ---------------  ------  ---------  -----------  -----------  ------
      1  Manaweft Sliver                            1.25          1.5    0.25

Worst diffs:

  Count  Name                              Foil    Playset      Old price    New price    Diff
-------  --------------------------------  ------  ---------  -----------  -----------  ------
      1  Shield of the Oversoul                                      1            0.75   -0.25
      1  Battle Sliver                             โœ“                 1            0.75   -0.25
      2  Predatory Sliver                          โœ“                 2            1.75   -0.25
      1  Kalemne, Disciple of Iroas (V.1)                            0.75         0.5    -0.25
      1  Foreboding Ruins                                            1.5          1.25   -0.25

Total price difference: -1.25.
Do you want to update these prices? [y/N]:

๐Ÿ”จ How

  1. Install requirements using pip install -r requirements.txt
  2. Copy config_template.json to config.json and fill in your API keys.
  3. Run python pymkm.py.
  4. Profit.

๐Ÿ“ˆ Price calculation

The price data is supplied by the Cardmarket API.

NOTE: This is a rough algorithm, designed to be safe and not to sell aggressively.

  1. Filter out English, not altered, not signed, minimum Good condition.
  2. Set price to lowest + (median - lowest / 4), rounded to closest rouding limit.
  3. Undercut price in seller's own country by the rounding limit if not contradicting 2)
  4. Never go below the rounding limit for foils

Base prices (โ‚ฌ) and discounts for lower grading (decimal %) can be set in config.json.

You can also create your own custom price calculation algorithm by using the config value custom_price_calculator (see details below).

๐Ÿ”“ Locking prices

Should you want to avoid updating certain articles in your stock, set the starting character of the comment for that article to ! (possible to change which character in config.json).

Price checking wantslist to .csv

This function selects a wantslist and dumps price data for all products in that list to a .csv file.

NOTE: This does not work for metaproducts, only for products.

CLI

Some functions have command line support, see python pymkm.py --help for more info.

Example 1

python pymkm.py --update_stock --partial 500 --cache True

This updates the stock, 500 articles each time, using the local cache of the stock if available.

Example 2

python pymkm.py --price_check_wantslist fancycards --cache True

This dumps price data for all the cards in the wantslist "fancycards" to a .csv file, using the local cache of the wantslists if available.

โš™๏ธ Config parameters

custom_price_calculator

This can be used to load in a custom price calculation module. Here is an example config value for addressing your custom class:

"custom_price_calculator": "custom.calculators.DiscountForGoblinsCalculator",

Use the supplied example class to get started. Look at DefaultPriceCalculator in pymkm_calculators if you want to study the default algorithm.

price_limit_by_rarity

Set a lower price limit (and also rounding target) for different rarities. Example: "mythic": "1.0" would set the lowest price Mythic rarity cards to โ‚ฌ1, and would set prices to round to nearest โ‚ฌ1.

discount_by_condition

Set a decimal multiplier on each card condition level. Example: "PL": "0.5" would set the price for Played cards to 50% off the trend price.

search_filters

Variable Value
language Specify a language to find deals from a specific user.
isAltered Determines if the card is altered.
isSigned Determines if the card is signed.
minCondition Determines the minimal condition of a card. (see below for additional information)
userType Only articles from sellers with the specified user type are returned. (private, commercial, powerseller)
idLanguage Only articles that match the given language are returned. (see below for additional information)

minCondition

Abbreviation Condition
MT Mint
NM Near Mint (default value when not specified)
EX Excellent
GD Good
LP Light-played
PL Played
PO Poor

idLanguage

ID Language
1 English
2 French
3 German
4 Spanish
5 Italian
6 Simplified Chinese
7 Japanese
8 Portuguese
9 Russian
10 Korean
11 Traditional Chinese

sticky_price_char

The character in the card comment used to disable price updates for specific cards. Default !.

partial_update_filename

The name of the file storing partial updates. Default partial_stock_update.txt.

local_cache_filename

The name of the database file storing cached data. Default local_pymkm_data.db.

csv_import_filename

The name of the file which CSV importing is done from. Default list.csv.

csv_import_condition

The default condition for all CSV imports. Default NM.

show_num_best_worst_items

How many best and worst items to show after a price update. Default 20.

show_top_x_expensive_items

How many items to show in the Top X expensive function. Default 20.

log_level

Log level for the application and API. Default WARNING.

stock_settings

Variable Value
idGame Specifies the Game the stock file is for. (1=Mtg, 3=YGO, 6=PKM)
isSealed Specifies if sealed product should be returned. (true, false)
idLanguage Specifies the Language of the Local Name column. (default is 1 for English)

๐Ÿ“„ CSV importing

If you scan cards using an app like Delver Lens or the TCG Player app, this feature can help you do bulk import of that list.

Drop your list of cards into a file called list.csv in the root directory (there is an example file included in this repo). The file has to follow this format (including the header row):

Card,Set Name,Quantity,Foil,Language
Dragon Breath,Scourge,1,Foil,French

Remove all quotation marks and extra commas in card names.

Any cards that fail to import are written to a new .csv file called failed_imports.csv.

๐Ÿ“Š Competition view

This feature allows you to get a better view of how you should price individual cards depending on your local market and also the whole market:

Action number: 3
Note: does not support playsets, booster displays etc (yet).
Search product name:
temple gar
Foil? [y/N]:

Found product: Temple Garden
----------------------------------------------------------------------
Local competition:

Username     Country    Condition      Count    Price
-----------  ---------  -----------  -------  -------
Karand       SE         NM                 1        6
-> testuser  SE         NM                 1       13
----------------------------------------------------------------------
Total average price: 9.5, Total median price: 9.5, Total # of articles: 2

----------------------------------------------------------------------
Top 20 cheapest:

Username         Country    Condition      Count    Price
---------------  ---------  -----------  -------  -------
syresatve        GR         NM                 1     4.9
Tromeck          ES         NM                 1     4.99
    <cut out rows to save vertical space in README.md>
peiraikos        GR         NM                 1     5.95
finespoo         FI         NM                 2     5.98
----------------------------------------------------------------------
Total average price: 9.82, Total median price: 7.79, Total # of articles: 320

About

Python wrapper for the cardmarket.com API. Also contains a working app with price updating of your personal stock, csv import etc.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 100.0%