Skip to content

Commit

Permalink
traveltimes: debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
clezag committed Nov 11, 2024
1 parent 600d166 commit 77c7d7d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 23 deletions.
6 changes: 2 additions & 4 deletions data-collectors/traveltimes-a22/calls.http
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
@token = {{login.response.body.SubscribeResult.sessionId}}
POST {{host}}/token
Content-Type: application/json
User-Agent: NOI/A22TraveltimesConnector
User-Agent: NOI/A22TravelTimesConnector
Accept: */*

{
Expand All @@ -14,8 +14,6 @@ Accept: */*
"password": "{{$dotenv A22_CONNECTOR_PWD}}"
}
}


### De-authorize
DELETE {{host}}/token/{{token}}
User-Agent: NOI/A22TraveltimesConnector
Expand Down Expand Up @@ -45,7 +43,7 @@ Accept: */*
{
"request": {
"sessionId": "{{token}}",
"idtratto": "1840-1841",
"idtratto": "1867-1865",
"fromData": "/Date({{fromTs}}000+0000)/",
"toData": "/Date({{toTs}}999+0000)/"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,22 @@
*/
package it.bz.noi.a22.traveltimes;

import org.apache.commons.io.IOUtils;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.JSONValue;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.JSONValue;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* encapsulates the A22 API to query travel times
*/
Expand All @@ -44,7 +44,7 @@ public class Connector {
private static final String USER_AGENT = "NOI/A22TravelTimesConnector";
private static final int WS_CONN_TIMEOUT_MSEC = 30000;
private static final int WS_READ_TIMEOUT_MSEC = 1800000;
private static final boolean DEBUG = true;
private static final Logger LOG = LoggerFactory.getLogger(MainA22Traveltimes.class);

private String token = null;
private String url = null;
Expand Down Expand Up @@ -109,9 +109,7 @@ public Connector(String url, String username, String password) throws IOExceptio
this.url = url;
this.token = session_id;

if (DEBUG) {
System.err.println("authentication OK new token = " + token);
}
LOG.debug("authentication OK new token = " + token);

}

Expand Down Expand Up @@ -167,9 +165,7 @@ public void close() throws IOException {
throw new RuntimeException("de-authentication failure (de-authentication was not confirmed)");
}

if (DEBUG) {
System.err.println("de-authentication OK old token = " + token);
}
LOG.debug("de-authentication OK old token = " + token);

this.url = null;
this.token = null;
Expand Down Expand Up @@ -250,9 +246,7 @@ public List<HashMap<String, String>> getTravelTimeSegments() throws IOException
throw new RuntimeException("could not parse list of segments");
}

if (DEBUG) {
System.err.println("getTravelTimeSegments() OK: got " + output.size() + " segments");
}
LOG.debug("getTravelTimeSegments() OK: got " + output.size() + " segments");

return output;

Expand Down Expand Up @@ -285,6 +279,8 @@ public List<HashMap<String, String>> getTravelTimes(long fr, long to, String id)
// (see the comment "Reverse engineering the A22 time stamp format" at the end of the file)
String frTS = fr + "000+0000";
String toTS = to + "999+0000";

LOG.debug("Retrieving traveltimes for station %s with timestamps %s - %s", id, frTS, toTS);

// retrieve events
HttpURLConnection conn = (HttpURLConnection) (new URL(url + "/percorrenze/tempi")).openConnection();
Expand Down Expand Up @@ -353,9 +349,7 @@ public List<HashMap<String, String>> getTravelTimes(long fr, long to, String id)
throw new RuntimeException("could not parse list of travel times");
}

if (DEBUG) {
System.err.println("getTravelTimes() OK: got " + output.size() + " travel times");
}
LOG.debug("getTravelTimes() OK: got " + output.size() + " travel times");

return output;

Expand Down

0 comments on commit 77c7d7d

Please sign in to comment.