Metrics For Premium Resources

Sep 23, 2020
Metrics For Premium Resources
  • (back to thread)

    Utility to build charts showing your premium resource sales from Spigot.

    I wrote this utility a few years ago but I wanted to document how to use it so that it can hopefully be of some use to other people as well. Here is a quick screenshot of one of the charts. The rest you can find on my website here.
    [​IMG]

    The basic idea was I had a bunch of PayPal receipts in my email inbox from a few years of selling premium resources on Spigot. I wanted a way to track these a bit better so I ended up writing a utility to comb through my inbox, pick out these receipts, and parse them into some useful data. After running the data parsing utility, I used c3.js to create graphs from these static data files.

    You could definitely improve this by making a dynamic web application that runs this data collection more often, but I host my website through Github Pages so I create static data files every few months as I see fit at the moment.

    You interested in seeing your charts? Cool, let's get started.

    Step 1: Clone the gmail data parsing repo (PayPalGmailComb)

    Step 2: Modify the ResourceType enum to match your own premium resources

    This can be found in the PaypalPurchase.java file and will look like this:
    Code (Java):
    public enum ResourceType {
        SHOP, MACHINES, ARATHI_BASIN;
        public static ResourceType parse(String s){
            if(s.contains("Shop"))
                return SHOP;
            if(s.contains("Machines")){
                return MACHINES;
            }
            if(s.contains("Arathi")){
                return ARATHI_BASIN;
            }
            return null;
        }
    }
    Simply change these values to match your own premium resources and their names. (Just check your Paypal receipt emails to see what values to put here. These are just the names of my own Premium resources)
    Step 3: Generate a Google Oauth2 Token to allow your program to read from your Gmail inbox
    Navigate to https://console.developers.google.com/apis/ and then go to Credentials. Create a new OAuth Client ID credential for Desktop.
    [​IMG]
    Download your Token and you will get a client_secret_*****************.json file. Rename this to client_secret.json and place it in the resources folder (/PaypalGmailComb/src/main/resources).​

    Step 4: Run the code

    The main class is in JsonExporter.java. Each method in here creates a different dataset file that our charts are going to use. It will export a few JSON files all to a directory under your main PayPalGmailComb repo.

    When you first run the code, a browser window will pop up and ask that you login with your Google account you want to read your gmail inbox in. Sign in with the google account that your paypal emails are going to here and you will see a window that the app is unauthorized. You can authorize your App if you want but feel free to just skip this as shown in the screenshot.
    [​IMG]

    From here on, your Oauth2.0 token will be saved as a cached credential in your "user.home" system path under .credentials/gmail-java-quickstart. If you ever want to remove this, feel free and you will have to sign in to your google account to generate a new cached credential.

    This will take a few minutes to run depending on the amount of email receipts you have so sit back, relax and have a nice age appropriate drink.
    Step 5: Use the generated data files in some charts!

    I have written some charts using c3.js that I will leave the downloads for in this google drive link.
    The files in here contain a basic html webpage to display the charts and the different javascript files, one for each type of chart corresponding to the data file that was generated. Just drop your generated JSON data files from step 4 into the json folder here. You will need to run a basic webserver to allow the javascript to read from local files but I am going to assume some knowledge here.

    And that's it! Please let me know if this was helpful or if there is anything else that would be useful to add.

    You can reply to the main thread here!
    Much love!
    -Snow





  • Loading...
  • Loading...