Skip to content

Commit

Permalink
Enabled Showclix Strict Filtering, improved Showclix checking
Browse files Browse the repository at this point in the history
-Made Browser Socket read timeout 3100ms for Showclix API timeout of 3000ms
-Made ShowclixReader return null if unable to download events for Seller or Partner
-Made ShowclixReader filter events by event name, ignore non-PAX events
-Made Showclix Checker display [Error Connecting] if above change happens
-Labeled CheckShowclixEventPage output
-Enabled Showclix Strict Filtering in GUI and CLI
-Changed version to 3.0.3
  • Loading branch information
SunnyBat committed May 27, 2016
1 parent a538e45 commit f271012
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 105 deletions.
2 changes: 1 addition & 1 deletion src/com/github/sunnybat/paxchecker/PAXChecker.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
*/
public final class PAXChecker {

public static final String VERSION = "3.0.2";
public static final String VERSION = "3.0.3";
private static TwitterStreamer myStreamer; // TODO: Factor elsewhere?
private static LinkManager myLinkManager; // TODO: Factor elsewhere?

Expand Down
2 changes: 1 addition & 1 deletion src/com/github/sunnybat/paxchecker/browser/Browser.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public static HttpURLConnection setUpConnection(URL url) { // NOTE: getURL() met
HttpURLConnection httpCon = (HttpURLConnection) url.openConnection();
httpCon.addRequestProperty("User-Agent", "Mozilla/4.0");
httpCon.setConnectTimeout(5000);
httpCon.setReadTimeout(2000);
httpCon.setReadTimeout(3100); // Showclix API request throttling = 3 seconds
return httpCon;
} catch (Exception e) {
e.printStackTrace();
Expand Down
111 changes: 43 additions & 68 deletions src/com/github/sunnybat/paxchecker/browser/ShowclixReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,67 +89,31 @@ public String getNamedURL(String url) {
return url;
}

/**
* Checks whether or not the page associated with the given Showclix EventID is a PAX ticket page.
*
* @param showclixID The Showclix ID to check
* @return True if it is, false if not
*/
public boolean isPaxPage(int showclixID) {
return isPaxPage(EVENT_LINK_BASE + showclixID);
}

/**
* Checks whether or not the given URL is a PAX ticket page or a queue page. Note that this does NOT follow any redirects.
*
* @param link The URL to check
* @return True if it is, false if not
*/
public boolean isPaxPage(String link) { // CHECK: Move this (and strict filtering) to somewhere else?
try {
URLConnection connect = Browser.setUpConnection(new URL(link));
BufferedReader reader = new BufferedReader(new InputStreamReader(connect.getInputStream()));
String line;
while ((line = reader.readLine()) != null) {
line = line.toLowerCase();
DataTracker.addDataUsed(line.length());
if (line.contains("pax")) {
System.out.println("SR: Found PAX in page -- is PAX page.");
return true;
} else if (line.contains("queue")) {
int firstIndex = line.indexOf("queue");
if (firstIndex == line.indexOf("queuetime")) {
System.out.println("SR: Found queueTime on Showclix page -- ignoring");
line = line.substring(firstIndex + 9); // Skip "queueTime", check again
if (!line.contains("queue")) { // Queue not found, continue reading rest of page
continue;
}
}
if (strictFiltering) {
System.out.println("SR: Found queue in page, but strict filtering is enabled");
} else {
System.out.println("SR: Found queue in page -- is PAX page.");
return true;
}
}
}
} catch (IOException iOException) {
System.out.println("SR: IOException in isPaxPage() -- returning strictFiltering");
return !strictFiltering;
}
System.out.println("SR: Is not PAX page.");
return false;
}

/**
* Gets all relevant event URLs. These will not be sorted in any particular order.
*
* @return All relevant event URLs
*/
public Set<String> getAllEventURLs() {
Set<String> retSet = getAllSellerEventURLs(expoToCheck);
retSet.addAll(getAllPartnerEventURLs(expoToCheck));
retSet.addAll(getAllVenueEventURLs(expoToCheck));
Set<String> retSet = new TreeSet<>();
Set<String> sellerEvents = getAllSellerEventURLs(expoToCheck);
if (sellerEvents == null) {
System.out.println("SR: Error downloading Seller Event URLs");
return null;
}
retSet.addAll(sellerEvents);
Set<String> partnerEvents = getAllPartnerEventURLs(expoToCheck);
if (partnerEvents == null) {
System.out.println("SR: Error downloading Partner Event URLs");
return null;
}
retSet.addAll(partnerEvents);
Set<String> venueEvents = getAllVenueEventURLs(expoToCheck);
if (venueEvents == null) {
System.out.println("SR: Error downloading Partner Event URLs");
return null;
}
retSet.addAll(venueEvents);
return retSet;
}

Expand All @@ -173,19 +137,20 @@ private Set<String> getAllEventURLs(JSONObject obj) {
JSONObject jObj = (JSONObject) obj.get(eventID);
if (jObj.containsKey("event")) {
if (jObj.get("event") == null) {
if (strictFiltering) {
System.out.println("SR: Event " + eventID + " is null, strictFiltering, ignoring");
} else {
System.out.println("SR: Event " + eventID + " is null, !strictFiltering, adding");
retSet.add(EVENT_LINK_BASE + eventID);
System.out.println("SR: Event " + eventID + " is null, ignoring");
} else {
String eventName = jObj.get("event").toString().toLowerCase();
if (eventName.contains("pax")) {
System.out.println("SR: PAX event found: " + eventID + " (" + jObj.get("event") + ")");
if (!strictFiltering || eventName.contains(expoToCheck.toString().toLowerCase())) {
retSet.add(EVENT_LINK_BASE + eventID);
} else {
System.out.println("SR: Strict Filtering is on, ignoring");
}
}
} else if (jObj.get("event").toString().toLowerCase().contains("pax")) {
System.out.println("SR: SC: PAX event found: " + eventID + " (" + jObj.get("event") + ")");
retSet.add(EVENT_LINK_BASE + eventID);
} // else event is not PAX, ignoring
} else {
System.out.println("SR: Event " + eventID + " does not contain an event title -- adding");
retSet.add(EVENT_LINK_BASE + eventID);
System.out.println("SR: Event " + eventID + " does not contain an event title -- ignoring");
}
} else if (((String) obj.get(eventID)).equals("HIDDEN")) {
System.out.println("SR: Event " + eventID + " is currently hidden");
Expand All @@ -208,31 +173,40 @@ private Set<String> getAllEventURLs(JSONObject obj) {
private Set<String> getAllSellerEventURLs(int sellerID) {
try {
String jsonText = readJSONFromURL(new URL(API_LINK_BASE + API_EXTENSION_SELLER + sellerID + EVENTS_ATTRIBUTE_LINK));
if (jsonText == null) {
return null;
}
return parseEvents(jsonText);
} catch (IOException iOException) {
System.out.println("SR: ERROR connecting to Seller " + sellerID);
}
return new TreeSet<>();
return null;
}

private Set<String> getAllPartnerEventURLs(int partnerID) {
try {
String jsonText = readJSONFromURL(new URL(API_LINK_BASE + API_EXTENSION_PARTNER + partnerID + EVENTS_ATTRIBUTE_LINK));
if (jsonText == null) {
return null;
}
return parseEvents(jsonText);
} catch (IOException iOException) {
System.out.println("SR: Error connecting to Partner " + partnerID);
}
return new TreeSet<>();
return null;
}

private Set<String> getAllVenueEventURLs(int venueID) {
try {
String jsonText = readJSONFromURL(new URL(API_LINK_BASE + API_EXTENSION_VENUE + venueID + EVENTS_ATTRIBUTE_LINK));
if (jsonText == null) {
return null;
}
return parseEvents(jsonText);
} catch (IOException iOException) {
System.out.println("SR: ERROR connecting to Venue " + venueID);
}
return new TreeSet<>();
return null;
}

private Set<String> parseEvents(String jsonText) {
Expand Down Expand Up @@ -336,6 +310,7 @@ private static String readJSONFromURL(URL url) {
reader.close();
return build.toString();
} catch (IOException iOException) {
iOException.printStackTrace();
return null;
}
}
Expand Down
38 changes: 18 additions & 20 deletions src/com/github/sunnybat/paxchecker/check/CheckShowclix.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
public class CheckShowclix extends Check {

private Set<String> alreadyChecked = new TreeSet<>();
private String currentLink; // When new link found, this will not be null
private String currentLink; // Null until the API returns events found
private ShowclixReader showReader;

/**
Expand All @@ -26,9 +26,9 @@ public class CheckShowclix extends Check {
public CheckShowclix(Expo expo, boolean shouldFilterShowclix) {
super();
showReader = new ShowclixReader(expo);
//if (shouldFilterShowclix) {
if (shouldFilterShowclix) {
showReader.strictFilter();
//}
}
}

@Override
Expand All @@ -39,15 +39,21 @@ public synchronized void init(CheckerInfoOutput s, java.util.concurrent.Phaser c

@Override
public synchronized boolean ticketsFound() {
return currentLink != null; // currentLink is not null if a new link has been found
return currentLink != null && !currentLink.startsWith("["); // currentLink is not null if a new link has been found
}

@Override
public synchronized void updateLink() {
updateLink("[Checking]");
Set<String> allLinksFound = getLinks();
if (alreadyChecked.isEmpty()) { // In case there was no API connection before, we don't want to alert for ALL the events found
if (allLinksFound == null) {
updateLink("[Error Connecting]");
return;
}
if (currentLink == null) { // In case there was no API connection before, we don't want to alert for ALL the events found
System.out.println("currentLink is null, adding all links");
alreadyChecked.addAll(allLinksFound);
currentLink = "[No New Events]";
} else {
updateLinkFromSet(allLinksFound);
}
Expand All @@ -74,23 +80,15 @@ private void updateLinkFromSet(Set<String> allLinksFound) {
} else if (Browser.unshortenURL(temp2) == null) { // 404'd again
System.out.println("CS: URL " + link + " and updated URL " + temp2 + " unable to resolve -- checking again later");
continue;
} else {
if (!temp2.equalsIgnoreCase(link)) {
alreadyChecked.add(link); // So we don't check this URL again (every time)
link = temp2;
}
} else if (!temp2.equalsIgnoreCase(link)) {
alreadyChecked.add(link); // So we don't check this URL again (every time)
link = temp2;
}
}
if (!alreadyChecked.contains(link)) {
System.out.println("CS: Not checked: " + link);
/*if (showReader.isPaxPage(link)) {*/
currentLink = link;
System.out.println("CS: PAX page found: " + currentLink);
break;
/*} else {
System.out.println("CS: Link is not pax page. Ignoring.");
alreadyChecked.add(link);
}*/
currentLink = link;
System.out.println("CS: PAX page found: " + currentLink);
break;
}
}
}
Expand All @@ -109,7 +107,7 @@ public synchronized void reset() {
if (currentLink != null) {
System.out.println("CS: Adding " + currentLink + " to alreadyChecked");
alreadyChecked.add(currentLink);
currentLink = null;
currentLink = "[No New Events]";
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public synchronized final void updateLink() {
break; // Found a link, we're done
}
} catch (MalformedURLException mue) {
System.out.println("Invalid URL: " + url);
System.out.println("CSEP: Invalid URL: " + url);
}
}
updateLink(getLink());
Expand All @@ -61,21 +61,19 @@ private boolean testURL(URL connectTo) {
try {
conn = Browser.setUpConnection(connectTo);
if (conn == null) { // In case it fails to set up correctly
System.out.println("URLConnection failed to set up for " + connectTo);
System.out.println("CSEP: URLConnection failed to set up for " + connectTo);
return false;
}
if (conn.getResponseCode() >= 400 && conn.getResponseCode() < 500) { // getResponseCode() will throw IOE if unable to properly set up connection
if (conn.getResponseCode() != 404) { // I don't think it should ever be 404, but if it is, we don't need to report it
System.out.println("Unexpected error response code " + conn.getResponseCode());
System.out.println("CSEP: Unexpected error response code " + conn.getResponseCode());
}
return false;
} else if (conn.getResponseCode() >= 300 && conn.getResponseCode() < 400) { // Redirect, however it's probably going from HTTP
System.out.println("Location = " + conn.getHeaderField("Location")); // to HTTPS, which Java does not do for security
System.out.println("CSEP: Location = " + conn.getHeaderField("Location")); // to HTTPS, which Java does not do for security
return testURL(new URL(conn.getHeaderField("Location"))); // Will throw MalformedURLException if getHF() is null, we're catching this
} else if (conn.getResponseCode() >= 200 && conn.getResponseCode() < 300) {
if (conn.getResponseCode() != 200) {
System.out.println("Found :: URL = " + conn.getURL() + " :: Code = " + conn.getResponseCode());
}
System.out.println("CSEP: Found :: URL = " + conn.getURL() + " :: Code = " + conn.getResponseCode());
validPageURL = connectTo.toString();
return true;
} else {
Expand All @@ -84,10 +82,10 @@ private boolean testURL(URL connectTo) {
}
} catch (IOException ioe) {
if (conn != null) {
System.out.println("Unsure of URL " + conn.getURL() + " (" + connectTo + ")");
System.out.println("CSEP: Unsure of URL " + conn.getURL() + " (" + connectTo + ")");
ioe.printStackTrace();
} else {
System.out.println("Unable to find link from " + connectTo);
System.out.println("CSEP: Unable to find link from " + connectTo);
}
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions src/com/github/sunnybat/paxchecker/setup/SetupCLI.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ public void promptForSettings() {
checkPaxWebsite = isResponseYes(myScanner);
System.out.print("Check Showclix Website (Y/N): ");
checkShowclixWebsite = isResponseYes(myScanner);
//System.out.print("Filter Showclix Website (Y/N): ");
//filterShowclix = isResponseYes(myScanner);
System.out.print("Filter Showclix Website (Y/N): ");
filterShowclix = isResponseYes(myScanner);
System.out.print("Check Known Events (Y/N): ");
checkKnownEvents = isResponseYes(myScanner);
System.out.print("Check Twitter (Y/N): ");
Expand Down
2 changes: 0 additions & 2 deletions src/com/github/sunnybat/paxchecker/setup/SetupGUI.form
Original file line number Diff line number Diff line change
Expand Up @@ -480,10 +480,8 @@
</Container>
<Component class="javax.swing.JCheckBox" name="JCBFilterShowclix">
<Properties>
<Property name="selected" type="boolean" value="true"/>
<Property name="text" type="java.lang.String" value="Strict Filtering"/>
<Property name="toolTipText" type="java.lang.String" value="&lt;html&gt;&#xa;Enabling this will hopefully reduce the&lt;br&gt;&#xa;amount of false positives, however&lt;br&gt;&#xa;might also cause the PAXChecker to&lt;br&gt;&#xa;miss the queue. Use at your own risk.&#xa;&lt;/html&gt;"/>
<Property name="enabled" type="boolean" value="false"/>
</Properties>
</Component>
<Component class="javax.swing.JCheckBox" name="JCBTextTweets">
Expand Down
2 changes: 0 additions & 2 deletions src/com/github/sunnybat/paxchecker/setup/SetupGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -707,10 +707,8 @@ public void mouseClicked(java.awt.event.MouseEvent evt) {
.addComponent(jLabel6))
);

JCBFilterShowclix.setSelected(true);
JCBFilterShowclix.setText("Strict Filtering");
JCBFilterShowclix.setToolTipText("<html>\nEnabling this will hopefully reduce the<br>\namount of false positives, however<br>\nmight also cause the PAXChecker to<br>\nmiss the queue. Use at your own risk.\n</html>");
JCBFilterShowclix.setEnabled(false);

JCBTextTweets.setText("Text Tweets");
JCBTextTweets.setToolTipText("<html>\nSend a text to the given email address<br>\nif a link is found in a Tweet.If you receive<br>\nTweets directly from Twitter, this option<br>\nwill likely be redundant (and therefore not<br>\nrecommended).\n</html>");
Expand Down

0 comments on commit f271012

Please sign in to comment.