Skip to content
This repository has been archived by the owner on Jun 20, 2023. It is now read-only.

Commit

Permalink
Fixed single station information reloader
Browse files Browse the repository at this point in the history
  • Loading branch information
Fi0x committed Dec 1, 2022
1 parent 5c04415 commit d9b7c74
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 18 deletions.
23 changes: 14 additions & 9 deletions src/main/java/com/fi0x/edct/logic/cleanup/HTMLCleanup.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,33 @@ public class HTMLCleanup
{
public static ArrayList<Element> getStationTrades(String inputHTML)
{
//TODO: Adjust for new inara
ArrayList<Element> stationTrades = new ArrayList<>();

Document doc = Jsoup.parse(inputHTML);
Element mainContainer = doc.getElementsByClass("maincontainer").first();

Element mainconten1s = doc.getElementsByClass("maincontainer").first();
Elements mainContents = Objects.requireNonNull(mainContainer).getElementsByClass("maincontent0");
if(mainContents.size() == 0)
return null;

assert mainconten1s != null;
Elements mainblocks = mainconten1s.getElementsByClass("mainblock maintable");
if(mainblocks.size() == 0) return null;
Elements mainBlocks = Objects.requireNonNull(mainContents.first()).getElementsByClass("mainblock");
if(mainBlocks.size() == 0)
return null;

Elements tables = Objects.requireNonNull(mainblocks.first()).getElementsByTag("table");
if(tables.size() == 0) return null;
Elements tables = Objects.requireNonNull(mainBlocks.last()).getElementsByTag("table");
if(tables.size() == 0)
return null;

Elements bodies = Objects.requireNonNull(tables.first()).getElementsByTag("tbody");
if(bodies.size() == 0) return null;
if(bodies.size() == 0)
return null;

Elements rows = Objects.requireNonNull(bodies.first()).getElementsByTag("tr");

for(Element row : rows)
{
if(row.hasClass("subheader")) continue;
if(row.className().contains("subheader"))
continue;
stationTrades.add(row);
}

Expand Down
10 changes: 6 additions & 4 deletions src/main/java/com/fi0x/edct/logic/cleanup/INARACleanup.java
Original file line number Diff line number Diff line change
Expand Up @@ -161,16 +161,17 @@ public static ArrayList<TRADE> getCommodityTradesForStation(String inputHTML, St
ArrayList<TRADE> results = new ArrayList<>();

ArrayList<Element> stationCommodities = HTMLCleanup.getStationTrades(inputHTML);
if(stationCommodities == null) return results;
if(stationCommodities == null)
return results;

long currentMillis = System.currentTimeMillis();
for(Element commodity : stationCommodities)
{
Elements cols = commodity.getElementsByTag("td");
int inaraID = getIntFromString(Objects.requireNonNull(cols.get(0).getElementsByTag("a").first()).attr("href"));
int importPrice = getIntFromString(Objects.requireNonNull(cols.get(1).getElementsByTag("span").first()).ownText());
int exportPrice = getIntFromString(Objects.requireNonNull(cols.get(2).getElementsByTag("span").first()).ownText());
int demand = getIntFromString(cols.get(3).ownText());
int demand = getIntFromString(cols.get(2).ownText());
int exportPrice = getIntFromString(Objects.requireNonNull(cols.get(3).getElementsByTag("span").first()).ownText());
int supply = getIntFromString(cols.get(4).ownText());

STATION s = DBHandler.getStation(systemName, stationName);
Expand All @@ -182,8 +183,9 @@ public static ArrayList<TRADE> getCommodityTradesForStation(String inputHTML, St

private static int getIntFromString(String input)
{
String cleanString = input.replace("commodity", "").replace("/", "");
String cleanString = input.replace("elite/commodity", "").replace("/", "");
cleanString = cleanString.replace("-", "0").replace(",", "");
cleanString = cleanString.replace("Cr", "");

if(cleanString.equals("")) return 0;
return Integer.parseInt(cleanString);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public enum ENDPOINTS
Prices("https://inara.cz/commodities/", "GET", "pi1", "pi2", "pi3", "pi4", "pi5", "pi7", "pi8", "pi9", "pi10", "pi11", "pi12"),
StationSearch("https://inara.cz/elite/stations/", "GET", "search"),
StationInfo("https://inara.cz/elite/station/", "GET"),
StationMarket("https://inara.cz/elite/station-market/", "GET"),
EDSMCoordinates("https://www.edsm.net/api-v1/system", "GET", "systemName", "showCoordinates");

public final String url;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/fi0x/edct/logic/threads/EDDNHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ private void retrieveStationInterrupted(String outputString)
counter++;
try
{
html = InaraStation.getStationHtml(stationID);
html = InaraStation.getStationInfoHtml(stationID);
break;
} catch(HtmlConnectionException ignored)
{
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/com/fi0x/edct/logic/websites/InaraStation.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,18 @@ public static String getInaraStationID(String stationName, String systemName) th
return INARACleanup.getStationID(html, stationName, systemName);
}

public static String getStationHtml(String stationID) throws InterruptedException, HtmlConnectionException
public static String getStationInfoHtml(String stationID) throws InterruptedException, HtmlConnectionException
{
return RequestHandler.sendHTTPRequest(ENDPOINTS.StationInfo.url + stationID, ENDPOINTS.StationInfo.type, new HashMap<>());
}

public static void updateSingleStationTrades(String stationName, String systemName, TRADE tradeToUpdate)
{
//TODO: Update for new inara
String stationHTML = null;
try
{
String inaraID = getInaraStationID(stationName, systemName);
stationHTML = getStationHtml(inaraID);
stationHTML = RequestHandler.sendHTTPRequest(ENDPOINTS.StationMarket.url + inaraID, ENDPOINTS.StationMarket.type, new HashMap<>());
} catch(InterruptedException | HtmlConnectionException ignored)
{
}
Expand All @@ -56,7 +55,6 @@ public static void updateSingleStationTrades(String stationName, String systemNa
tradeToUpdate.EXPORT_PRICE = t.EXPORT_PRICE;
}
}

}
}

Expand Down

0 comments on commit d9b7c74

Please sign in to comment.