summaryrefslogtreecommitdiffstats
path: root/skripti
diff options
context:
space:
mode:
authorAnton Luka Šijanec <anton@sijanec.eu>2024-02-02 12:49:38 +0100
committerAnton Luka Šijanec <anton@sijanec.eu>2024-02-02 12:49:38 +0100
commit53b31c6ea98363871c7c6bdb8e662ad825e3f47a (patch)
treeafb56424b413287bb9189a014475286bf06dc706 /skripti
parentla2kol (diff)
downloadr-53b31c6ea98363871c7c6bdb8e662ad825e3f47a.tar
r-53b31c6ea98363871c7c6bdb8e662ad825e3f47a.tar.gz
r-53b31c6ea98363871c7c6bdb8e662ad825e3f47a.tar.bz2
r-53b31c6ea98363871c7c6bdb8e662ad825e3f47a.tar.lz
r-53b31c6ea98363871c7c6bdb8e662ad825e3f47a.tar.xz
r-53b31c6ea98363871c7c6bdb8e662ad825e3f47a.tar.zst
r-53b31c6ea98363871c7c6bdb8e662ad825e3f47a.zip
Diffstat (limited to 'skripti')
-rwxr-xr-xskripti/poprbot.py77
1 files changed, 77 insertions, 0 deletions
diff --git a/skripti/poprbot.py b/skripti/poprbot.py
new file mode 100755
index 0000000..c10fdbf
--- /dev/null
+++ b/skripti/poprbot.py
@@ -0,0 +1,77 @@
+#!/usr/bin/python3
+from sys import argv
+from os import getenv
+import requests
+import json
+from datetime import datetime
+from time import sleep
+from bs4 import BeautifulSoup
+popr = "https://popr.uni-lj.si/"
+def prijavi_se(s, event, slotid):
+ form = BeautifulSoup(s.get(popr + "student/events.html?page=booking&id=14564&slotId=44840&bookingAction=BOOK").text, features="lxml").find("form")
+ dejta = "_eventId_book=Submit"
+ for inp in form.findAll("input"):
+ try:
+ dejta += "&" + inp.attrs["name"] + "=" + inp.attrs["value"]
+ except KeyError:
+ pass
+ s.post(popr + "student/events.html", data=dejta, headers={"Content-Type": "application/x-www-form-urlencoded"})
+def get_event(s, event):
+ jwt = s.get(popr + "api/user/token/refresh").text
+ s.headers.update({"Authorization": "Bearer " + jwt});
+ return json.loads(s.get(popr + "ext/svc/events-api-0-0/events/user/event/slots/" + event + "?locale=en").text)[0];
+def main():
+ if len(argv) < 2:
+ print("Prvi argument naj bo numerični ID dogodka.")
+ return
+ event = argv[1]
+ slot = None
+ if len(argv) >= 3:
+ slot = int(argv[2])
+ if getenv("JSESSIONID") == None:
+ print("Okoljska spremenljivka JSESSIONID naj vsebuje vrednost istoimenskega piškotka.")
+ return
+ s = requests.Session()
+ s.cookies.set("JSESSIONID", getenv("JSESSIONID"));
+ ev = get_event(s, event)
+ slotid = ev["slots"][0]["id"]
+ if len(ev["slots"]) > 1 and slot == None:
+ print("Za izbrani dogodek obstaja več slotov. V drugi argument bi morali napisati številko slota, začenši z 0. Sloti na voljo:");
+ for sl in range(len(ev["slots"])):
+ print(str(sl) + "\t" + ev["slots"][sl]["start"] + "-" + ev["slots"][sl]["end"] + "\t" + ev["slots"][sl]["location"]["name"])
+ return
+ if slot != None:
+ slotid = ev["slots"][slot]["id"]
+ else:
+ slot = 0
+ if "message" in ev["slots"][slot].keys() and "Booking not yet open" in ev["slots"][slot]["message"]:
+ ura = ev["slots"][slot]["message"].split(" ")[-1]
+ datum = ev["slots"][slot]["message"].split(" ")[-3]
+ kdaj = datetime(int(datum.split("-")[2]), ["Nul", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"].index(datum.split("-")[1]), int(datum.split("-")[0]), int(ura.split(":")[0]), int(ura.split(":")[1]))
+ print("Prijave na dogodek se odpro " + kdaj.ctime() + ". Do takrat čakam, nato pa bom snajpal prijavo.")
+ while True:
+ if (kdaj-datetime.now()).total_seconds() < 190:
+ break
+ ev2 = get_event(s, event);
+ if ev2 != ev:
+ print("NAPAKA! Dogodek se je spremenil!")
+ return
+ sleep(180)
+ sleep((kdaj-datetime.now()).total_seconds()-3)
+ while True:
+ prijavi_se(s, event, slotid)
+ if (kdaj-datetime.now()).total_seconds() < -3:
+ ev = get_event(s, event)
+ if ev["slots"][slot]["booked"] == True:
+ print("Prijavljeni ste.")
+ return
+ else:
+ print("NAPAKA! Niste prijavljeni.")
+ return
+ prijavi_se(s, event, slotid)
+ ev = get_event(s, event)
+ if ev["slots"][slot]["booked"] == True:
+ print("Prijavljeni ste.")
+ else:
+ print("NAPAKA! Niste prijavljeni.")
+main()