Last active
August 29, 2015 14:13
-
-
Save ksahnine/1f9f2c0839a46d19026b to your computer and use it in GitHub Desktop.
Dropwizard - Resource
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Imports | |
@Path("/trafic-ratp") | |
@Produces(MediaType.APPLICATION_JSON) | |
public class TraficRatpResource { | |
private final String urlRatp; | |
public TraficRatpResource(String urlRatp) { | |
this.urlRatp = urlRatp; | |
} | |
@GET | |
@Timed | |
@Path("/metro/{ligne: [0-9]{1,2}[b]{0,1}}/{station}/{sens: [A|R]}") | |
public ArrayList<Passage> metro(@PathParam("ligne") String ligne, | |
@PathParam("station") String station, | |
@PathParam("sens") String sens) throws IOException { | |
ArrayList<Passage> prochainsPassages = new ArrayList<Passage>(); | |
// web scraping | |
String url = urlRatp + "/" + station + "/" + ligne + "/" + sens; | |
Document doc = Jsoup.connect(url).get(); | |
Elements resultatBrut = doc.select("#prochains_passages fieldset table tr"); // Enregistrements du tableau des prochains passages | |
for (Element e : resultatBrut) { | |
if ( e.childNodeSize() < 4 ) | |
continue; | |
if ( e.child(0).tagName().equals("th") ) | |
continue; | |
String direction = e.child(0).text(); | |
String attente = e.child(1).text(); | |
prochainsPassages.add( new Passage(direction, attente) ); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment