Skip to content

Instantly share code, notes, and snippets.

@thirdy
Last active November 18, 2015 04:06
Show Gist options
  • Save thirdy/925bc249e554edb39a05 to your computer and use it in GitHub Desktop.
Save thirdy/925bc249e554edb39a05 to your computer and use it in GitHub Desktop.
Standalone Java console app to view your Github releases download counts or statistics
/*
* Copyright (C) 2015 thirdy, reddit: /u/ProFalseIdol
*
* This work is free. You can redistribute it and/or modify it under the
* terms of the Do What The Fuck You Want To Public License, Version 2,
* as published by Sam Hocevar. See http://www.wtfpl.net/ for more details.
*/
package poe.trade.assist;
import java.util.Arrays;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONArray;
import org.json.JSONObject;
import com.mashape.unirest.http.Unirest; // http://unirest.io/java.html
import com.mashape.unirest.http.exceptions.UnirestException;
/**
* After running, copy paste to google spreadsheets for viewing
*
* @author thirdy
*
*/
public class GetGithubDownloadStatistics {
/**
* @param args
* @throws UnirestException
*/
public static void main(String[] args) throws UnirestException {
System.out.println("download_count owner repo tag_name browser_download_url html_url");
Arrays.asList("blackmarket", "poe.trade.assist", "durian").stream().forEach(s -> printRepo("thirdy", s));
printRepo("bluemarlinexile", "bluemarlin");
printRepo("Stickymaddness", "Procurement");
printRepo("Novynn", "acquisitionplus");
printRepo("xyzz", "acquisition");
printRepo("EmmittJ", "PoESkillTree");
// printRepo("Bahnzo", "POE-ItemInfo"); unfortunately, the download is from google drive
printRepo("survfate", "PoESimpleGuild");
printRepo("Gloorf", "poewatcher");
printRepo("Kapps", "PoEWhisperNotifier");
printRepo("M1nistry", "GuildStatus");
printRepo("ben-wallis", "Filtration");
// printRepo("hbm50006", "tradewatch-master"); // no releases
// http://bschug.github.io/poedit/poedit.html - awesome tool, I assume no releases
// https://github.com/Asday/WhatAreTheChances no releases
// https://github.com/OmegaK2/PyPoE no releases
}
private static void printRepo(String owner, String repo) {
JSONArray array = null;
try {
array = Unirest.get("https://api.github.com/repos/" + owner + "/" + repo + "/releases")
// .basicAuth("thirdy", "quicksandisunderratedbandandofcthisisnotmyrealpassword") // note that basic auth is optional but you'll be limited to 60 request per hour
.asJson().getBody()
.getArray();
for (int i = 0; i < array.length(); i++) {
JSONObject object = (JSONObject) array.get(i);
String tag_name = object.getString("tag_name");
String html_url = object.getString("html_url");
JSONArray assets = (JSONArray) object.get("assets");
for (int j = 0; j < assets.length(); j++) {
JSONObject asset = (JSONObject) assets.get(j);
String browser_download_url = asset.getString("browser_download_url");
int download_count = asset.getInt("download_count");
print(owner, repo, html_url, tag_name, StringUtils.substringAfterLast(browser_download_url, "/"), download_count);
}
}
} catch (UnirestException e) {
e.printStackTrace();
}
}
private static void print(String owner, String repo, String html_url, String tag_name, String browser_download_url, int download_count) {
System.out.println(String.format("%d\t%s\t%s\t%s\t%s\t%s",
download_count,owner,repo,tag_name,browser_download_url,html_url
));
}
}
@thirdy
Copy link
Author

thirdy commented Nov 18, 2015

You'll need unirest into your classpath:

http://unirest.io/java.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment