Fix api rate limit
This commit is contained in:
@@ -25,16 +25,15 @@ public class APIFootballUpdater {
|
|||||||
|
|
||||||
public void updateFixtures(int league) {
|
public void updateFixtures(int league) {
|
||||||
String apiFootballUrl = "https://v2.api-football.com/fixtures/league/" + league + "?timezone=Europe/Berlin";
|
String apiFootballUrl = "https://v2.api-football.com/fixtures/league/" + league + "?timezone=Europe/Berlin";
|
||||||
|
S3Provider prov = new S3Provider();
|
||||||
try {
|
try {
|
||||||
String content = getRawData(apiFootballUrl);
|
String content = getRawData(apiFootballUrl);
|
||||||
S3Provider prov = new S3Provider();
|
|
||||||
prov.writeFixturesToS3(league, content);
|
prov.writeFixturesToS3(league, content);
|
||||||
} catch (Exception e) {
|
} 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 {
|
try {
|
||||||
Thread.sleep(1000 * 60);
|
Thread.sleep(1000 * 60);
|
||||||
String content = getRawData(apiFootballUrl);
|
String content = getRawData(apiFootballUrl);
|
||||||
S3Provider prov = new S3Provider();
|
|
||||||
prov.writeFixturesToS3(league, content);
|
prov.writeFixturesToS3(league, content);
|
||||||
} catch (InterruptedException interruptedException) {
|
} catch (InterruptedException interruptedException) {
|
||||||
interruptedException.printStackTrace();
|
interruptedException.printStackTrace();
|
||||||
@@ -51,6 +50,11 @@ public class APIFootballUpdater {
|
|||||||
HashSet<Integer> leagues = getLeagues(season);
|
HashSet<Integer> leagues = getLeagues(season);
|
||||||
for (Integer league : leagues) {
|
for (Integer league : leagues) {
|
||||||
updateFixtures(league);
|
updateFixtures(league);
|
||||||
|
try {
|
||||||
|
Thread.sleep(1000*6);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,21 +62,25 @@ public class APIFootballUpdater {
|
|||||||
HashSet<Integer> leagues = getLeagues(season);
|
HashSet<Integer> leagues = getLeagues(season);
|
||||||
for (Integer league : leagues) {
|
for (Integer league : leagues) {
|
||||||
updateRounds(league);
|
updateRounds(league);
|
||||||
|
try {
|
||||||
|
Thread.sleep(1000*6);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateRounds(int league) {
|
public void updateRounds(int league) {
|
||||||
String apiFootballUrl = "https://v2.api-football.com/fixtures/rounds/" + league;
|
String apiFootballUrl = "https://v2.api-football.com/fixtures/rounds/" + league;
|
||||||
|
S3Provider prov = new S3Provider();
|
||||||
try {
|
try {
|
||||||
String content = getRawData(apiFootballUrl);
|
String content = getRawData(apiFootballUrl);
|
||||||
S3Provider prov = new S3Provider();
|
|
||||||
prov.writeRoundsToS3(league, content);
|
prov.writeRoundsToS3(league, content);
|
||||||
} catch (Exception e) {
|
} 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 {
|
try {
|
||||||
Thread.sleep(1000 * 60);
|
Thread.sleep(1000 * 60);
|
||||||
String content = getRawData(apiFootballUrl);
|
String content = getRawData(apiFootballUrl);
|
||||||
S3Provider prov = new S3Provider();
|
|
||||||
prov.writeRoundsToS3(league, content);
|
prov.writeRoundsToS3(league, content);
|
||||||
} catch (InterruptedException interruptedException) {
|
} catch (InterruptedException interruptedException) {
|
||||||
interruptedException.printStackTrace();
|
interruptedException.printStackTrace();
|
||||||
@@ -117,7 +125,7 @@ public class APIFootballUpdater {
|
|||||||
while (true) {
|
while (true) {
|
||||||
try {
|
try {
|
||||||
line = rd.readLine();
|
line = rd.readLine();
|
||||||
} catch (IOException e) {
|
} catch (Exception e) {
|
||||||
/* TODO */
|
/* TODO */
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user