Skip to content

Commit

Permalink
added pretix functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
themrphantom committed Nov 4, 2024
1 parent 9bc11d4 commit 09b93c6
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 0 deletions.
6 changes: 6 additions & 0 deletions backend/TaskScheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,9 @@ def add_Daily_Task(self, task, *args) -> None:
schedule.every().day.at("00:01").do(task, args)
else:
schedule.every().day.at("00:01").do(task)

def add_5min_Task(self, task, *args) -> None:
if len(args) > 0:
schedule.every(5).minutes.do(task, args)
else:
schedule.every(5).minutes.do(task)
72 changes: 72 additions & 0 deletions backend/database/Queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,78 @@ def add_aliases_if_non_existend(self):

self.session.commit()

def get_checkin_status_from_pretix(self):
# Define the endpoint
endpoint = f"{util.pretix_url}/api/v1/organizers/{util.pretix_organizer}/events/{util.pretix_event}/checkinlists/{util.pretix_checkin_list_id}/positions/"
headers = {
"Authorization": f"Token {util.pretix_api_token}",
"Content-Type": "application/json"
}

try:
# Send the request
response = requests.get(endpoint, headers=headers)
response.raise_for_status() # Raise an error for unsuccessful requests

# Parse JSON response
data = response.json()

# Extract and print attendee name and check-in state
attendees = []

for position in data.get("results", []):
name = position.get("attendee_name", "No Name Provided")
checkin_state = position.get("checkins", [])

if len(checkin_state) > 0:
checkin_state = checkin_state[0].get(
"type", "exit") == "entry"
else:
checkin_state = False
attendees.append((name, checkin_state))

nextPage = data.get("next")
while nextPage is not None:
response = requests.get(nextPage, headers=headers)
response.raise_for_status()
data = response.json()
for position in data.get("results", []):
name = position.get("attendee_name", "No Name Provided")
checkin_state = position.get("checkins", [])

if len(checkin_state) > 0:
checkin_state = checkin_state[0].get(
"type", "exit") == "entry"
else:
checkin_state = False
attendees.append((name, checkin_state))
nextPage = data.get("next")

return attendees

except requests.exceptions.RequestException as e:
print("Error fetching check-in data:", e)
return []

def enable_disable_pretix_user(self):
print("Checking pretix check-in")
attendee_list = self.get_checkin_status_from_pretix()

for attendee in attendee_list:
name, checked_in = attendee
member: Member | None = self.session.query(
Member).filter_by(name=name.lower()).first()
if member is not None:
if checked_in:
self.change_user_visibility(member.id, visibility=False)
else:
self.change_user_visibility(member.id, visibility=True)
else:
print(f"User {name} not found in database")
# Add user to database
self.add_user(name, 0, util.standard_user_password,
name, hidden=not checked_in)

def add_token(self, token, member_id, time):
session: Session = self.session.query(
Session).filter_by(member_id=member_id).first()
Expand Down
3 changes: 3 additions & 0 deletions backend/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@

taskScheduler = TaskScheduler.TaskScheduler()
taskScheduler.add_Daily_Task(db.hide_inactive)
if util.pretix_url is not None:
db.enable_disable_pretix_user()
taskScheduler.add_5min_Task(db.enable_disable_pretix_user)
taskScheduler.start()


Expand Down
12 changes: 12 additions & 0 deletions backend/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,18 @@
OIDC_USER_NEEDS_VERIFICATION = os.environ.get(
"OIDC_USER_NEEDS_VERIFICATION")=="true" if os.environ.get("OIDC_USER_NEEDS_VERIFICATION") else True

pretix_url = os.environ.get("PRETIX_URL") if os.environ.get(
"PRETIX_URL") else None
pretix_checkin_list_id = os.environ.get("CHECKIN_LIST_ID") if os.environ.get(
"CHECKIN_LIST_ID") else None
pretix_organizer = os.environ.get("ORGANIZER") if os.environ.get(
"ORGANIZER") else None
pretix_event = os.environ.get("EVENT") if os.environ.get(
"EVENT") else None
pretix_api_token = os.environ.get("API_TOKEN") if os.environ.get(
"API_TOKEN") else None


tempfile_path = "tempfiles"
backup_file_name = "backup.json"

Expand Down

0 comments on commit 09b93c6

Please sign in to comment.