1+ import java .io .BufferedReader ;
2+ import java .io .FileWriter ;
3+ import java .io .InputStreamReader ;
4+ import java .io .IOException ;
5+ import java .util .Scanner ;
6+
17public class Main {
28 public static void main (String [] args ) {
3- System .out .println ("Hello world!" );
9+ Scanner scanner = new Scanner (System .in ); // Create a Scanner object
10+ System .out .println ("Enter Studiengang:" );
11+ String studiengang = scanner .nextLine (); // Read user input
12+
13+ // Construct the curl command using the user input
14+ String [] curlCommand = {
15+ "curl" ,
16+ "-X" , "GET" ,
17+ "https://raumzeit.hka-iwi.de/api/v1/timetables/public/" + studiengang ,
18+ "-H" , "accept: text/calendar"
19+ };
20+
21+ try {
22+ // Execute the curl command using ProcessBuilder
23+ ProcessBuilder processBuilder = new ProcessBuilder (curlCommand );
24+ Process process = processBuilder .start ();
25+
26+ // Read the output of the curl command
27+ BufferedReader reader = new BufferedReader (new InputStreamReader (process .getInputStream ()));
28+ StringBuilder output = new StringBuilder ();
29+ String line ;
30+
31+ while ((line = reader .readLine ()) != null ) {
32+ output .append (line ).append ("\n " );
33+ }
34+
35+ // Wait for the process to complete
36+ int exitCode = process .waitFor ();
37+ if (exitCode == 0 ) {
38+ // Write the API response to a .ics file
39+ String fileName = studiengang + ".ics" ;
40+ try (FileWriter fileWriter = new FileWriter (fileName )) {
41+ fileWriter .write (output .toString ());
42+ System .out .println ("API response saved to " + fileName );
43+ }
44+ } else {
45+ System .err .println ("Error: API call failed with exit code " + exitCode );
46+ }
47+
48+ } catch (IOException | InterruptedException e ) {
49+ e .printStackTrace (); // Handle any exceptions
50+ }
451 }
552}
0 commit comments