working rooms request
This commit is contained in:
parent
b54e97a99f
commit
8b94cac5ba
1 changed files with 23 additions and 10 deletions
33
Bot/Untis.go
33
Bot/Untis.go
|
|
@ -7,18 +7,20 @@ import (
|
|||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
|
||||
"github.com/joho/godotenv"
|
||||
)
|
||||
|
||||
type Params struct {
|
||||
Users string `json:"users"`
|
||||
Password string `json:"key"`
|
||||
Users string `json:"user"`
|
||||
Password string `json:"password"`
|
||||
Client string `json:"client"`
|
||||
}
|
||||
type getRooms struct {
|
||||
Id string `json:"id"`
|
||||
Method string `json:"method"`
|
||||
Params Params `json:"params"`
|
||||
Jsonrpc string `json:"jsonrpc:"`
|
||||
Id string `json:"id"`
|
||||
Method string `json:"method"`
|
||||
Params interface{} `json:"params"`
|
||||
Jsonrpc string `json:"jsonrpc"`
|
||||
}
|
||||
type Login struct {
|
||||
Id string `json:"id"`
|
||||
|
|
@ -42,6 +44,7 @@ var Password = os.Getenv("UNTIS_PASSWORD")
|
|||
var USERS = os.Getenv("UNTIS_USER")
|
||||
|
||||
func Main() {
|
||||
godotenv.Load("../.env")
|
||||
cookies, err := Auth()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
|
|
@ -70,13 +73,16 @@ func Auth() ([]*http.Cookie, error) {
|
|||
// Parse cookies from response
|
||||
cookies := LoginOut.Cookies()
|
||||
log.Println("Received cookies:", cookies)
|
||||
log.Println("Set-Cookie headers:", LoginOut.Header["Set-Cookie"])
|
||||
loginRespBody, _ := io.ReadAll(LoginOut.Body)
|
||||
log.Println("Login response body:", string(loginRespBody))
|
||||
return cookies, nil
|
||||
|
||||
}
|
||||
|
||||
func Rooms(cookies []*http.Cookie) {
|
||||
log.Println("Abrufen der Stunden")
|
||||
g := getRooms{"2023-05-06 15:44:22.215292", "getRooms", Params{}, "2.0"}
|
||||
//log.Println("Abrufen der Stunden")
|
||||
g := getRooms{"2023-05-06 15:44:22.215292", "getRooms", map[string]interface{}{}, "2.0"}
|
||||
roomsJson, err := json.Marshal(g)
|
||||
if err != nil {
|
||||
log.Fatalf("Error marshaling login data: %v", err)
|
||||
|
|
@ -89,12 +95,19 @@ func Rooms(cookies []*http.Cookie) {
|
|||
log.Fatalf("Error creatingrequest: %v", err)
|
||||
return
|
||||
}
|
||||
log.Println(prompt)
|
||||
//log.Println("prompt without extra header or cookie ", prompt)
|
||||
log.Println("Cookie: ", cookies)
|
||||
|
||||
prompt.Header.Set("Content-Type", "application/json")
|
||||
prompt.Header.Set("User-Agent", "Webuntis Test")
|
||||
|
||||
for _, cookie := range cookies {
|
||||
//if cookie.Name == "JSESSIONID" {
|
||||
prompt.AddCookie(cookie)
|
||||
log.Println("prompt ", prompt)
|
||||
log.Printf("Added JSESSIONID cookie: %s=%s", cookie.Name, cookie.Value)
|
||||
//}
|
||||
}
|
||||
log.Println("Request JSON:", string(roomsJson))
|
||||
out, err := http.DefaultClient.Do(prompt)
|
||||
if err != nil {
|
||||
log.Printf("Error during request: %v", err)
|
||||
|
|
|
|||
Loading…
Reference in a new issue