Skip to content

Commit 20d9dc5

Browse files
committed
👽 Code update due to website changes
1 parent 002abaf commit 20d9dc5

File tree

3 files changed

+17
-22
lines changed

3 files changed

+17
-22
lines changed

src/com/github/parsad23/motogpapi/reader/ChampionshipStandingsReader.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ private static JsonArray getJSONArrayStandings(Category category, String url) th
4848
JsonArray result;
4949

5050
try {
51-
String refer = URLGenerator.base_url + "series/" + category.toString().toLowerCase();
52-
result = (JsonParser.parseString(JsonReader.readJsonFromUrl(url, refer, URLGenerator.base_url)).getAsJsonObject()).getAsJsonArray("standings");
51+
String referer = URLGenerator.base_url + "results/" + category.toString().toLowerCase();
52+
result = (JsonParser.parseString(JsonReader.readJsonFromUrl(url, referer, URLGenerator.base_url)).getAsJsonObject()).getAsJsonArray("standings");
5353

5454
} catch (IOException e) {
5555
throw new DataNotAvailableException("The requested standings do not exist or are not available");

src/com/github/parsad23/motogpapi/reader/JsonReader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public static String readJsonFromUrl(String url, String refererUrl, String origi
1818
URL obj = new URL(url);
1919
HttpURLConnection con = (HttpURLConnection)obj.openConnection();
2020

21-
con.setRequestProperty("User-Agent", " Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:75.0) Gecko/20100101 Firefox/75.0");
21+
con.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:89.0) Gecko/20100101 Firefox/89.0");
2222
con.setRequestProperty("Referer", refererUrl);
2323
con.setRequestProperty("Origin", originUrl);
2424
// con.setRequestProperty("Accept", "*/*");

src/com/github/parsad23/motogpapi/reader/URLGenerator.java

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,42 +18,30 @@ class URLGenerator {
1818
protected static final String base_url = "https://results.motorsportstats.com/";
1919

2020
protected static String getRidersChampionshipURL(Category category, int year){
21-
if (category == Category.MotoGP)
22-
return url_json_seasons + year + "-" + category.toString().toLowerCase() + "/standings/drivers/";
23-
return url_json_seasons + category.toString().toLowerCase() + "-" + year + "/standings/drivers/";
21+
return getStandingsURL(category, year) + "drivers/";
2422
}
2523

2624
protected static String getConstructorsChampionshipURL(Category category, int year){
27-
if (category == Category.MotoGP)
28-
return url_json_seasons + year + "-" + category.toString().toLowerCase() + "/standings/constructors/";
29-
return url_json_seasons + category.toString().toLowerCase() + "-" + year + "/standings/constructors/";
25+
return getStandingsURL(category, year) + "constructors/";
3026
}
3127

3228
protected static String getTeamsChampionshipURL(Category category, int year){
33-
if (category == Category.MotoGP)
34-
return url_json_seasons + year + "-" + category.toString().toLowerCase() + "/standings/teams/";
35-
return url_json_seasons + category.toString().toLowerCase() + "-" + year + "/standings/teams/";
29+
return getStandingsURL(category, year) + "teams/";
3630
}
3731

3832
protected static String getRidersChampionshipURL(Category category, int year, int raceNumber, String raceCode) throws DataNotAvailableException {
3933
String eventCode = getEventCode(category, year, raceNumber, raceCode);
40-
if (category == Category.MotoGP)
41-
return url_json_seasons + year + "-" + category.toString().toLowerCase() + "/standings/drivers/?eventSlug="+eventCode;
42-
return url_json_seasons + category.toString().toLowerCase() + "-" + year + "/standings/drivers/?eventSlug="+eventCode;
34+
return getStandingsURL(category, year) + "drivers/?eventSlug="+eventCode;
4335
}
4436

4537
protected static String getConstructorsChampionshipURL(Category category, int year, int raceNumber, String raceCode) throws DataNotAvailableException{
4638
String eventCode = getEventCode(category, year, raceNumber, raceCode);
47-
if (category == Category.MotoGP)
48-
return url_json_seasons + year + "-" + category.toString().toLowerCase() + "/standings/constructors/?eventSlug="+eventCode;
49-
return url_json_seasons + category.toString().toLowerCase() + "-" + year + "/standings/constructors/?eventSlug="+eventCode;
39+
return getStandingsURL(category, year) + "constructors/?eventSlug="+eventCode;
5040
}
5141

5242
protected static String getTeamsChampionshipURL(Category category, int year, int raceNumber, String raceCode) throws DataNotAvailableException {
5343
String eventCode = getEventCode(category, year, raceNumber, raceCode);
54-
if (category == Category.MotoGP)
55-
return url_json_seasons + year + "-" + category.toString().toLowerCase() + "/standings/teams/?eventSlug="+eventCode;
56-
return url_json_seasons + category.toString().toLowerCase() + "-" + year + "/standings/teams/?eventSlug="+eventCode;
44+
return getStandingsURL(category, year) + "teams/?eventSlug="+eventCode;
5745
}
5846

5947
protected static String getSessionResultsPageURL(Category category, int year, int raceNumber, String raceCode) throws DataNotAvailableException {
@@ -102,7 +90,7 @@ protected static String getEventCode(Category category, int year, int raceNumber
10290
String grandprix = "";
10391

10492
if (category == Category.MotoGP)
105-
url = url_json_seasons + year + "-" + category.toString().toLowerCase() + "/races/";
93+
url = url_json_seasons + year + "-world-championship-2" + "/races/";
10694
else
10795
url = url_json_seasons + category.toString().toLowerCase() + "-" + year + "/races/";
10896
String referer = base_url + "series/" + category.toString().toLowerCase() + "/season/" + year + "/";
@@ -135,4 +123,11 @@ protected static String getEventCode(Category category, int year, int raceNumber
135123
}
136124
return grandprix;
137125
}
126+
127+
private static String getStandingsURL(Category category, int year) {
128+
if (category == Category.MotoGP)
129+
return url_json_seasons + year + "-" + "world-championship-2" + "/standings/";
130+
return url_json_seasons + category.toString().toLowerCase() + "-" + year + "/standings/";
131+
}
132+
138133
}

0 commit comments

Comments
 (0)