NATION

PASSWORD

The Gold Retriever - Check your Puppets' Banks and Decks!

The place to wheel and deal, talk shop, and build up your dream deck!
User avatar
Valentine Z
Postmaster-General
 
Posts: 13018
Founded: Nov 08, 2015
Scandinavian Liberal Paradise

The Gold Retriever - Check your Puppets' Banks and Decks!

Postby Valentine Z » Fri Dec 13, 2019 11:40 pm

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. ^^
Image

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
Image
Last edited by Valentine Z on Mon Jan 13, 2020 11:55 am, edited 10 times in total.
Val's Stuff. ♡ ^_^ ♡ For You
If you are reading my sig, I want you to have the best day ever ! You are worth it, do not let anyone get you down !
Glory to De Geweldige Sierlijke Katachtige Utopia en Zijne Autonome Machten ov Valentine Z !
(✿◠‿◠) ☆ \(^_^)/ ☆

Issues Thread Photography Stuff Project: Save F7. Stats Analysis

The Sixty! Valentian Stories! Gwen's Adventures!

• Never trouble trouble until trouble troubles you.
• World Map is a cat playing with Australia.
Let Fate sort it out.

User avatar
Feu de Glace
Lobbyist
 
Posts: 22
Founded: Mar 22, 2016
Democratic Socialists

Postby Feu de Glace » Fri Dec 13, 2019 11:51 pm

Thank you so much for doing this, V! (V, not V—clearly) It's already been amazingly helpful for me personally and I think a lot of other people too.

I can't wait to see what random API related shenanigans you come up!

User avatar
Valentine Z
Postmaster-General
 
Posts: 13018
Founded: Nov 08, 2015
Scandinavian Liberal Paradise

Postby Valentine Z » Fri Dec 13, 2019 11:54 pm

Feu de Glace wrote:Thank you so much for doing this, V! (V, not V—clearly) It's already been amazingly helpful for me personally and I think a lot of other people too.

I can't wait to see what random API related shenanigans you come up!

Haha, you're welcome! ^^ And you are welcome for the various feedback as well! None of this would have improvements as great as this without you guys helping me out too. :3
Val's Stuff. ♡ ^_^ ♡ For You
If you are reading my sig, I want you to have the best day ever ! You are worth it, do not let anyone get you down !
Glory to De Geweldige Sierlijke Katachtige Utopia en Zijne Autonome Machten ov Valentine Z !
(✿◠‿◠) ☆ \(^_^)/ ☆

Issues Thread Photography Stuff Project: Save F7. Stats Analysis

The Sixty! Valentian Stories! Gwen's Adventures!

• Never trouble trouble until trouble troubles you.
• World Map is a cat playing with Australia.
Let Fate sort it out.

User avatar
Recuecn
Ambassador
 
Posts: 1049
Founded: Feb 02, 2015
New York Times Democracy

Postby Recuecn » Sat Dec 14, 2019 12:31 am

I'd like to add my thanks as well! This tool is very helpful and I appreciate you making it public, VZ, but I especially appreciate how helpful and accommodating you've been helping users like me figure it out! Thanks again for this community contribution!
rəswɛsən

User avatar
Valentine Z
Postmaster-General
 
Posts: 13018
Founded: Nov 08, 2015
Scandinavian Liberal Paradise

Postby Valentine Z » Sat Dec 14, 2019 12:39 am

Recuecn wrote:I'd like to add my thanks as well! This tool is very helpful and I appreciate you making it public, VZ, but I especially appreciate how helpful and accommodating you've been helping users like me figure it out! Thanks again for this community contribution!

You're welcome! And especially thanks to you peeps for helping me out as well! ^^
Val's Stuff. ♡ ^_^ ♡ For You
If you are reading my sig, I want you to have the best day ever ! You are worth it, do not let anyone get you down !
Glory to De Geweldige Sierlijke Katachtige Utopia en Zijne Autonome Machten ov Valentine Z !
(✿◠‿◠) ☆ \(^_^)/ ☆

Issues Thread Photography Stuff Project: Save F7. Stats Analysis

The Sixty! Valentian Stories! Gwen's Adventures!

• Never trouble trouble until trouble troubles you.
• World Map is a cat playing with Australia.
Let Fate sort it out.

User avatar
SherpDaWerp
Technical Moderator
 
Posts: 1895
Founded: Mar 02, 2016
Benevolent Dictatorship

Postby SherpDaWerp » Sat Dec 14, 2019 1:02 am

And here I was, in the middle of making a Node.js variant of this exact thing! Mind if I steal some of your ideas for my version?
Became an editor on 18/01/23 techie on 29/01/24

Rampant statistical speculation from before then is entirely unofficial

User avatar
Valentine Z
Postmaster-General
 
Posts: 13018
Founded: Nov 08, 2015
Scandinavian Liberal Paradise

Postby Valentine Z » Sat Dec 14, 2019 1:03 am

SherpDaWerp wrote:And here I was, in the middle of making a Node.js variant of this exact thing! Mind if I steal some of your ideas for my version?

Of course, feel free to do so! ^^ I don't mind sharing and seeing what others come up with as well. :3
Val's Stuff. ♡ ^_^ ♡ For You
If you are reading my sig, I want you to have the best day ever ! You are worth it, do not let anyone get you down !
Glory to De Geweldige Sierlijke Katachtige Utopia en Zijne Autonome Machten ov Valentine Z !
(✿◠‿◠) ☆ \(^_^)/ ☆

Issues Thread Photography Stuff Project: Save F7. Stats Analysis

The Sixty! Valentian Stories! Gwen's Adventures!

• Never trouble trouble until trouble troubles you.
• World Map is a cat playing with Australia.
Let Fate sort it out.

User avatar
SherpDaWerp
Technical Moderator
 
Posts: 1895
Founded: Mar 02, 2016
Benevolent Dictatorship

Postby SherpDaWerp » Sat Dec 14, 2019 1:05 am

Sick, thanks heaps. I'll keep ya'll posted! :)
Last edited by SherpDaWerp on Sat Dec 14, 2019 1:05 am, edited 1 time in total.
Became an editor on 18/01/23 techie on 29/01/24

Rampant statistical speculation from before then is entirely unofficial

User avatar
Valentine Z
Postmaster-General
 
Posts: 13018
Founded: Nov 08, 2015
Scandinavian Liberal Paradise

Postby Valentine Z » Sat Dec 14, 2019 10:50 pm

As suggested by Ballotonia, one thing that I am trying to implement (and seeking help) is to add an UserAgent output so that the site can identify the users in the rare event that the script goes too fast.

Here's what was said in the Discord server:
Improvement suggestions: set a UserAgent string, so that the site logs know who wrote the script (contact info in case of something going horribly wrong). Also, check the error value of the request result. That way you catch it if you're going too fast. Seems so far this ran on a system which was slow enough, so it never ran into a speed problem, but if someone copies your script and runs it in a python shell directly I would expect it to go too fast.

I will try to add that in, but I need something that will work without pip install, basically something that Google Colab can run, as well as the basic Python/Anaconda codes. Worst case scenario is needing to install the needed package, but this should not be invasive; after all, you are just installing the Python package.

I will see how it goes! ^^ It will be great if one of you can help me out, so yeah. ^^;
Last edited by Valentine Z on Sat Dec 14, 2019 11:51 pm, edited 1 time in total.
Val's Stuff. ♡ ^_^ ♡ For You
If you are reading my sig, I want you to have the best day ever ! You are worth it, do not let anyone get you down !
Glory to De Geweldige Sierlijke Katachtige Utopia en Zijne Autonome Machten ov Valentine Z !
(✿◠‿◠) ☆ \(^_^)/ ☆

Issues Thread Photography Stuff Project: Save F7. Stats Analysis

The Sixty! Valentian Stories! Gwen's Adventures!

• Never trouble trouble until trouble troubles you.
• World Map is a cat playing with Australia.
Let Fate sort it out.

User avatar
Valentine Z
Postmaster-General
 
Posts: 13018
Founded: Nov 08, 2015
Scandinavian Liberal Paradise

Postby Valentine Z » Mon Dec 16, 2019 1:31 am

More features!

I am proud to announce that the code now 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.

How to set the DV and Bank floors? Right here as shown in the screenshot:
https://media.discordapp.net/attachments/551962655380996106/656050499308617758/unknown.png

See for yourself here! ^^
https://media.discordapp.net/attachments/551962655380996106/656050118675398676/unknown.png?width=2880&height=1015

-----

The UserAgent thing is still held at the backburner for the time being. ^^;

(Screenshots are linked instead of the img tag used, given the resolutions exceeding 1800.)

-----

Credit: Special thanks to Praeceps for this helpful suggestion. ^^
Last edited by Valentine Z on Mon Dec 16, 2019 1:41 am, edited 3 times in total.
Val's Stuff. ♡ ^_^ ♡ For You
If you are reading my sig, I want you to have the best day ever ! You are worth it, do not let anyone get you down !
Glory to De Geweldige Sierlijke Katachtige Utopia en Zijne Autonome Machten ov Valentine Z !
(✿◠‿◠) ☆ \(^_^)/ ☆

Issues Thread Photography Stuff Project: Save F7. Stats Analysis

The Sixty! Valentian Stories! Gwen's Adventures!

• Never trouble trouble until trouble troubles you.
• World Map is a cat playing with Australia.
Let Fate sort it out.

User avatar
Valentine Z
Postmaster-General
 
Posts: 13018
Founded: Nov 08, 2015
Scandinavian Liberal Paradise

Postby Valentine Z » Thu Dec 19, 2019 9:56 pm

New version has been pushed! There was a small error/bug with deckless or bankless nations. In other words, these nations exist, but they neither have bank nor deck.

I didn't mean no bank as in 0.00 bank. I mean that these nations have no bank value, not even 0.00, assigned to it. It returns a None. That threw off the code because "None" is not a float. It's a little different from float(0.00), because 0 is still a number.

This should hopefully fix it, because the types of errors are a little too vast. Let me know if it works! ^^

Image
Last edited by Valentine Z on Thu Dec 19, 2019 10:04 pm, edited 3 times in total.
Val's Stuff. ♡ ^_^ ♡ For You
If you are reading my sig, I want you to have the best day ever ! You are worth it, do not let anyone get you down !
Glory to De Geweldige Sierlijke Katachtige Utopia en Zijne Autonome Machten ov Valentine Z !
(✿◠‿◠) ☆ \(^_^)/ ☆

Issues Thread Photography Stuff Project: Save F7. Stats Analysis

The Sixty! Valentian Stories! Gwen's Adventures!

• Never trouble trouble until trouble troubles you.
• World Map is a cat playing with Australia.
Let Fate sort it out.

User avatar
Valentine Z
Postmaster-General
 
Posts: 13018
Founded: Nov 08, 2015
Scandinavian Liberal Paradise

Postby Valentine Z » Mon Dec 30, 2019 4:09 am

As I was notified, the code was running through a problem. Apparently, every single nation and API call was returning "The nation does not exist" error, even if the nation exists.

The code is effectively down and out at the moment.

I will be working on this as soon as possible!

EDIT: Something happened to the XML retriever package that I am using. Maybe the syntax or the way it works changed, or something to that effect. I'll try to look at it when I get back home.
Last edited by Valentine Z on Mon Dec 30, 2019 4:36 am, edited 2 times in total.
Val's Stuff. ♡ ^_^ ♡ For You
If you are reading my sig, I want you to have the best day ever ! You are worth it, do not let anyone get you down !
Glory to De Geweldige Sierlijke Katachtige Utopia en Zijne Autonome Machten ov Valentine Z !
(✿◠‿◠) ☆ \(^_^)/ ☆

Issues Thread Photography Stuff Project: Save F7. Stats Analysis

The Sixty! Valentian Stories! Gwen's Adventures!

• Never trouble trouble until trouble troubles you.
• World Map is a cat playing with Australia.
Let Fate sort it out.

User avatar
Valentine Z
Postmaster-General
 
Posts: 13018
Founded: Nov 08, 2015
Scandinavian Liberal Paradise

Postby Valentine Z » Mon Dec 30, 2019 7:44 am

Special thanks to Racoda for helping me out with this one!

So err... rookie mistake in the code! As Ballotonia and others have actually advised me to, the code needs an User Agent, basically something that identifies your main nation, or the user behind it. I put it off for a while not because I think that it's unimportant. I was doing some other stuff, and I still am not very sure what kind of stuff UserAgent needs, and the like. But this was actually... pretty okay, as it turns out. It doesn't need any personal info, just a main nation identifying who you are.

Disclaimer: FOR THE main_nation FIELD, PLEASE DO NOT USE ANY OTHER NATION THAT ARE NOT YOURS. THE MAIN NATION FIELD SHOULD BE YOURS AND YOURS ONLY. I will not be responsible for the misuse of the name fields as UserAgent.

To clarify, the list of nations you want to see can be any other nations that are either yours or not, that part doesn't matter and it's fine. The UserAgent, however, should be YOUR nation.

This code is at the top few lines to prevent it from being missed and scrolled away.

Image

I decided not to spoiler the big image because this needs to be seen and emphasized for responsible usage.
Last edited by Valentine Z on Mon Dec 30, 2019 3:34 pm, edited 4 times in total.
Val's Stuff. ♡ ^_^ ♡ For You
If you are reading my sig, I want you to have the best day ever ! You are worth it, do not let anyone get you down !
Glory to De Geweldige Sierlijke Katachtige Utopia en Zijne Autonome Machten ov Valentine Z !
(✿◠‿◠) ☆ \(^_^)/ ☆

Issues Thread Photography Stuff Project: Save F7. Stats Analysis

The Sixty! Valentian Stories! Gwen's Adventures!

• Never trouble trouble until trouble troubles you.
• World Map is a cat playing with Australia.
Let Fate sort it out.

User avatar
Valentine Z
Postmaster-General
 
Posts: 13018
Founded: Nov 08, 2015
Scandinavian Liberal Paradise

Postby Valentine Z » Mon Dec 30, 2019 8:20 am

Sorry if I have been rapidly churning out posts to the point of spam. I figured that this could be a separate post!

So... you have the first chunk of code that basically outputs as usual, yes? However, you ask: What if I want to export or paste it into Excel / Google Sheets?

Ask and you shall receive, for now you got a second block of code below that puts all these data neatly into a Pandas table. All you need to do is select that cell, run it, Ctrl + A the output, and paste it in your favorite table / spreadsheet program!

Image
Val's Stuff. ♡ ^_^ ♡ For You
If you are reading my sig, I want you to have the best day ever ! You are worth it, do not let anyone get you down !
Glory to De Geweldige Sierlijke Katachtige Utopia en Zijne Autonome Machten ov Valentine Z !
(✿◠‿◠) ☆ \(^_^)/ ☆

Issues Thread Photography Stuff Project: Save F7. Stats Analysis

The Sixty! Valentian Stories! Gwen's Adventures!

• Never trouble trouble until trouble troubles you.
• World Map is a cat playing with Australia.
Let Fate sort it out.

User avatar
Valentine Z
Postmaster-General
 
Posts: 13018
Founded: Nov 08, 2015
Scandinavian Liberal Paradise

Postby Valentine Z » Fri Feb 28, 2020 8:50 am

A quick bump and more info to give you this quick and dirty QOL fix! So now the variables that you need to edit and stuff are all on the top instead of being scattered all over the place. Once again, you will still need to login using your Gmail account, in order to use the Playground mode.

Image


My future plan is to make it like Auralia's NS Login Git Repo. It looks cleaner, and it actually bypasses the need for logging in and whatsoever. I will see to it soon, hopefully by next month if I am free!
Val's Stuff. ♡ ^_^ ♡ For You
If you are reading my sig, I want you to have the best day ever ! You are worth it, do not let anyone get you down !
Glory to De Geweldige Sierlijke Katachtige Utopia en Zijne Autonome Machten ov Valentine Z !
(✿◠‿◠) ☆ \(^_^)/ ☆

Issues Thread Photography Stuff Project: Save F7. Stats Analysis

The Sixty! Valentian Stories! Gwen's Adventures!

• Never trouble trouble until trouble troubles you.
• World Map is a cat playing with Australia.
Let Fate sort it out.


Advertisement

Remove ads

Return to Trading Cards

Who is online

Users browsing this forum: No registered users

Advertisement

Remove ads