Valentine's Meowvellous Adventures into Coding - Bank and Deck Value Retriever!
FIRST TIME USER? Please check this post out!
Hello to you, my friends! ^^
So yesterday, this idea suddenly took off, and it was an adaptation on the code that I was using to retrieve the NS Stats. With that out of the way, I would like to introduce to you - The Gold Retriever, as I would like to call it! Basically, it's a Python code that uses NationStates' API in order to trawl through a list of puppets / nations that you have inputted and will spit out the relevant stats.
Link to it here: https://colab.research.google.com/drive/1Rrd20eBdX-MvLkUHJGHhIdJP3SrjPbtE. I might be planning a Git repo soon, but not at the immediate moment.
How does it work?
It simply makes use of the https://www.nationstates.net/cgi-bin/api.cgi?q=cards+info;nationname= API in order to extract the Trading cards information about that nation, and print it over the list of puppets that you have typed in as an input. Here's a screenshot of the latest build so far. ^^
So far it can handle various errors after several improvements to the code. The code is programmed to run even if there are:
- Nations that have CTE'd and thus the code cannot find the deck and the bank value of it. Rather than crashing it, it will continue.
- Nations that don't have deck but have a bank will still be displayed.
- There are special occasions whereby the nation does exist, but it neither has bank nor deck, almost as if it has not initiated the card game yet. These are also acknowledged and it will reflect back as having 0.00 bank and 0.00 DV.
How to use it?
The link that I have shared made it so that no one else but me can edit the original code. However, that's where it comes in handy! If you log in with your Gmail account, you can enter "Playground Mode", which is a programming term for editing and modifying the code, but without changing the original. Basically, you can change the list of puppets, and for those who are more daring, you can also edit the other parts of the code to make it better, or to see how it works. The Gmail account can be anything, and it can be an anonymous burner account as well! As long as you are logged in, you can enter Playground Mode, as well as make a copy for yourself straight into the burner account's Google Drive so that you have a copy of your own.
In short, log in, or copy-paste the code locally into your IDE. Then paste the list of puppets inside, then let it run. (There was an original idea of the code reading from a .txt file for the list of puppets, but this has been abandoned in favor of making the code self-complete. So if you have thousands of puppets, this might get a little difficult.)
You can interrupt the code any time with Ctrl + C, or the Stop button you can find on Google Colab. This will invoke KeyboardInterrupt, which basically translates to "You interrupted the code, so the error came from you, not from the code", so if you see this, don't fret. You simply interrupted the code, and it can be run again. If this happens, the code will gather up whatever variables it have and return you the data it collected so far, along with it printing out the individual puppets. That error in the screenshot is me interrupting it.
The code also has the ability to spit out a list of puppets that has a certain threshold of Bank, or DV. And you can modify this to your heart's content. For my testing, and for the original code, I have defaulted to 5.00 Bank and 20.00 DV. Basically, along the way, the code will sniff out your puppets and check on certain conditions to spit out two lists:
- The Bank Threshold, for example, 5.00 Bank. As you can see in the code later, the nations that has >= 5.00 (more than or equal to) Bank will have the nation's name appended inside one list. This is called High-Bank Puppets.
- The DV Threshold, for example, 20.00 DV. This will append a smaller puppet list from your bigger list, indicating which nations have >= 20.00 DV. This is called High-DV Puppets.
Some important points.
- The code has a sleep function (defaulted as sleep(0.000), time is in seconds) in order to deliberately delay the process of getting API requests. To my knowledge, one nation call is equal to one API request, so this code does not have 2 API calls for bank and deck value each. Both of these values already exists from one call, so it is strictly one nation = one API. So far, due to the time complexity of processing the XML code and printing out the data, it stays well below the 50 requests / 30 seconds = 1.666667 requests / second. If it does exceed, you can increase the sleep(0.000) to any number (in seconds) so that it will put in an artificial delay. Test it out with a small sample size of puppets if you are not sure. ALWAYS make sure that the API request rate is within acceptable rate!
- The code DOES NOT ask you for any personal information other than needing a list of your puppets or nations that you wanted to put inside. You will need to log into Gmail, sure, but you can use a burner account for that if you so desire. Additionally, for those that have Python and Anaconda on their machines, you can simply copy and paste the code inside your desired IDE and let it run.
- So far there is a glitch that where if the nation does not exist, it will still return 0.00 Bank and 0.00 DV, instead of returning an output "This nation not found!" For instance, in that screenshot, Vostrov is edited as Vostrofsdjnksdjnk and yet it is still returned. I cannot fix this bug for the time being, and will need some time to deal with various exceptions - bad XML, no such nation exists, or empty Deck Space/Value.
- The DV - Deck Value, changes very rapidly even in the span of a few seconds, so what you have after the code finished trawling for DV, can be significantly different from the realtime value. This is normal due to the nature of cards being constantly auctioned and having their MVs changed.
Standard Disclaimer.
The aim of this code is for NationStates users to enter their list of puppets (or anyone else's, if they want) and to check the banks and total banks. This code only extracts API through public means. IT DOES NOT ASK FOR PASSWORDS, OR ANY OTHER SENSITIVE INFORMATION - SECRETLY OR OTHERWISE. The Python code does not require any external files, and it can work standalone on Google Colab (only outputting on the browser and does not write files onto your Desktop, or your Local machine). This is all to my knowledge. If there are discrepancies in the codes from other people who have copied and edited my code, my original code will take precedence in terms of legality and making sure that everything is followed on the dot to NS' OSRS, as well as National and International Laws regarding internet privacy.
Credit goes to the NS Technical and Admin team for the API, and myself for the code (in the Author field). However, this code would not have been where it has been now without the help of a lot of people from the NS Card Server (link here). I declare the code public while taking ownership of the original - feel free to modify and share it with others on the site, as well as to improve on the current design.
Happy Trading! ^^
- Valentine Z