Login and get coding
My kids love Minecraft and they always want me to play with them. At times gathering resources can get boring so I sometimes deck them out with some enchanted items so that we can take on some pillager strongholds. Although typing in the commands is relatively simple, they can get pretty long and unwieldy!
After doing it a few times, I decided to turn to my favorite tool, Python! This bite is actually my first step in creating a command line utility that generates the commands for me. I've already done this but I thought it would be great to see how others would tackle the same problem. Your challenge here is to scrape digminecraft.com for a list of enchantable items and create a couple of classes from the information gathered.
What I'm looking for is a dictionary of Minecraft items. The page only contains information on the enchantments so that is all we'll be focusing on. If done correctly the
main()function should print the following results:Armor:  binding_curse  blast_protection  fire_protection  projectile_protection  protection  thorns Axe:  bane_of_arthropods  efficiency  fortune  sharpness  silk_touch  smite Boots:  depth_strider  feather_falling  frost_walker Bow:  flame  infinity  power  punch Chestplate:  mending  unbreaking  vanishing_curse Crossbow:  multishot  piercing  quick_charge Fishing Rod:  luck_of_the_sea  lure  mending  unbreaking  vanishing_curse Helmet:  aqua_affinity  respiration Pickaxe:  efficiency  fortune  mending  silk_touch  unbreaking  vanishing_curse Shovel:  efficiency  fortune  silk_touch Sword:  bane_of_arthropods  fire_aspect  knockback  looting  mending  sharpness  smite  sweeping  unbreaking  vanishing_curse Trident:  channeling  impaling  loyalty  riptide
Tasks to complete:
- id_name: Internal name of the enchantment
- name: User friendly name of the enchantment
- max_level: Enchantment level. Original is in Roman numerals; they need to be converted to integers
- description: Summary of what the enchantment does
- items: List of item names that are typically enchanted with this enchantment.If, for example, the
mendinginstance is printed, it should look like this:
Mending (1): Uses xp to mend your tools, weapons and armor
NOTE: Notice that the name is title cased,
max_levelis surrounded by parenthesis, which is followed by the description.
If you print its items, it would look like this:
['sword', 'chestplate', 'pickaxe', 'fishing_rod']
NOTE: Notice that the items are not in alphabetical order! They are stored in the order in which they are parsed from the html and are only alphabetized when the instance in printed.
- name: Name of the item
- enchantments: List of the enchantment instances.
If, for example, the
fishing_rodobject is printed, it should look like this:Fishing Rod:  luck_of_the_sea  lure  mending  unbreaking  vanishing_curse
NOTE: Notice that the name is title cased and that the
_has been replaced with a space!
If you were to print each enchantment belonging to the
fishing_rod, it would look like this:Curse of Vanishing (1): Cursed item will disappear after player dies Luck of the Sea (3): Increases chances of catching valuable items Lure (3): Increases the rate of fish biting your hook Mending (1): Uses xp to mend your tools, weapons and armor Unbreaking (3): Increases durability of item
NOTE: Notice that this output is exactly like the one for the Enchantment objects, because that's what they are.
The following functions are what you will need to complete:
- This function is responsible for generating a dictionary of the Enchantment objects.
- This function is responsible for generating a dictionary of the Item objects.
Some helpful tips:
Each of the enchantments has an image in place of actual item names. The best thing that I could come up with was to clean up the image name and extract the information from them. Removing the following from the names will do the job: ".", "_", "enchanted", "iron", "png", and "sm"
vanishing_cursehas this image:
Which would be scraped as
["sword", "chestplate", "pickaxe", "fishing_rod"]for that enchantment.
NOTE: Caution must be taken here since fishing_rod is a valid item name that must be maintained!
The titles will need some work as well. In it's raw form the titles are listed as
Aqua Affinity(aqua_affinity). You'll have to separate the two and assign them to their correct variables:
id_name, where the latter is the one in parenthesis.
Pay attention to that output above. Not only are the items sorted, but also each of the item's enchantments! Don't try and modify the output from
main()as that is not used in the testing.