Giter Site home page Giter Site logo

warriorzz / untis4j Goto Github PK

View Code? Open in Web Editor NEW

This project forked from untisapi/untis4j

0.0 0.0 0.0 243 KB

A java API for webuntis

Home Page: https://bytedream.org/docs/untis4j/

License: GNU Lesser General Public License v3.0

Java 99.85% Kotlin 0.15%

untis4j's Introduction

untis4j - a java API for webuntis

Click here to get the latest version of the API (dependencies included)

CI badge Codacy Badge Download Badge

Introduction

untis4j is a rich java API for the webuntis timetable / schedule software and is inspired from the python webuntis api and another java webuntis api. It support almost all webuntis request and is easy to use. If a request method is missing, you can easily implement the method yourself with the Session.getCustomData(...) method.

Requirements

Installation

Just download the latest untis4j.jar file, implement it into your project and start coding :)

Gradle

settings.gradle.kts
sourceControl {
    gitRepository(java.net.URI("https://github.com/bytedream/untis4j.git")) {
        producesModule("org.bytedream:untis4j")
    }
}
build.gradle.kts
dependencies {
    implementation("org.bytedream:untis4j") {
        version {
            branch = "master"
        }
    }
}

Examples

To get an overview about all classes and methods, read the docs.

Note: For the Session.login(...) method a server and a school name is required. To gain these you have to go to webuntis.com, type in your school and choose it. Then you will be redirected to the untis login page. The url of this page is, for example https://example.webuntis.com/WebUntis/?school=myschool#/basic/main. The server is the beginning of the url https://example.webuntis.com and the school name is the parameter after the ?school=, in this case it is myschool

Simple timetable

public class Main {
    
    public static void main(String[] args) {
        try { 
            Session session = Session.login("your webuntis username", "your webuntis password", "https://example.webuntis.com", "myschool");  // create a new webuntis session

            // get the timetable and print every lesson
            Timetable timetable = session.getTimetableFromClassId(LocalDate.now(), LocalDate.now(), session.getInfos().getClassId());
            for (int i = 0; i < timetable.size(); i++) {
                System.out.println("Lesson " + (i+1) + ": " + timetable.get(i).getSubjects().toString());
            }

            // logout
            session.logout();
        } catch (LoginException e) {
            // this exception get thrown if something went wrong with Session.login
            System.out.println("Failed to login: " + e.getMessage());
        } catch (IOException e) {
            // if an error appears this get thrown
            e.printStackTrace();
        }
    }
}

Find / search a specific class

public class Main {
    
    public static void main(String[] args){
        try { 
            Session session = Session.login("your webuntis username", "your webuntis password", "https://example.webuntis.com", "myschool");  // creates a new webuntis session

            Classes classes = session.getClasses();

            // get a class by its id
            // findBy(...) methods only returns one result
            System.out.println(classes.findById(1234));

            // this prints all classes which contains 's' in their name.
            // searchBy(...) methods can return multiple results / matches
            for (Classes.ClassObject classObject : classes.searchByName("s")) {
                System.out.println(classObject);
            }

            // logout
            session.logout();
        } catch (LoginException e) {
            // this exception get thrown if something went wrong with Session.login
            System.out.println("Failed to login: " + e.getMessage());
        } catch (IOException e) {
            // if an error appears this get thrown
            e.printStackTrace();
        }
    }

}

Custom request

public class Main {

    public static void main(String[] args) {
        try { 
            Session session = Session.login("your webuntis username", "your webuntis password", "webuntis.grupet.at", "demo_inf");
            // creates a new webuntis session

            Response response = session.getCustomData("getAMethodThatIsNotImplemented");
            // requests the custom method
            if (response.isError()) {
                // you can easily check if the response contains an error
                return;
            } else {
                // get the response...
                JSONObject responseObject = response.getResponse();
                // ...and read it
                JSONObject result = responseObject.getJSONObject("result");

                System.out.println(result.toString());
            }

            // logout
            session.logout();
        } catch (LoginException e) {
            // this exception get thrown if something went wrong with Session.login
            System.out.println("Failed to login: " + e.getMessage());
        } catch (IOException e) {
            // if an error appears this get thrown
            e.printStackTrace();
        }
    }
}

Information

Caching

Caching allows to use saved request responses. The advantages of caching are the obviously faster answer when the same things are requested, that the server does not have to send as much data and in case of internet loss data can still be accessed. Caching is activated by default, but can use Session.useCache(...) to enable / disable it.

Building

If you want to build / compile this project yourself, the java: Compilation failed: internal java compiler error error may occur when using IntelliJ as your IDE. To fix this, go to File | Settings | Build, Execution, Deployment | Compiler | Java Compiler and change the compiler from Javac to Eclipse.

License

This project is licensed under the GNU Lesser General Public License v3.0 (LGPL-3.0) - see the LICENSE file for more details.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.