Created
February 10, 2024 01:53
-
-
Save TellyO3/3c217ecc4c5c5a1dd56cce7831353f41 to your computer and use it in GitHub Desktop.
Azerothcore Gathermate database creation script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import copy | |
import json | |
from json import JSONDecodeError | |
import requests | |
""" | |
This script generates a lua table that can be used with the Gathermate addon for WoW 3.3.5. | |
Gathermate allows you to track the location of found nodes for herbs, mining veins/deposits, fishing schools, treasure | |
and gas clouds. | |
This script uses the freely available data on Azerothcore to build a database file that the addon can | |
use. Because of this, you won't have to create your own. | |
Use an addon like routes, also available for 3.3.5 to create a route on your map to visit all the possible spawns of | |
nodes. | |
IMPORTANT | |
Mining nodes overlap... The types of nodes are ordered roughly based on how frequent they are. | |
An example, in places where Saronite can spawn, so can titanium AND Rich Saronite. | |
Therefore, you will only find a few "Titanium" spawns, despite there being many Titanium veins in the world. | |
The same goes for Ragveil and Flamecap, and some fishing information. | |
This script was written by SK, sk2655 on discord if you have any questions or problems. The script is not perfect, but | |
it should give you a good indication of where to look. This script probably contains some horribly optimized disgusting | |
unpythonic code. But it works™, and that's good enough for me. Keep in mind that your game might not like the size of | |
the file produced. | |
If it doesn't work, check if the website is actually up. I never bothered to add in error handling😂. If it works | |
like intended it should generate a couple thousand lines of output. | |
Usage: | |
1. Run script, | |
2. Close WoW completely, | |
3. Place the output file in $WRATHINSTALL\WTF\Account\$ACCOUNTNAME\SavedVariables\ | |
""" | |
# List of zones with no entries based on the ID's used by the addon. | |
clean_database = { | |
0: {}, # Throwaway | |
1: {}, # Arathi | |
2: {}, # Orgrimmar | |
4: {}, # Undercity | |
5: {}, # Barrens | |
6: {}, # Darnassus | |
7: {}, # AzuremystIsle | |
8: {}, # UngoroCrater | |
9: {}, # BurningSteppes | |
10: {}, # Wetlands | |
11: {}, # Winterspring | |
12: {}, # Dustwallow | |
13: {}, # Darkshore | |
14: {}, # LochModan | |
15: {}, # BladesEdgeMountains | |
16: {}, # Durotar | |
17: {}, # Silithus | |
18: {}, # ShattrathCity | |
19: {}, # Ashenvale | |
21: {}, # Nagrand | |
22: {}, # TerokkarForest | |
23: {}, # EversongWoods | |
24: {}, # SilvermoonCity | |
25: {}, # Tanaris | |
26: {}, # Stormwind | |
27: {}, # SwampOfSorrows | |
28: {}, # EasternPlaguelands | |
29: {}, # BlastedLands | |
30: {}, # Elwynn | |
31: {}, # DeadwindPass | |
32: {}, # DunMorogh | |
33: {}, # TheExodar | |
34: {}, # Felwood | |
35: {}, # Silverpine | |
36: {}, # ThunderBluff | |
37: {}, # Hinterlands | |
38: {}, # StonetalonMountains | |
39: {}, # Mulgore | |
40: {}, # Hellfire | |
41: {}, # Ironforge | |
42: {}, # ThousandNeedles | |
43: {}, # Stranglethorn | |
44: {}, # Badlands | |
45: {}, # Teldrassil | |
46: {}, # Moonglade | |
47: {}, # ShadowmoonValley | |
48: {}, # Tirisfal | |
49: {}, # Azshara | |
50: {}, # Redridge | |
51: {}, # BloodmystIsle | |
52: {}, # WesternPlaguelands | |
53: {}, # Alterac | |
54: {}, # Westfall | |
55: {}, # Duskwood | |
56: {}, # Netherstorm | |
57: {}, # Ghostlands | |
58: {}, # Zangarmarsh | |
59: {}, # Desolace | |
61: {}, # SearingGorge | |
63: {}, # Feralas | |
64: {}, # Hillsbrad | |
65: {}, # Sunwell | |
67: {}, # BoreanTundra | |
68: {}, # Dragonblight | |
69: {}, # GrizzlyHills | |
70: {}, # HowlingFjord | |
71: {}, # IcecrownGlacier | |
72: {}, # SholazarBasin | |
73: {}, # TheStormPeaks | |
74: {}, # ZulDrak | |
76: {}, # ScarletEnclave | |
77: {}, # CrystalsongForest | |
78: {}, # LakeWintergrasp | |
80: {}, # Dalaran | |
143: {}, # Hrothgars landing | |
} | |
# This website reflects stock azerothcore, the revision hash can be found on the main page. | |
# I cannot guarantee that a private server based on azerothcore has not made changes to their node database. | |
baseurl = "https://wowgaming.altervista.org/aowow/" | |
# List of fishing ID's to check | |
fishing_ids = [ | |
180663, # Sagefish School | |
180751, # Floating Wreckage | |
180753, # Patch of Elemental Water | |
180655, # Floating Debris | |
180661, # Oil Spill | |
180683, # Firefin Snapper School | |
180684, # Greater Sagefish School | |
180682, # Oily Blackmouth School | |
180658, # School of Deviate Fish | |
180712, # Stonescale Eel Swarm | |
182957, # Highland Mixed School | |
182951, # Pure Water | |
182959, # Bluefish School | |
182954, # Brackish Mixed School | |
182958, # Mudfish School | |
182956, # School of Darter | |
182953, # Sporefish School | |
182952, # Steam Pump Flotsam | |
180248, # School of Tastyfish | |
192051, # Borean Man O' War School | |
192053, # Deep Sea Monsterbelly School | |
192048, # Dragonfin Angelfish School | |
192049, # Fangtooth Herring School | |
192050, # Glacial Salmon School | |
192059, # Glassfin Minnow School | |
192052, # Imperial Manta Ray School | |
192054, # Moonglow Cuttlefish School | |
192046, # Musselback Sculpin School | |
192057, # Nettlefish School | |
180662, # Schooner Wreckage | |
180685, # Waterlogged Wreckage | |
180901, # Bloodsail Wreckage | |
180656, # Lesser Sagefish School | |
180582, # Lesser Oily Blackmouth School | |
180664, # Sparse Oily Blackmouth School | |
180900, # Abundant Oily Blackmouth School | |
180750, # Teeming Oily Blackmouth School | |
180657, # Sparse Firefin Snapper School | |
180752, # Teeming Firefin Snapper School | |
180902, # Abundant Firefin Snapper School | |
] | |
# List of mining ID's to check | |
mining_ids = [ | |
181557, # Khorium Vein | |
191133, # Titanium Vein | |
185877, # Nethercite Deposit | |
165658, # Dark Iron Deposit | |
1734, # Gold Vein | |
150080, # Gold Vein | |
1733, # Silver Vein | |
2047, # Truesilver Deposit | |
150081, # Truesilver Deposit | |
181108, # Truesilver Deposit | |
123309, # Ooze Covered Truesilver Deposit | |
73940, # Ooze Covered Silver Vein | |
189979, # Rich Cobalt Deposit | |
175404, # Rich Thorium Vein | |
189981, # Rich Saronite Deposit | |
181569, # Rich Adamantite Deposit | |
177388, # Ooze Covered Rich Thorium Vein | |
1735, # Iron Deposit | |
123310, # Ooze Covered Mithril Deposit | |
123848, # Ooze Covered Thorium Vein | |
324, # Small Thorium Vein | |
150082, # Small Thorium Vein | |
176643, # Small Thorium Vein | |
181555, # Fel Iron Deposit | |
181556, # Adamantite Deposit | |
2040, # Mithril Deposit | |
189980, # Saronite Deposit | |
189978, # Cobalt Deposit | |
1731, # Copper Vein | |
2055, # Copper Vein | |
3763, # Copper Vein | |
103713, # Copper Vein | |
181248, # Copper Vein | |
1732, # Tin Vein | |
2054, # Tin Vein | |
3764, # Tin Vein | |
103711, # Tin Vein | |
181249, # Tin Vein | |
] | |
# List of gas cloud ID's to check | |
gas_ids = [ | |
24222, # Windy Cloud | |
17378, # Swamp Gas | |
17408, # Arcane Vortex | |
17407, # Felmist | |
32544, # Steam Cloud | |
32522, # Cinder Cloud | |
24879, # Arctic Cloud | |
] | |
# List of herb ID's to check | |
herb_ids = [ | |
1618, # Peacebloom | |
3724, # Peacebloom | |
1617, # Silverleaf | |
3725, # Silverleaf | |
1619, # Earthroot | |
3726, # Earthroot | |
1620, # Mageroyal | |
3727, # Mageroyal | |
1621, # Briarthorn | |
3729, # Briarthorn | |
2045, # Stranglekelp | |
1622, # Bruiseweed | |
3730, # Bruiseweed | |
1623, # Wild Steelbloom | |
1628, # Grave Moss | |
1624, # Kingsblood | |
2041, # Liferoot | |
2042, # Fadeleaf | |
2046, # Goldthorn | |
2043, # Khadgars Whisker | |
2044, # Wintersbite | |
2866, # Firebloom | |
142140, # Purple Lotus | |
176642, # Arthas Tears | |
142141, # Arthas Tears | |
142142, # Sungrass | |
176636, # Sungrass | |
142143, # Blindweed | |
183046, # Blindweed | |
142144, # Ghost Mushroom | |
142145, # Gromsblood | |
176637, # Gromsblood | |
176583, # Golden Sansam | |
176638, # Golden Sansam | |
176584, # Dreamfoil | |
176639, # Dreamfoil | |
176586, # Mountain Silversage | |
176640, # Mountain Silversage | |
176587, # Plaguebloom | |
176641, # Plaguebloom | |
176588, # Icecap | |
176589, # Black Lotus | |
181270, # Felweed | |
183044, # Felweed | |
181271, # Dreaming Glory | |
183045, # Dreaming Glory | |
181277, # Terocone | |
181166, # Bloodthistle | |
181281, # Mana Thistle | |
181279, # Netherbloom | |
181280, # Nightmare Vine | |
181275, # Ragveil | |
183043, # Ragveil | |
181276, # Flame Cap | |
185881, # Netherdust Bush | |
191019, # Adders Tongue | |
189973, # Goldclover | |
190172, # Icethorn | |
190171, # Lichbloom | |
190170, # Talandras Rose | |
190169, # Tiger Lily | |
191303, # Firethorn | |
190173, # Frozen Herb | |
190175, # Frozen Herb | |
190176, # Frost Lotus | |
] | |
# List of treasure ID's to check | |
treasure_ids = [ | |
2744, # Giant Clam | |
19017, # Giant Clam | |
19018, # Giant Clam | |
2843, # Battered Chest | |
2849, # Battered Chest | |
106318, # Battered Chest | |
106319, # Battered Chest | |
2844, # Tattered Chest | |
2845, # Tattered Chest | |
2847, # Tattered Chest | |
3715, # Tattered Chest | |
4096, # Tattered Chest | |
105578, # Tattered Chest | |
105579, # Tattered Chest | |
105581, # Tattered Chest | |
111095, # Tattered Chest | |
2850, # Solid Chest | |
2852, # Solid Chest | |
2855, # Solid Chest | |
2857, # Solid Chest | |
4149, # Solid Chest | |
153451, # Solid Chest | |
153453, # Solid Chest | |
153454, # Solid Chest | |
75293, # Large Battered Chest | |
153468, # Large Mithril Bound Chest | |
157936, # Un'Goro Dirt Pile | |
164958, # Bloodpetal Sprout | |
179486, # Battered Footlocker | |
179488, # Battered Footlocker | |
179490, # Battered Footlocker | |
179487, # Waterlogged Footlocker | |
179489, # Waterlogged Footlocker | |
179491, # Waterlogged Footlocker | |
179492, # Dented Footlocker | |
179494, # Dented Footlocker | |
179496, # Dented Footlocker | |
184741, # Dented Footlocker | |
179493, # Mossy Footlocker | |
179497, # Mossy Footlocker | |
179498, # Scarlet Footlocker | |
181798, # Fel Iron Chest | |
181800, # Heavy Fel Iron Chest | |
181802, # Adamantite Bound Chest | |
181804, # Felsteel Chest | |
184740, # Wicker Chest | |
185915, # Netherwing Egg | |
193997, # Everfrost Chip | |
] | |
# Translation key for zone ID's from web -> addon. | |
translate_zone_key = { | |
0: 0, # Zones I don't care about, like instances. | |
45: 1, # Arathi | |
1637: 2, # Orgrimmar | |
1497: 4, # Undercity | |
17: 5, # Barrens | |
1657: 6, # Darnassus | |
3524: 7, # AzuremystIsle | |
490: 8, # UngoroCrater | |
46: 9, # BurningSteppes | |
11: 10, # Wetlands | |
618: 11, # Winterspring | |
15: 12, # Dustwallow | |
148: 13, # Darkshore | |
38: 14, # LochModan | |
3522: 15, # BladesEdgeMountains | |
14: 16, # Durotar | |
1377: 17, # Silithus | |
3703: 18, # ShattrathCity | |
331: 19, # Ashenvale | |
3518: 21, # Nagrand | |
3519: 22, # TerokkarForest | |
3430: 23, # EversongWoods | |
3487: 24, # SilvermoonCity | |
440: 25, # Tanaris | |
1519: 26, # Stormwind | |
8: 27, # SwampOfSorrows | |
139: 28, # EasternPlaguelands | |
4: 29, # BlastedLands | |
12: 30, # Elwynn | |
41: 31, # DeadwindPass | |
1: 32, # DunMorogh | |
3357: 33, # TheExodar | |
361: 34, # Felwood | |
130: 35, # Silverpine | |
1638: 36, # ThunderBluff | |
47: 37, # Hinterlands | |
406: 38, # StonetalonMountains | |
215: 39, # Mulgore | |
3483: 40, # Hellfire | |
1537: 41, # Ironforge | |
400: 42, # ThousandNeedles | |
33: 43, # Stranglethorn | |
3: 44, # Badlands | |
141: 45, # Teldrassil | |
493: 46, # Moonglade | |
3520: 47, # ShadowmoonValley | |
85: 48, # Tirisfal | |
16: 49, # Azshara | |
44: 50, # Redridge | |
3525: 51, # BloodmystIsle | |
28: 52, # WesternPlaguelands | |
36: 53, # Alterac | |
40: 54, # Westfall | |
10: 55, # Duskwood | |
3523: 56, # Netherstorm | |
3433: 57, # Ghostlands | |
3521: 58, # Zangarmarsh | |
405: 59, # Desolace | |
51: 61, # SearingGorge | |
357: 63, # Feralas | |
267: 64, # Hillsbrad | |
4080: 65, # Sunwell | |
3537: 67, # BoreanTundra | |
65: 68, # Dragonblight | |
394: 69, # GrizzlyHills | |
495: 70, # HowlingFjord | |
210: 71, # IcecrownGlacier | |
3711: 72, # SholazarBasin | |
67: 73, # TheStormPeaks | |
66: 74, # ZulDrak | |
4298: 76, # ScarletEnclave | |
2817: 77, # CrystalsongForest | |
4197: 78, # LakeWintergrasp | |
4395: 80, # Dalaran | |
4742: 143, # Hrothgars landing | |
} | |
# Translation key for fishing ID's from web -> addon. | |
translate_fishing_key = { | |
180663: 108, # Sagefish School | |
180751: 101, # Floating Wreckage | |
180753: 102, # Patch of Elemental Water | |
180655: 103, # Floating Debris | |
180661: 104, # Oil Spill | |
180683: 105, # Firefin Snapper School | |
180684: 106, # Greater Sagefish School | |
180682: 107, # Oily Blackmouth School | |
180658: 109, # School of Deviate Fish | |
180712: 110, # Stonescale Eel Swarm | |
182957: 112, # Highland Mixed School | |
182951: 113, # Pure Water | |
182959: 114, # Bluefish School | |
182954: 115, # Brackish Mixed School | |
182958: 116, # Mudfish School | |
182956: 117, # School of Darter | |
182953: 118, # Sporefish School | |
182952: 119, # Steam Pump Flotsam | |
180248: 120, # School of Tastyfish | |
192051: 121, # Borean Man O' War School | |
192053: 122, # Deep Sea Monsterbelly School | |
192048: 123, # Dragonfin Angelfish School | |
192049: 124, # Fangtooth Herring School | |
192050: 126, # Glacial Salmon School | |
192059: 127, # Glassfin Minnow School | |
192052: 128, # Imperial Manta Ray School | |
192054: 129, # Moonglow Cuttlefish School | |
192046: 130, # Musselback Sculpin School | |
192057: 131, # Nettlefish School | |
180662: 133, # Schooner Wreckage | |
180685: 134, # Waterlogged Wreckage | |
180901: 135, # Bloodsail Wreckage | |
180656: 136, # Lesser Sagefish School | |
180582: 137, # Lesser Oily Blackmouth School | |
180664: 138, # Sparse Oily Blackmouth School | |
180900: 139, # Abundant Oily Blackmouth School | |
180750: 140, # Teeming Oily Blackmouth School | |
180657: 142, # Sparse Firefin Snapper School | |
180752: 144, # Teeming Firefin Snapper School | |
180902: 143, # Abundant Firefin Snapper School | |
} | |
# Translation key for mining ID's from web -> addon. | |
translate_mining_key = { | |
0: 0, # Overflow | |
181557: 224, # Khorium Vein | |
191133: 230, # Titanium Vein | |
185877: 227, # Nethercite Deposit | |
165658: 217, # Dark Iron Deposit | |
1734: 205, # Gold Vein | |
150080: 205, # Gold Vein | |
1733: 204, # Silver Vein | |
2047: 208, # Truesilver Deposit | |
150081: 208, # Truesilver Deposit | |
181108: 208, # Truesilver Deposit | |
123309: 211, # Ooze Covered Truesilver Deposit | |
73940: 209, # Ooze Covered Silver Vein | |
189979: 229, # Rich Cobalt Deposit | |
175404: 215, # Rich Thorium Vein | |
189981: 232, # Rich Saronite Deposit | |
181569: 223, # Rich Adamantite Deposit | |
177388: 212, # Ooze Covered Rich Thorium Vein | |
1735: 203, # Iron Deposit | |
123310: 207, # Ooze Covered Mithril Deposit | |
123848: 213, # Ooze Covered Thorium Vein | |
324: 214, # Small Thorium Vein | |
150082: 214, # Small Thorium Vein | |
176643: 214, # Small Thorium Vein | |
181555: 221, # Fel Iron Deposit | |
181556: 222, # Adamantite Deposit | |
2040: 206, # Mithril Deposit | |
189980: 231, # Saronite Deposit | |
189978: 228, # Cobalt Deposit | |
1731: 201, # Copper Vein | |
2055: 201, # Copper Vein | |
3763: 201, # Copper Vein | |
103713: 201, # Copper Vein | |
181248: 201, # Copper Vein | |
1732: 202, # Tin Vein | |
2054: 202, # Tin Vein | |
3764: 202, # Tin Vein | |
103711: 202, # Tin Vein | |
181249: 202, # Tin Vein | |
} | |
# Translation key for gas cloud ID's from web -> addon. | |
translate_cloud_key = { | |
24222: 301, # Windy Cloud | |
17378: 302, # Swamp Gas | |
17408: 303, # Arcane Vortex | |
17407: 304, # Felmist | |
32544: 305, # Steam Cloud | |
32522: 306, # Cinder Cloud | |
24879: 307, # Arctic Cloud | |
} | |
# Translation key for herb ID's from web -> addon. | |
translate_herb_key = { | |
0: 0, # Designated ID for everything I want to skip over, like herbs in instances. | |
1618: 401, # Peacebloom | |
3724: 401, # Peacebloom | |
1617: 402, # Silverleaf | |
3725: 402, # Silverleaf | |
1619: 403, # Earthroot | |
3726: 403, # Earthroot | |
1620: 404, # Mageroyal | |
3727: 404, # Mageroyal | |
1621: 405, # Briarthorn | |
3729: 405, # Briarthorn | |
2045: 407, # Stranglekelp | |
1622: 408, # Bruiseweed | |
3730: 408, # Bruiseweed | |
1623: 409, # Wild Steelbloom | |
1628: 410, # Grave Moss | |
1624: 411, # Kingsblood | |
2041: 412, # Liferoot | |
2042: 413, # Fadeleaf | |
2046: 414, # Goldthorn | |
2043: 415, # Khadgar's Whisker | |
2044: 416, # Wintersbite | |
2866: 417, # Firebloom | |
142140: 418, # Purple Lotus | |
176642: 420, # Arthas' Tears | |
142141: 420, # Arthas' Tears | |
142142: 421, # Sungrass | |
176636: 421, # Sungrass | |
142143: 422, # Blindweed | |
183046: 422, # Blindweed | |
142144: 423, # Ghost Mushroom | |
142145: 424, # Gromsblood | |
176637: 424, # Gromsblood | |
176583: 425, # Golden Sansam | |
176638: 425, # Golden Sansam | |
176584: 426, # Dreamfoil | |
176639: 426, # Dreamfoil | |
176586: 427, # Mountain Silversage | |
176640: 427, # Mountain Silversage | |
176587: 428, # Plaguebloom | |
176641: 428, # Plaguebloom | |
176588: 429, # Icecap | |
176589: 431, # Black Lotus | |
181270: 432, # Felweed | |
183044: 432, # Felweed | |
181271: 433, # Dreaming Glory | |
183045: 433, # Dreaming Glory | |
181277: 434, # Terocone | |
181166: 436, # Bloodthistle | |
181281: 437, # Mana Thistle | |
181279: 438, # Netherbloom | |
181280: 439, # Nightmare Vine | |
181275: 440, # Ragveil | |
183043: 440, # Ragveil | |
181276: 441, # Flame Cap | |
185881: 442, # Netherdust Bush | |
191019: 443, # Adder's Tongue | |
189973: 446, # Goldclover | |
190172: 447, # Icethorn | |
190171: 448, # Lichbloom | |
190170: 449, # Talandra's Rose | |
190169: 450, # Tiger Lily | |
191303: 451, # Firethorn | |
190173: 452, # Frozen Herb | |
190175: 453, # Frost Lotus | |
} | |
# Translation key for treasure ID's from web -> addon. | |
translate_treasure_key = { | |
0: 0, # Overflow | |
2744: 501, # Giant Clam | |
19017: 501, # Giant Clam | |
19018: 501, # Giant Clam | |
2843: 502, # Battered Chest | |
2849: 502, # Battered Chest | |
106318: 502, # Battered Chest | |
106319: 502, # Battered Chest | |
2844: 503, # Tattered Chest | |
2845: 503, # Tattered Chest | |
2847: 503, # Tattered Chest | |
3715: 503, # Tattered Chest | |
4096: 503, # Tattered Chest | |
105578: 503, # Tattered Chest | |
105579: 503, # Tattered Chest | |
105581: 503, # Tattered Chest | |
111095: 503, # Tattered Chest | |
2850: 504, # Solid Chest | |
2852: 504, # Solid Chest | |
2855: 504, # Solid Chest | |
2857: 504, # Solid Chest | |
4149: 504, # Solid Chest | |
153451: 504, # Solid Chest | |
153453: 504, # Solid Chest | |
153454: 504, # Solid Chest | |
75293: 507, # Large Battered Chest | |
153468: 509, # Large Mithril Bound Chest | |
157936: 511, # Un'Goro Dirt Pile | |
164958: 512, # Bloodpetal Sprout | |
179486: 515, # Battered Footlocker | |
179488: 515, # Battered Footlocker | |
179490: 515, # Battered Footlocker | |
179487: 516, # Waterlogged Footlocker | |
179489: 516, # Waterlogged Footlocker | |
179491: 516, # Waterlogged Footlocker | |
179492: 517, # Dented Footlocker | |
179494: 517, # Dented Footlocker | |
179496: 517, # Dented Footlocker | |
184741: 517, # Dented Footlocker | |
179493: 518, # Mossy Footlocker | |
179497: 518, # Mossy Footlocker | |
179498: 519, # Scarlet Footlocker | |
181798: 521, # Fel Iron Chest | |
181800: 522, # Heavy Fel Iron Chest | |
181802: 523, # Adamantite Bound Chest | |
181804: 524, # Felsteel Chest | |
184740: 526, # Wicker Chest | |
185915: 531, # Netherwing Egg | |
193997: 532, # Everfrost Chip | |
} | |
def main(): | |
database_fishing = copy.deepcopy(clean_database) | |
for fish in fishing_ids: | |
store_object_info(fish, database_fishing, translate_fishing_key) | |
convert_to_lua_table(database_fishing, "Fish") | |
database_mining = copy.deepcopy(clean_database) | |
for mine in mining_ids: | |
store_object_info(mine, database_mining, translate_mining_key) | |
convert_to_lua_table(database_mining, "Mine") | |
database_gas = copy.deepcopy(clean_database) | |
for gas in gas_ids: | |
store_object_info(gas, database_gas, translate_cloud_key) | |
convert_to_lua_table(database_gas, "Gas") | |
database_herb = copy.deepcopy(clean_database) | |
for herb in herb_ids: | |
store_object_info(herb, database_herb, translate_herb_key) | |
convert_to_lua_table(database_herb, "Herb") | |
database_treasure = copy.deepcopy(clean_database) | |
for treasure in treasure_ids: | |
store_object_info(treasure, database_treasure, translate_treasure_key) | |
convert_to_lua_table(database_treasure, "Treasure") | |
def store_object_info(object_id, database, object_key): | |
"""Adds all nodes retrieved from the web to the database""" | |
raw_data = get_object_info(object_id) | |
if raw_data is not None: | |
for entry in raw_data: | |
add_entry(object_id, entry[0], entry[1], entry[2], database, object_key) | |
def add_entry(object_id, zone_id, x, y, database, object_key): | |
"""Adds a new node to the database""" | |
coords = transform_coords(x, y) | |
object_id = transform_id(object_id, object_key) | |
zone_id = transform_id(zone_id, translate_zone_key) | |
database[zone_id][coords] = object_id | |
def transform_coords(x, y): | |
"""Transforms the web format coordinates into the format used by the addon. | |
The addon stores the coordinates as an 8-digit number like so: xxxxyyyy. """ | |
x = str(x * 1000)[:4] | |
y = str(y * 1000)[:4] | |
return x + y | |
def transform_id(web_id, translation_key): | |
"""Transforms the ID, of either an object or a zone to an ID that is recognized by the addon.""" | |
if web_id in translation_key: | |
return translation_key[web_id] | |
else: | |
return translation_key[0] | |
def get_object_info(node_id): | |
"""Retrieves the coordinates and the zones in which an object is located based on its id.""" | |
if node_id in gas_ids: | |
page = requests.get(f"{baseurl}?npc={node_id}") # These fuckers are not objects. | |
else: | |
page = requests.get(f"{baseurl}?object={node_id}") | |
data = page.text | |
# Extract the actual JSON we need to extract the coordinates from | |
start = data.find("g_mapperData = ") + len("g_mapperData = ") | |
end = data.find("var myMapper = new Mapper") | |
data = data[start:end] | |
data = data.strip() | |
data = data.removesuffix(";") | |
try: | |
raw_data = json.loads(data) | |
except JSONDecodeError as _: # Something is wrong with the data we received. | |
return None | |
return extract_coords(raw_data) | |
def extract_coords(raw_data): | |
"""Extracts the all node coordinates along with their respective zones based on raw scraped data.""" | |
coord_list = [] | |
for zone in raw_data: | |
try: | |
for node in raw_data[zone][0]["coords"]: | |
coord_list.append([int(zone), node[0], node[1]]) | |
# zone, x coord, y coord | |
except KeyError as _: | |
pass | |
return coord_list | |
def convert_to_lua_table(database_part, category): | |
"""Converts the database into a lua table.""" | |
with open("GatherMate.lua", 'a') as f: | |
f.write(f"GatherMate{category}DB = {{\n") | |
database_part.pop(0) | |
for zone in database_part: | |
f.write(f"\t[{zone}] = {{\n") | |
for node in database_part[zone]: | |
f.write(f"\t\t[{node}] = {database_part[zone][node]},\n") | |
f.write(f"\t}},\n") | |
f.write("}\n") | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment