diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 7232d1c..adba367 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,14 +2,17 @@ + + + - - - - + + + + @@ -212,22 +215,22 @@ - + - - + + - - + + - - + + - + @@ -252,17 +255,25 @@ - + - + + + + + - + + + + + - + \ No newline at end of file diff --git a/README.md b/README.md index 2f94836..53b39f0 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,8 @@ https://nickcano.com/reversing-league-of-legends-client/ https://lcu.vivide.re/ - LCU docs +https://jsoup.org/ - java web scraping + **TODO**: Spin up Discord API - check if Discord has r/w/x permissions to set runes @@ -21,8 +23,6 @@ how to get runes? get high elo matches, see what they are running via riot api? https://developer.riotgames.com/apis#match-v4/GET_getMatch -clean up making rune pages if pages already exist - **Problems**: LCU wrapper only runs locally - can't be entirely server side diff --git a/pom.xml b/pom.xml index 69160a8..ca3d24c 100644 --- a/pom.xml +++ b/pom.xml @@ -47,6 +47,13 @@ 2.8.6 + + + org.jsoup + jsoup + 1.13.1 + + diff --git a/src/main/java/org/example/App.java b/src/main/java/org/example/App.java index a357449..24ec039 100644 --- a/src/main/java/org/example/App.java +++ b/src/main/java/org/example/App.java @@ -10,6 +10,7 @@ import generated.LolPerksPerkPageResource; import org.example.champs.ChampLoader; +import org.example.puller.RunePuller; import org.example.runes.RuneFamily; import org.example.runes.RuneSlots; @@ -29,19 +30,7 @@ public class App { static ChampLoader champLoader = new ChampLoader(); static HashMap champNamesAndKeys = champLoader.getChampMap(); - static List poppyRunes = Arrays.asList(8437, 8446, 8429, 8451, 8345, 8313, 5005, 5008, 5002); - //grasp, demolish, - //perfect timing - //resolve > inspiration - - /* - precision: 8000 - domination: 8100 - sorcery: 8200 - inspiration: 8300 - resolve: 8400 - */ - + static RunePuller opggGetter = new RunePuller(); public static void main(String[] args) { @@ -161,19 +150,8 @@ public static void setNewPage() { getApi().executeDelete("/lol-perks/v1/pages"); } - LolPerksPerkPageResource newPage = new LolPerksPerkPageResource(); - List listOfNewPerks; String champ = getCurrentChamp(); - - /* - TODO: Replace this with code that fetches proper runepages for each champ - */ - - newPage.name = "Runes: " + champ; - listOfNewPerks = poppyRunes; - newPage.primaryStyleId = 8400; - newPage.subStyleId = 8300; - newPage.selectedPerkIds = listOfNewPerks; + LolPerksPerkPageResource newPage = doTheThing(champ); getApi().executePost("/lol-perks/v1/pages/", newPage); @@ -183,6 +161,108 @@ public static void setNewPage() { } + } + + /* + Gets locked in champ and fetches runes + */ + private static LolPerksPerkPageResource doTheThing(String champ) { + ArrayList runenameStrings = opggGetter.returnRunes(champ); + + List opRunes = new ArrayList(); + + //System.out.println(runeNamesAndIds); + + for (String str : runenameStrings) { + //System.out.println(str); + str = str.replace(" ", ""); + //removes spacing + + String res = runeNamesAndIds.get(str); + //System.out.println(res); + if (res != null) { + opRunes.add(Integer.parseInt(res)); + //if its not a tertiary + } + } + + opRunes.add(5005); + opRunes.add(5008); + opRunes.add(5002); + + LolPerksPerkPageResource newPage = new LolPerksPerkPageResource(); + + //List poppyRunes = Arrays.asList(8437, 8446, 8429, 8451, 8345, 8313, 5005, 5008, 5002); + //grasp, demolish, + //perfect timing + //resolve > inspiration + /* + 5005, > 10% atck speed + 5008, > +9 adaptive force + 5002 > +6 armor + */ + + newPage.name = "Runes: " + champ; + + //GOTTA GET THESE SOMEHOW + /* + precision: 8000 + domination: 8100 + sorcery: 8200 + inspiration: 8300 + resolve: 8400 + */ + + newPage.primaryStyleId = 8000; + newPage.subStyleId = 8100; + + //primary id + if (opRunes.contains(8112) || opRunes.contains(8124) || opRunes.contains(8128) || opRunes.contains(9923)) { + System.out.println("domination"); + newPage.primaryStyleId = 8100; + } else if (opRunes.contains(8214) || opRunes.contains(8229) || opRunes.contains(8230)) { + System.out.println("sorcery"); + newPage.primaryStyleId = 8200; + } else if (opRunes.contains(8351) || opRunes.contains(8360) || opRunes.contains(8358)) { + System.out.println("inspiration"); + newPage.primaryStyleId = 8300; + } else if (opRunes.contains(8437) || opRunes.contains(8439) || opRunes.contains(8465)) { + System.out.println("resolve"); + newPage.primaryStyleId = 8400; + } else if (opRunes.contains(8005) || opRunes.contains(8008) || opRunes.contains(8021) || opRunes.contains(8010)) { + System.out.println("precision"); + newPage.primaryStyleId = 8000; + } + + + String arbSecond = String.valueOf(opRunes.get(4)); + if (arbSecond.matches("81[0-9][0-9]")) { + System.out.println("domination secondary!"); + newPage.subStyleId = 8100; + } else if (arbSecond.matches("82[0-9][0-9]")) { + System.out.println("srocery secondary!"); + newPage.subStyleId = 8200; + + } else if (arbSecond.matches("83[0-9][0-9]")) { + newPage.subStyleId = 8300; + + System.out.println("inspiration secondary!"); + } else if (arbSecond.matches("84[0-9][0-9]")) { + System.out.println("reoslve secondary!"); + newPage.subStyleId = 8400; + + } else if (arbSecond.matches("80[0-9][0-9]")) { + System.out.println("precision secondary!"); + newPage.subStyleId = 8500; + + } + + newPage.selectedPerkIds = opRunes; + + + return newPage; + + } /* @@ -217,8 +297,10 @@ public static HashMap getPerkNames() { for (int i = 0; i < s.length; i++) { for (int j = 0; j < s[i].runes.length; j++) { String aName = s[i].runes[j].name; + aName = aName.replace("\'", ""); + //removes ' for future's market String anId = s[i].runes[j].id; - runeNamesAndIds.put(anId, aName); + runeNamesAndIds.put(aName, anId); } } diff --git a/src/main/java/org/example/puller/RunePuller.java b/src/main/java/org/example/puller/RunePuller.java new file mode 100644 index 0000000..12735f3 --- /dev/null +++ b/src/main/java/org/example/puller/RunePuller.java @@ -0,0 +1,128 @@ +package org.example.puller; + +import org.jsoup.Jsoup; +import org.jsoup.nodes.Document; +import org.jsoup.nodes.Element; +import org.jsoup.select.Elements; + +import java.io.IOException; +import java.util.ArrayList; + +public class RunePuller { + + /* + this class will pull runes from whatever resource (riot, op.gg, etc) + in order to create preferred rune pages for each champ. + */ + + ArrayList runeNames = new ArrayList<>(); + + + public RunePuller() { + + } + + public ArrayList returnRunes(String champ) { + + /* + urls structured like this: + https://na.op.gg/champion/poppy/statistics/top + + if you remove role, defaults to most common one: ie - + https://na.op.gg/champion/poppy/statistics > top runes appear first + */ + + //really just excellent code in here + try { + champ = champ.toLowerCase(); + champ = champ.replace("\"", ""); + + String url = "https://na.op.gg/champion/" + champ + "/statistics/"; + + //Document doc = Jsoup.connect("https://na.op.gg/champion/poppy/statistics/top").get(); + + Document doc = Jsoup.connect(url).get(); + System.out.println(url); + System.out.println(champ); + + + Elements runes = doc.getElementsByClass("tabItem ChampionKeystoneRune-1"); + //gets the first table of runes + + Element selected = runes.first(); + + Elements keystone = selected.getElementsByClass("perk-page__item perk-page__item--keystone perk-page__item--active"); + + Element realKeystone = keystone.first().getElementsByClass("perk-page__image").first(); + String[] keyStoneName = realKeystone.html().split(">"); + //System.out.println(keyStoneName[1].split("<")[0]); + //good regex - rewrite later + + runeNames.add(keyStoneName[1].split("<")[0]); + + Elements a = selected.getElementsByClass("perk-page__item perk-page__item--active"); + //also need to grab secondary tree + + Element first = a.get(0); + Element second = a.get(1); + Element third = a.get(2); + + Elements minorRunes = new Elements(first, second, third); + + for (Element ele : minorRunes) { + Element realMinor = ele.getElementsByClass("perk-page__image").first(); + String[] minorName = realMinor.html().split(">"); + //System.out.println(keyStoneName[1].split("<")[0]); + //good regex - rewrite later + + runeNames.add(minorName[1].split("<")[0]); + + } + + System.out.println(runeNames); + + //now to get secondary runes ... + Elements secondary = selected.getElementsByClass("perk-page__item perk-page__item--active"); + + secondary.remove(3); + secondary.remove(2); + + for (Element ele : secondary) { + Element realMinor = ele.getElementsByClass("perk-page__image").first(); + String[] minorName = realMinor.html().split(">"); + //System.out.println(keyStoneName[1].split("<")[0]); + //good regex - rewrite later + + runeNames.add(minorName[1].split("<")[0]); + } + + System.out.println(runeNames); + + //and now, the miniperk things + Elements tertiary = selected.getElementsByClass("active tip"); + + tertiary.remove(5); + tertiary.remove(4); + tertiary.remove(3); + + for (Element ele : tertiary) { + Elements active = ele.getElementsByClass("active tip"); + String finallyName = active.toString().split("")[1].split("")[0]; + + runeNames.add(finallyName); + + } + + System.out.println(runeNames); + + + } catch ( + IOException e) { + e.printStackTrace(); + } + + + return runeNames; + } + +} diff --git a/src/main/java/org/example/runes/RunepageStore.java b/src/main/java/org/example/runes/RunepageStore.java index 5d724cb..82cf733 100644 --- a/src/main/java/org/example/runes/RunepageStore.java +++ b/src/main/java/org/example/runes/RunepageStore.java @@ -24,6 +24,12 @@ public void loadRunes() { quints rune family ids name + + precision: 8000 + domination: 8100 + sorcery: 8200 + inspiration: 8300 + resolve: 8400 */ Gson gson = new Gson(); diff --git a/src/test/java/org/example/AppTest.java b/src/test/java/org/example/AppTest.java index 2afa11e..7a6115f 100644 --- a/src/test/java/org/example/AppTest.java +++ b/src/test/java/org/example/AppTest.java @@ -3,17 +3,21 @@ import static org.junit.Assert.assertTrue; import com.google.gson.*; +import org.jsoup.Jsoup; +import org.jsoup.nodes.Document; +import org.jsoup.nodes.Element; +import org.jsoup.select.Elements; import org.junit.Ignore; import org.junit.Test; import java.io.File; import java.io.FileNotFoundException; +import java.io.IOException; import java.lang.reflect.Type; -import java.util.HashMap; -import java.util.Map; -import java.util.Scanner; -import java.util.Set; +import java.sql.SQLOutput; +import java.util.*; import java.util.function.Consumer; +import java.util.jar.JarOutputStream; /** * Unit test for simple App. @@ -22,12 +26,12 @@ public class AppTest { /** * Rigorous Test :-) */ - @Test + @Ignore public void shouldAnswerWithTrue() { assertTrue(true); } - @Test + @Ignore public void getChampNames() { Gson gson = new Gson(); HashMap champNames = new HashMap<>(); @@ -53,7 +57,7 @@ public void getChampNames() { Set> champSet = champsArray.entrySet(); HashMap keyChampNamePairs = new HashMap(); - for(Map.Entry ele : champSet){ + for (Map.Entry ele : champSet) { //ele = each entry, which is strucutred as a key/value of JsonObject vals = (JsonObject) ele.getValue(); System.out.println(vals.get("name") + " " + vals.get("key")); @@ -64,7 +68,106 @@ public void getChampNames() { } + } + + @Test + public void scrapeRunes() { + /* + urls structured like this: + https://na.op.gg/champion/poppy/statistics/top + + if you remove role, defaults to most common one: ie - + https://na.op.gg/champion/poppy/statistics > top runes appear first + */ + + //really just excellent code in here + try { + ArrayList runeNames = new ArrayList<>(); + + String champ = "aatrox"; + champ = champ.toLowerCase(); + + String url = "https://na.op.gg/champion/" + champ + "/statistics/"; + + //Document doc = Jsoup.connect("https://na.op.gg/champion/poppy/statistics/top").get(); + + Document doc = Jsoup.connect(url).get(); + + + Elements runes = doc.getElementsByClass("tabItem ChampionKeystoneRune-1"); + //gets the first table of runes + + Element selected = runes.first(); + + Elements keystone = selected.getElementsByClass("perk-page__item perk-page__item--keystone perk-page__item--active"); + + Element realKeystone = keystone.first().getElementsByClass("perk-page__image").first(); + String[] keyStoneName = realKeystone.html().split(">"); + //System.out.println(keyStoneName[1].split("<")[0]); + //good regex - rewrite later + + runeNames.add(keyStoneName[1].split("<")[0]); + + Elements a = selected.getElementsByClass("perk-page__item perk-page__item--active"); + //also need to grab secondary tree + + Element first = a.get(0); + Element second = a.get(1); + Element third = a.get(2); + + Elements minorRunes = new Elements(first, second, third); + for (Element ele : minorRunes) { + Element realMinor = ele.getElementsByClass("perk-page__image").first(); + String[] minorName = realMinor.html().split(">"); + //System.out.println(keyStoneName[1].split("<")[0]); + //good regex - rewrite later + + runeNames.add(minorName[1].split("<")[0]); + + } + + System.out.println(runeNames); + + //now to get secondary runes ... + Elements secondary = selected.getElementsByClass("perk-page__item perk-page__item--active"); + + secondary.remove(3); + secondary.remove(2); + + for (Element ele : secondary) { + Element realMinor = ele.getElementsByClass("perk-page__image").first(); + String[] minorName = realMinor.html().split(">"); + //System.out.println(keyStoneName[1].split("<")[0]); + //good regex - rewrite later + + runeNames.add(minorName[1].split("<")[0]); + } + + System.out.println(runeNames); + + //and now, the miniperk things + Elements tertiary = selected.getElementsByClass("active tip"); + + tertiary.remove(5); + tertiary.remove(4); + tertiary.remove(3); + + for (Element ele : tertiary) { + Elements active = ele.getElementsByClass("active tip"); + String finallyName = active.toString().split("")[1].split("")[0]; + + runeNames.add(finallyName); + + } + + System.out.println(runeNames); + + + } catch ( + IOException e) { + e.printStackTrace(); + } } diff --git a/target/classes/org/example/App$1.class b/target/classes/org/example/App$1.class index ace663b..b54a8bf 100644 Binary files a/target/classes/org/example/App$1.class and b/target/classes/org/example/App$1.class differ diff --git a/target/classes/org/example/App.class b/target/classes/org/example/App.class index 1e515bd..7bd2763 100644 Binary files a/target/classes/org/example/App.class and b/target/classes/org/example/App.class differ diff --git a/target/classes/org/example/puller/RunePuller.class b/target/classes/org/example/puller/RunePuller.class new file mode 100644 index 0000000..898a4e4 Binary files /dev/null and b/target/classes/org/example/puller/RunePuller.class differ diff --git a/target/classes/org/example/runes/RunepageStore.class b/target/classes/org/example/runes/RunepageStore.class index 5025709..717b5e0 100644 Binary files a/target/classes/org/example/runes/RunepageStore.class and b/target/classes/org/example/runes/RunepageStore.class differ diff --git a/target/test-classes/org/example/AppTest.class b/target/test-classes/org/example/AppTest.class index 9837e95..65d8cb4 100644 Binary files a/target/test-classes/org/example/AppTest.class and b/target/test-classes/org/example/AppTest.class differ