-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetTimesCali.java
112 lines (90 loc) · 4.12 KB
/
getTimesCali.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import java.io.*;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Date;
import java.text.SimpleDateFormat;
import java.util.TimerTask;
import java.util.Timer;
public class GetTimesCali {
public static void main(String[] args) {
int minutes = 5; // The delay in minutes
Timer timer = new Timer();
timer.schedule(new TimerTask() {
public void run() {
getTimes();
}
}, 0, 1000 * 60 * minutes);
}
public static void getTimes() {
String waitTime = "";
String rideType = "";
String rideName = "";
String[] rideTimes = new String[10];
String[] wantedRides = new String[] {"RadiatorSpringsRacers","Incredicoaster","SillySymphonySwings","GuardiansoftheGalaxy-Mission:BREAKOUT!","GrizzlyRiverRun","Soarin'AroundtheWorld","ToyStoryMidwayMania!","WEBSLINGERS:ASpider-ManAdventure","PixarPal-A-Round–Non-Swinging","PixarPal-A-Round-Swinging"};
try {
URL url = new URL("https://api.themeparks.wiki/preview/parks/DisneylandResortCaliforniaAdventure/waittime");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setRequestProperty("Accept", "application/json");
Date date = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("EEEE MM/dd HH:mm a");
String fullDate = formatter.format(date);
if (conn.getResponseCode() != 200) {
throw new RuntimeException("Failed : HTTP error code : "
+ conn.getResponseCode());
}
BufferedReader br = new BufferedReader(new InputStreamReader((conn.getInputStream())));
FileWriter csvWriter = new FileWriter("DisneyTimesCA0613.csv", true);
File newFile = new File("DisneyTimesCA0613.csv");
if (newFile.length() == 0) {
csvWriter.append("Date,Radiator Springs Racers,Incredicoaster,Silly Symphony Swings,Guardians of the Galaxy-Mission: BREAKOUT!,Grizzly River Run,Soarin' Around the World,Toy Story Midway Mania!,WEBSLINGERS: A Spider-Man Adventure,Pixar Pal-A-Round–Non-Swinging,Pixar Pal-A-Round-Swinging,\n");
}
String output;
while ((output = br.readLine()) != null) {
output = output.replaceAll("\\s", "");
output = output.replaceAll("\"", "");
output = output.replaceAll(",", "");
if (output.substring(0,1).equals("w")) {
if (output.substring(9).equals("null")) {
waitTime = "closed";
} else {
waitTime = output.substring(9) + " minutes";
}
} else if (output.substring(0,1).equals("n")) {
rideName = output.substring(5);
} else if (output.substring(0,1).equals("t")) {
rideType = output.substring(5);
}
if (rideType.equals("ATTRACTION") && isWanted(rideName, wantedRides)) {
for (int i = 0; i < wantedRides.length; i++) {
if (rideName.equals(wantedRides[i])) {
rideTimes[i] = waitTime;
}
}
rideType = "";
}
}
csvWriter.write(fullDate + ",");
for (int i = 0; i < rideTimes.length; i ++) {
csvWriter.write(rideTimes[i] + ",");
}
csvWriter.write("\n");
csvWriter.flush();
csvWriter.close();
conn.disconnect();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
public static boolean isWanted(String ride, String[] wantedRides) {
for (int i = 0; i < wantedRides.length; i++) {
if (ride.equals(wantedRides[i])) {
return true;
}
}
return false;
}
}