diff --git a/src/main/java/de/jeyp91/apifootball/APIFootballUpdater.java b/src/main/java/de/jeyp91/apifootball/APIFootballUpdater.java index ba7db85..7f8f9b5 100644 --- a/src/main/java/de/jeyp91/apifootball/APIFootballUpdater.java +++ b/src/main/java/de/jeyp91/apifootball/APIFootballUpdater.java @@ -25,16 +25,15 @@ public class APIFootballUpdater { public void updateFixtures(int league) { String apiFootballUrl = "https://v2.api-football.com/fixtures/league/" + league + "?timezone=Europe/Berlin"; + S3Provider prov = new S3Provider(); try { String content = getRawData(apiFootballUrl); - S3Provider prov = new S3Provider(); prov.writeFixturesToS3(league, content); } catch (Exception e) { - if(e.getMessage().endsWith("did not have any results with status: 'Too many requests. Your rate limit is 10 requests per minute.'")) { + if(e.getMessage().toLowerCase().contains("rate limit'")) { try { Thread.sleep(1000 * 60); String content = getRawData(apiFootballUrl); - S3Provider prov = new S3Provider(); prov.writeFixturesToS3(league, content); } catch (InterruptedException interruptedException) { interruptedException.printStackTrace(); @@ -51,6 +50,11 @@ public class APIFootballUpdater { HashSet leagues = getLeagues(season); for (Integer league : leagues) { updateFixtures(league); + try { + Thread.sleep(1000*6); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } } } @@ -58,21 +62,25 @@ public class APIFootballUpdater { HashSet leagues = getLeagues(season); for (Integer league : leagues) { updateRounds(league); + try { + Thread.sleep(1000*6); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } } } public void updateRounds(int league) { String apiFootballUrl = "https://v2.api-football.com/fixtures/rounds/" + league; + S3Provider prov = new S3Provider(); try { String content = getRawData(apiFootballUrl); - S3Provider prov = new S3Provider(); prov.writeRoundsToS3(league, content); } catch (Exception e) { - if(e.getMessage().endsWith("did not have any results with status: 'Too many requests. Your rate limit is 10 requests per minute.'")) { + if(e.getMessage().toLowerCase().contains("rate limit'")) { try { Thread.sleep(1000 * 60); String content = getRawData(apiFootballUrl); - S3Provider prov = new S3Provider(); prov.writeRoundsToS3(league, content); } catch (InterruptedException interruptedException) { interruptedException.printStackTrace(); @@ -117,7 +125,7 @@ public class APIFootballUpdater { while (true) { try { line = rd.readLine(); - } catch (IOException e) { + } catch (Exception e) { /* TODO */ e.printStackTrace(); }