## Code ``` import enum import requests import pandas as pd CP_MAP = { "regular": { "alpha": {"legendary": 3000, "epic": 600, "rare": 120, "common": 30}, "beta": {"legendary": 1500, "epic": 300, "rare": 60, "common": 15}, "dice": {"legendary": 1000, "epic": 200, "rare": 40, "common": 10}, "promo": {"legendary": 3000, "epic": 600, "rare": 120, "common": 30}, "untamed": {"legendary": 1000, "epic": 200, "rare": 40, "common": 10}, "chaos": {"legendary": 500, "epic": 100, "rare": 20, "common": 5} }, "gold": { "alpha": {"legendary": 150000, "epic": 30000, "rare": 6000, "common": 1500}, "beta": {"legendary": 75000, "epic": 15000, "rare": 3000, "common": 750}, "dice": {"legendary": 50000, "epic": 10000, "rare": 2000, "common": 500}, "promo": {"legendary": 150000, "epic": 30000, "rare": 6000, "common": 1500}, "untamed": {"legendary": 50000, "epic": 10000, "rare": 2000, "common": 500}, "chaos": {"legendary": 12500, "epic": 2500, "rare": 500, "common": 125} } } class Rarity(enum.IntEnum): Common = 1 Rare = 2 Epic = 3 Legendary = 4 class Edition(enum.IntEnum): Alpha = 0 Beta = 1 Promo = 2 Reward = 3 Untamed = 4 Dice = 5 def to_slug(self, card_id): slug = self.name.lower() if slug == "reward": if card_id <= 223: return "beta" elif 224 <= card_id and card_id <= 298: return "dice" elif 299 <= card_id and card_id <= 330: return "gradius" elif 331 <= card_id and card_id <= 351: return "chaos" else: return slug def get_data(): market = requests.get(f"https://api2.splinterlands.com/market/for_rent_grouped").json() card_details = requests.get("https://api.splinterlands.io/cards/get_details").json() result = {} for card in market: gold_slug = "gold" if card["gold"] else "regular" edition_slug = Edition(card["edition"]).to_slug(card["card_detail_id"]) rarity_id = [card_detail["rarity"] for card_detail in card_details if card_detail["id"] == card["card_detail_id"]][0] rarity_slug = Rarity(rarity_id).name.lower() card["cp"] = CP_MAP[gold_slug][edition_slug][rarity_slug] card["cp_per_dec"] = round(float(card["cp"]) / float(card["low_price"]), 3) if card["cp"] in result and float(card["low_price"]) < float(result[card["cp"]]["low_price"]): result[card["cp"]] = card else: result[card["cp"]] = card return result data = get_data() df = pd.DataFrame(data.values()) df = df.set_index("cp") df = df.sort_index() df[15:][["card_detail_id", "gold", "edition", "low_price", "cp_per_dec"]] ``` ## Result  You can run the code in Google Colab. https://colab.research.google.com/drive/16tsx765O_Zl9txHNlA8Qe1bY5QMnUIzg?usp=sharing
author | cs50x |
---|---|
permlink | python-list-the-lowest-rental-prices-for-each-cp |
category | hive-13323 |
json_metadata | {"tags":["hive-13323","splintertalk","splinterlands","python"],"image":["https://i.gyazo.com/7c0a8366fdc3c3c71aef3ed8b34aff84.png"],"links":["https://colab.research.google.com/drive/16tsx765O_Zl9txHNlA8Qe1bY5QMnUIzg?usp=sharing"],"format":"markdown","canonical_url":"https://www.splintertalk.io/@cs50x/python-list-the-lowest-rental-prices-for-each-cp","app":"splintertalk/1.0.0"} |
created | 2021-11-13 16:23:15 |
last_update | 2021-11-13 16:23:15 |
depth | 0 |
children | 1 |
last_payout | 2021-11-20 16:23:15 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.013 HBD |
curator_payout_value | 0.012 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 3,027 |
author_reputation | 71,740,087,953 |
root_title | "[Python] List the lowest rental prices for each CP" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 107,717,788 |
net_rshares | 18,774,801,836 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
holoz0r | 0 | 18,425,553,389 | 100% | ||
limka | 0 | 127,239,458 | 100% | ||
adulruna | 0 | 222,008,989 | 10% | ||
dripdripp | 0 | 0 | 100% |
Congratulations @cs50x! You have completed the following achievement on the Hive blockchain and have been rewarded with new badge(s): <table><tr><td><img src="https://images.hive.blog/60x70/http://hivebuzz.me/@cs50x/upvoted.png?202111131729"></td><td>You received more than 10 upvotes.<br>Your next target is to reach 50 upvotes.</td></tr> </table> <sub>_You can view your badges on [your board](https://hivebuzz.me/@cs50x) and compare yourself to others in the [Ranking](https://hivebuzz.me/ranking)_</sub> <sub>_If you no longer want to receive notifications, reply to this comment with the word_ `STOP`</sub> **Check out the last post from @hivebuzz:** <table><tr><td><a href="/hive-106258/@hivebuzz/hivefest6-contest"><img src="https://images.hive.blog/64x128/https://i.imgur.com/uFszcHY.png"></a></td><td><a href="/hive-106258/@hivebuzz/hivefest6-contest">HiveFestā¶ Meetings Contest</a></td></tr></table> 
author | hivebuzz |
---|---|
permlink | hivebuzz-notify-cs50x-20211113t173735 |
category | hive-13323 |
json_metadata | {"image":["http://hivebuzz.me/notify.t6.png"]} |
created | 2021-11-13 17:37:36 |
last_update | 2021-11-13 17:37:36 |
depth | 1 |
children | 0 |
last_payout | 2021-11-20 17:37:36 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 952 |
author_reputation | 369,429,795,449,453 |
root_title | "[Python] List the lowest rental prices for each CP" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 107,719,059 |
net_rshares | 0 |