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

Commit

Permalink
Inara url fix (#108)
Browse files Browse the repository at this point in the history
* Fixed inara commodity id retrieval

* Fixed inara commodity price retrieval

* re-added error display in window

* Added missing commodity-ids

* Updated inara station id search

* Fixed eddn station data loading

* Updated version info
  • Loading branch information
Fi0x authored Nov 30, 2022
1 parent 6bcb6bf commit 93c01bc
Show file tree
Hide file tree
Showing 19 changed files with 182 additions and 107 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/target/
/.idea/
/Output/
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<groupId>com.fi0x.edct</groupId>
<artifactId>EliteDangerousCarrierTrader</artifactId>
<!-- //TODO: update version -->
<version>1.7.11.9</version>
<version>2.0.0.0</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
Expand Down Expand Up @@ -139,7 +139,7 @@
<dependency>
<groupId>io.github.Fi0x</groupId>
<artifactId>JavaLogger</artifactId>
<version>1.1.8</version>
<version>1.1.9</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
Expand Down Expand Up @@ -169,7 +169,7 @@
<dependency>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
<version>3.39.4.1</version>
<version>3.40.0.0</version>
</dependency>
<dependency>
<groupId>org.zeromq</groupId>
Expand Down
2 changes: 1 addition & 1 deletion setup.iss
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

; TODO: Update Version info
#define MyAppName "Elite Dangerous Carrier Trader"
#define MyAppVersion "1.7.11.9"
#define MyAppVersion "2.0.0.0"
#define MyAppPublisher "Fi0x"
#define MyAppURL "https://github.com/Fi0x/EDCT"
#define MyAppExeName "EDCT.exe"
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/fi0x/edct/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class Main
public static File reddit;
public static File discord;
//TODO: Update version information
public static final String version = "1.7.11.9";//All.GUI.Logic.Hotfix
public static final String version = "2.0.0.0";//All.GUI.Logic.Hotfix
public static final VersionType versionType = VersionType.INSTALLER;

public static void main(String[] args)
Expand Down Expand Up @@ -181,7 +181,7 @@ private static boolean createFileIfNotExists(File file, boolean isFile)
if(file.createNewFile()) return false;
} catch(IOException e)
{
Logger.log("Could not create file: " + file, LogName.ERROR, e, 997);
Logger.log("Could not create file: " + file, LogName.getError(997), e, 997);
System.exit(997);
}
} else return !file.mkdir();
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/fi0x/edct/gui/controller/Interaction.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ private void loadDatastorage()
storageController.setInteractionController(this);
} catch(IOException e)
{
Logger.log("Could not load Datastorage controller", LogName.ERROR, e, 999);
Logger.log("Could not load Datastorage controller", LogName.getError(999), e, 999);
return;
}

Expand All @@ -64,7 +64,7 @@ private void loadFilters()
filterController = loader.getController();
} catch(IOException e)
{
Logger.log("Could not load Filters controller", LogName.ERROR, e, 999);
Logger.log("Could not load Filters controller", LogName.getError(999), e, 999);
return;
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/fi0x/edct/gui/controller/Results.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ private void loadCommodity()

} catch(IOException e)
{
Logger.log("Could not load Commodity controller", LogName.ERROR, e, 999);
Logger.log("Could not load Commodity controller", LogName.getError(999), e, 999);
return;
}

Expand All @@ -92,7 +92,7 @@ private void loadStation(boolean isBuying)
}
} catch(IOException e)
{
Logger.log("Could not load Station controller", LogName.ERROR, e, 999);
Logger.log("Could not load Station controller", LogName.getError(999), e, 999);
return;
}

Expand All @@ -110,7 +110,7 @@ private void loadDetails()

} catch(IOException e)
{
Logger.log("Could not load Details controller", LogName.ERROR, e, 999);
Logger.log("Could not load Details controller", LogName.getError(999), e, 999);
return;
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/fi0x/edct/gui/controller/Station.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public void initialize(URL url, ResourceBundle resourceBundle)

if(text == null)
{
Logger.log("Something went wrong when creating a reddit String", LogName.ERROR, null, 992);
Logger.log("Something went wrong when creating a reddit String", LogName.getError(992), null, 992);
return;
}

Expand All @@ -104,7 +104,7 @@ public void initialize(URL url, ResourceBundle resourceBundle)

if(text == null)
{
Logger.log("Something went wrong when creating a discord String", LogName.ERROR, null, 992);
Logger.log("Something went wrong when creating a discord String", LogName.getError(992), null, 992);
return;
}

Expand Down
10 changes: 5 additions & 5 deletions src/main/java/com/fi0x/edct/gui/visual/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void start(Stage stage)
root = loader.load();
} catch(IOException e)
{
Logger.log("Could not load MainWindow controller", LogName.ERROR, e, 999);
Logger.log("Could not load MainWindow controller", LogName.getError(999), e, 999);
System.exit(999);
return;
}
Expand All @@ -57,7 +57,7 @@ public void start(Stage stage)

progressbar.setStage(primaryStage);

Logger.log("GUI loaded", LogName.VERBOSE);
Logger.log("GUI loaded", LogName.INFO);

Main.updater.start();
}
Expand Down Expand Up @@ -96,7 +96,7 @@ private void loadInfo(FXMLLoader parentLoader)
infoController = loader.getController();
} catch(IOException e)
{
Logger.log("Could not load ProgramInfo controller", LogName.ERROR, e, 999);
Logger.log("Could not load ProgramInfo controller", LogName.getError(999), e, 999);
return;
}

Expand All @@ -118,7 +118,7 @@ private void loadInteraction(FXMLLoader parentLoader)
interactionController.setMainController(parentLoader.getController());
} catch(IOException e)
{
Logger.log("Could not load Interaction controller", LogName.ERROR, e, 999);
Logger.log("Could not load Interaction controller", LogName.getError(999), e, 999);
System.exit(999);
return;
}
Expand All @@ -138,7 +138,7 @@ private void loadResults(FXMLLoader parentLoader)
resultsController.updateResultController(parentLoader.getController());
} catch(IOException e)
{
Logger.log("Could not load Results controller", LogName.ERROR, e, 999);
Logger.log("Could not load Results controller", LogName.getError(999), e, 999);
System.exit(999);
return;
}
Expand Down
11 changes: 10 additions & 1 deletion src/main/java/com/fi0x/edct/logging/LogName.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
package com.fi0x.edct.logging;

import com.fi0x.edct.gui.visual.MainWindow;
import javafx.application.Platform;

public enum LogName
{
VERBOSE,
INFO,
WARNING,
ERROR
ERROR;

public static LogName getError(int errorCode)
{
Platform.runLater(() -> MainWindow.getInstance().infoController.setError(errorCode));
return ERROR;
}
}
5 changes: 5 additions & 0 deletions src/main/java/com/fi0x/edct/logic/NameMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class NameMap
put("H.E. Suits", "hazardousenvironmentsuits");
put("Hostages", "hostage");
put("Occupied Escape Pod", "occupiedcryopod");
put("Damaged Escape Pod", "damagedescapepod");
put("Skimmer Components", "skimercomponents");
put("Agri-Medicines", "agriculturalmedicines");
put("Guardian Casket", "ancientcasket");
Expand Down Expand Up @@ -224,12 +225,16 @@ public class NameMap
add("thargoidtissuesampletype2");
add("thargoidtissuesampletype3");
add("thargoidtissuesampletype4");
add("thargoidtissuesampletype5");
add("thargoidgeneratortissuesample");
add("unknownartifact");
add("unknownartifact2");
add("unknownartifact3");
add("s6_tissuesample_cells");
add("s6_tissuesample_coenosarc");
add("s_tissuesample_cells");
add("ancientrelictg");
add("unocuppiedescapepod");
}
};

Expand Down
30 changes: 23 additions & 7 deletions src/main/java/com/fi0x/edct/logic/cleanup/EDDNCleanup.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.util.ArrayList;
import java.util.Objects;
Expand Down Expand Up @@ -99,9 +100,14 @@ public static PADSIZE getStationPad(String inputHTML)
PADSIZE padsize = PADSIZE.NONE;

Element details = HTMLCleanup.getStationDetails(inputHTML);
if(details == null) return null;

for(Element pair : details.getElementsByClass("itempaircontainer"))
if(details == null)
return null;
Element div = details.getElementsByTag("div").first();
if(div == null)
return null;
Elements pairs = div.getElementsByClass("itempaircontainer");

for(Element pair : pairs)
{
String pairText = pair.toString().toLowerCase();
if(pairText.contains("landing pad"))
Expand All @@ -121,9 +127,14 @@ public static STATIONTYPE getStationType(String inputHTML)
STATIONTYPE type = STATIONTYPE.UNKNOWN;

Element details = HTMLCleanup.getStationDetails(inputHTML);
if(details == null) return null;

for(Element pair : details.getElementsByClass("itempaircontainer"))
if(details == null)
return null;
Element div = details.getElementsByTag("div").first();
if(div == null)
return null;
Elements pairs = div.getElementsByClass("itempaircontainer");

for(Element pair : pairs)
{
if(pair.toString().toLowerCase().contains("station type"))
{
Expand All @@ -146,7 +157,12 @@ public static double getStarDistance(String inputHTML)
double starDistance = -1;

Element details = HTMLCleanup.getStationDetails(inputHTML);
if(details == null) return -1;
if(details == null)
return -1;
Element div = details.getElementsByTag("div").first();
if(div == null)
return -1;
Elements pairs = div.getElementsByClass("itempaircontainer");

for(Element pair : details.getElementsByClass("itempaircontainer"))
{
Expand Down
73 changes: 43 additions & 30 deletions src/main/java/com/fi0x/edct/logic/cleanup/HTMLCleanup.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,17 @@

public class HTMLCleanup
{
public static Element getStationDetails(String inputHTML)
{
Elements mainconten1s = getStationMaincontent1(inputHTML);
if(mainconten1s == null || mainconten1s.size() == 0) return null;

Elements mainblocks = Objects.requireNonNull(mainconten1s.first()).getElementsByClass("mainblock");
if(mainblocks.size() == 0) return null;

for(Element block : mainblocks)
{
String blockText = block.toString().toLowerCase();
if(blockText.contains("class=\"mainblock\"") && (blockText.contains("landing pad") || blockText.contains("station type") || blockText.contains("href=\"/station/")))
return block;
}
return null;
}

public static ArrayList<Element> getStationTrades(String inputHTML)
{
//TODO: Adjust for new inara
ArrayList<Element> stationTrades = new ArrayList<>();

Elements mainconten1s = getStationMaincontent1(inputHTML);
if(mainconten1s == null || mainconten1s.size() == 0) return null;
Document doc = Jsoup.parse(inputHTML);

Element mainconten1s = doc.getElementsByClass("maincontainer").first();

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

Elements tables = Objects.requireNonNull(mainblocks.first()).getElementsByTag("table");
Expand All @@ -54,22 +40,49 @@ public static ArrayList<Element> getStationTrades(String inputHTML)
return stationTrades;
}

private static Elements getStationMaincontent1(String inputHTML)
public static Element getStationDetails(String inputHTML)
{
Document doc = Jsoup.parse(inputHTML);

Elements mainContainers = doc.getElementsByClass("maincontainer");
if(mainContainers.size() == 0)
return null;
Elements mainContents = Objects.requireNonNull(mainContainers.first()).getElementsByClass("maincontent0");
if(mainContents.size() == 0)
return null;
Elements subContents = Objects.requireNonNull(mainContents.first()).getElementsByClass("subcontent0 smallgaps");
if(subContents.size() == 0)
return null;
Elements mainBlocks = Objects.requireNonNull(subContents.first()).getElementsByClass("mainblock illustrationleftsmall");
if(mainBlocks.size() == 0)
return null;
Elements columns = Objects.requireNonNull(mainBlocks.first()).getElementsByClass("incontent grid2columns columnseparator");
if(columns.size() == 0)
return null;

return Objects.requireNonNull(columns.first()).getElementsByTag("div").first();
}

public static Elements getStationNameAndSystem(String inputHTML)
{
Document doc = Jsoup.parse(inputHTML);

Elements maincons = doc.getElementsByClass("maincon");
if(maincons.size() == 0) return null;
Elements mainContainers = doc.getElementsByClass("maincontainer");
if(mainContainers.size() == 0)
return null;

Elements containermains = Objects.requireNonNull(maincons.first()).getElementsByClass("containermain");
if(containermains.size() == 0) return null;
Elements mainContents = Objects.requireNonNull(mainContainers.first()).getElementsByClass("maincontent1 fullwidth");
if(mainContents.size() == 0)
return null;

Elements maincontentcontainers = Objects.requireNonNull(containermains.first()).getElementsByClass("maincontentcontainer");
if(maincontentcontainers.size() == 0) return null;
Elements mainBlocks = Objects.requireNonNull(mainContents.first()).getElementsByClass("mainblock");
if(mainBlocks.size() == 0)
return null;

Elements mainconten1s = Objects.requireNonNull(maincontentcontainers.first()).getElementsByClass("maincontent1");
if(mainconten1s.size() == 0) return null;
Elements table = Objects.requireNonNull(mainBlocks.first()).getElementsByClass("incontentlist columns3");
if(table.size() == 0)
return null;

return mainconten1s;
return Objects.requireNonNull(table.first()).getElementsByTag("a");
}
}
Loading

0 comments on commit 93c01bc

Please sign in to comment.