Skip to content

Commit

Permalink
let's start this
Browse files Browse the repository at this point in the history
  • Loading branch information
lbernhard95 committed Oct 30, 2024
1 parent 3f1d821 commit f3bb88b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
7 changes: 3 additions & 4 deletions lambda_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,18 @@ def start_new_poll(subscribed_emails) -> PollItem:
def schedule_next_schafkopf_event(emails: List[str], poll: PollItem) -> PollItem:
poll_website = bitpoll.get_website_from_poll_id(poll.running_poll_id)
print("Try to schedule next schafkopf event for:", poll_website)
page = bitpoll.get_poll_webpage(poll_id=poll.running_poll_id)
votes = bitpoll.collect_vote_dates(page)
voting_table = bitpoll.get_voting_table(poll_id=poll.running_poll_id)
votes = bitpoll.collect_vote_dates(voting_table)
best_vote = scheduler.find_best_date(votes)
print("Most promising vote:", best_vote)

if best_vote:
print("Found valid date, sending out invitation")
best_date = best_vote.date
# todo show "screenshot" of poll
gmail.send_schafkopf_meeting_invitation(
receivers=emails,
start=best_date,
bitpoll_link=poll_website,
bitpoll_link=poll_website
)
poll.event_scheduled_update(event_date=best_date)
return poll
Expand Down
14 changes: 8 additions & 6 deletions scheduler/bitpoll.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from datetime import datetime
from typing import List, Optional
from uuid import uuid4

import bs4
from pydantic import BaseModel, computed_field
import requests
from bs4 import BeautifulSoup
Expand Down Expand Up @@ -43,17 +45,17 @@ def attendance_probability(self) -> float:
@property
def participation_count(self) -> int:
return self.yes_count + self.no_count + self.probably_no_count + self.probably_yes_count



def get_poll_webpage(poll_id: str) -> BeautifulSoup:
def get_voting_table(poll_id: str) -> bs4.Tag:
rsp = requests.get(get_website_from_poll_id(poll_id))
return BeautifulSoup(rsp.text, features="html.parser")
page = BeautifulSoup(rsp.text, features="html.parser")
return page.find('table', id='poll')


def collect_vote_dates(poll_page: BeautifulSoup) -> List[VoteDate]:
dates = [date.get_text(strip=True) for date in poll_page.select("thead th.choice-group")]
details_row = poll_page.select("tfoot tr.print-only")[1]
def collect_vote_dates(table: bs4.Tag) -> List[VoteDate]:
dates = [date.get_text(strip=True) for date in table.select("thead th.choice-group")]
details_row = table.select("tfoot tr.print-only")[1]

all_votes = []
for i, cell in enumerate(details_row.select("td")):
Expand Down
5 changes: 5 additions & 0 deletions scripts/poll.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from scheduler import bitpoll

page = bitpoll.get_poll_webpage("23fd6020-cd54-4397-b4ff-f0ee748c7f4d")
table = bitpoll.get_voting_table(page)
print(table)

0 comments on commit f3bb88b

Please sign in to comment.