Compare commits
No commits in common. "master" and "range" have entirely different histories.
|
@ -1,82 +0,0 @@
|
|||
#!/usr/bin/python3
|
||||
import datetime
|
||||
import email.message
|
||||
import smtplib
|
||||
|
||||
import psycopg
|
||||
|
||||
import config
|
||||
|
||||
min_distance = datetime.timedelta(minutes=60)
|
||||
|
||||
def simple_sum(meet_id, kind):
|
||||
q = \
|
||||
f"""
|
||||
select k.*, sum(preference) as preference
|
||||
from {kind} k join {kind}_vote v on k.id = v.{kind}
|
||||
where k.meet = %s
|
||||
group by k.id order by preference desc
|
||||
"""
|
||||
csr.execute(q, (meet_id,))
|
||||
return csr.fetchall()
|
||||
|
||||
db = psycopg.connect(dbname=config.dbname, user=config.dbuser)
|
||||
csr = db.cursor(row_factory=psycopg.rows.namedtuple_row)
|
||||
|
||||
csr.execute("select * from meet where active")
|
||||
for meet in csr.fetchall():
|
||||
|
||||
csr.execute(
|
||||
"""
|
||||
select distinct email, short
|
||||
from date_vote
|
||||
join date on date_vote.date = date.id
|
||||
join bod on date_vote.bod = bod.id
|
||||
where meet = %s
|
||||
order by email
|
||||
""",
|
||||
(meet.id,))
|
||||
voters = csr.fetchall()
|
||||
dates = simple_sum(meet.id, "date")
|
||||
times = simple_sum(meet.id, "time")
|
||||
places = simple_sum(meet.id, "place")
|
||||
|
||||
msg = "Aktueller Favorit:\n\n" \
|
||||
f" {dates[0].date}, {times[0].time}\n" \
|
||||
f" im {places[0].name}\n\n\n" \
|
||||
"Abgestimmt haben:\n\n"
|
||||
for v in voters:
|
||||
msg += f" * {v.email}\n"
|
||||
|
||||
csr.execute(
|
||||
"""
|
||||
select *, now() - ts as age
|
||||
from news
|
||||
where meet = %s
|
||||
order by ts desc
|
||||
limit 1
|
||||
""",
|
||||
(meet.id,))
|
||||
last_news = csr.fetchone()
|
||||
if not last_news or last_news.content != msg and last_news.age >= min_distance:
|
||||
print(msg)
|
||||
|
||||
csr.execute(
|
||||
"""
|
||||
insert into news(meet, ts, content) values(%s, now(), %s)
|
||||
returning id
|
||||
""",
|
||||
(meet.id, msg))
|
||||
new_news = csr.fetchone()
|
||||
db.commit()
|
||||
|
||||
emsg = email.message.EmailMessage()
|
||||
emsg["From"] ="noreply@hjp.at"
|
||||
emsg["To"] = ", ".join(v.email for v in voters)
|
||||
emsg["Subject"] = "Neuer Zwischenstand: " + meet.title
|
||||
emsg["Message-ID"] = f"<meeat.{new_news.id}@hjp.at>"
|
||||
if last_news:
|
||||
emsg["In-Reply-To"] = f"<meeat.{last_news.id}@hjp.at>"
|
||||
emsg.set_content(msg)
|
||||
mta = smtplib.SMTP(host="localhost")
|
||||
mta.send_message(emsg)
|
20
app.py
20
app.py
|
@ -31,22 +31,7 @@ def home():
|
|||
log.debug("session = %s", session)
|
||||
if "user" not in session:
|
||||
return redirect(url_for("register", target="/"))
|
||||
csr = get_cursor()
|
||||
csr.execute(
|
||||
"""
|
||||
select * from meet where id in (
|
||||
select meet from date_vote dv join date d on dv.date = d.id where bod = %(bod_id)s
|
||||
union
|
||||
select meet from time_vote tv join time t on tv.time = t.id where bod = %(bod_id)s
|
||||
union
|
||||
select meet from place_vote pv join place p on pv.place = p.id where bod = %(bod_id)s
|
||||
)
|
||||
order by id desc
|
||||
""",
|
||||
{"bod_id": session["user"]["id"]}
|
||||
)
|
||||
meets = csr.fetchall()
|
||||
return render_template("home.html", meets=meets)
|
||||
return render_template("home.html")
|
||||
|
||||
@app.route("/register", methods=["GET", "POST"])
|
||||
def register():
|
||||
|
@ -157,7 +142,6 @@ def vote(key):
|
|||
|
||||
@app.post("/vote/date")
|
||||
def vote_date():
|
||||
log.debug("user = %s", session["user"])
|
||||
log.debug("form = %s", request.form)
|
||||
meet_id, preferences = get_preferences("date")
|
||||
date_ids = list(preferences.keys())
|
||||
|
@ -227,7 +211,6 @@ def result_date(meet_id):
|
|||
|
||||
@app.post("/vote/time")
|
||||
def vote_time():
|
||||
log.debug("user = %s", session["user"])
|
||||
log.debug("form = %s", request.form)
|
||||
meet_id, preferences = get_preferences("time")
|
||||
time_ids = list(preferences.keys())
|
||||
|
@ -295,7 +278,6 @@ def result_time(meet_id):
|
|||
|
||||
@app.post("/vote/place")
|
||||
def vote_place():
|
||||
log.debug("user = %s", session["user"])
|
||||
log.debug("form = %s", request.form)
|
||||
meet_id, preferences = get_preferences("place")
|
||||
place_ids = list(preferences.keys())
|
||||
|
|
|
@ -2,7 +2,6 @@ table meet
|
|||
column meet id serial primary key
|
||||
column meet title text not null
|
||||
column meet key text unique
|
||||
column meet active boolean default true
|
||||
|
||||
table date
|
||||
column date id serial primary key
|
||||
|
@ -31,20 +30,14 @@ column bod keychange timestamptz default now()
|
|||
table date_vote
|
||||
column date_vote date int not null references date
|
||||
column date_vote bod int not null references bod
|
||||
column date_vote preference float4
|
||||
column date_vote preference float4 not null
|
||||
|
||||
table time_vote
|
||||
column time_vote time int not null references time
|
||||
column time_vote bod int not null references bod
|
||||
column time_vote preference float4
|
||||
column time_vote preference float4 not null
|
||||
|
||||
table place_vote
|
||||
column place_vote place int not null references place
|
||||
column place_vote bod int not null references bod
|
||||
column place_vote preference float4
|
||||
|
||||
table news
|
||||
column news id serial primary key
|
||||
column news meet int references meet not null
|
||||
column news ts timestamptz not null default now()
|
||||
column news content text not null
|
||||
column place_vote preference float4 not null
|
||||
|
|
4
new_meet
4
new_meet
|
@ -48,7 +48,3 @@ for place in meet["places"]:
|
|||
(place["name"], meet_id,)
|
||||
)
|
||||
db.commit()
|
||||
|
||||
csr.execute("select * from meet where id = %s", (meet_id,))
|
||||
r = csr.fetchone()
|
||||
print(r.id, r.key, r.title)
|
||||
|
|
|
@ -144,11 +144,7 @@ label {
|
|||
font-size: 1.5rem;
|
||||
}
|
||||
.emoji {
|
||||
font-size: clamp(1rem, 5vw, 2rem);
|
||||
}
|
||||
|
||||
.slider {
|
||||
display: flex;
|
||||
font-size: 2rem;
|
||||
}
|
||||
|
||||
table.matrix th {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{% for d in dates %}
|
||||
<div class="vote-item">
|
||||
<label for="date_{{d.id}}">{{ d.display or d.date }}</label>
|
||||
<div class="slider">
|
||||
<div>
|
||||
<span class="emoji">😞</span>
|
||||
<input type="range" name="date_{{d.id}}" value="{{d.preference}}">
|
||||
<span class="emoji">😀</span>
|
||||
|
|
|
@ -6,18 +6,14 @@
|
|||
</head>
|
||||
<body>
|
||||
<p>Hallo, {{ session.user.email }}!</p>
|
||||
|
||||
{% for meet in meets %}
|
||||
{% if loop.first %}
|
||||
<ul>
|
||||
{% endif %}
|
||||
<li><a href="{{url_for("vote", key=meet.key)}}">{{meet.title}}</a></li>
|
||||
{% if loop.last %}
|
||||
</ul>
|
||||
{% endif %}
|
||||
{% else %}
|
||||
<p>(Du hast noch an keiner Abstimmung teilgenommen)</p>
|
||||
{% endfor %}
|
||||
|
||||
<p>
|
||||
{{ session }}
|
||||
</p>
|
||||
<p>
|
||||
{{ session.user }}
|
||||
</p>
|
||||
<p>
|
||||
{{ session.user.1 }}
|
||||
</p>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{% for d in places %}
|
||||
<div class="vote-item">
|
||||
<label for="place_{{d.id}}">{{ d.name }}</label>
|
||||
<div class="slider">
|
||||
<div>
|
||||
<span class="emoji">😞</span>
|
||||
<input type="range" name="place_{{d.id}}" value="{{d.preference}}">
|
||||
<span class="emoji">😀</span>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{% for d in times %}
|
||||
<div class="vote-item">
|
||||
<label for="time_{{d.id}}">{{ d.display or d.time }}</label>
|
||||
<div class="slider">
|
||||
<div>
|
||||
<span class="emoji">😞</span>
|
||||
<input type="range" name="time_{{d.id}}" value="{{d.preference}}">
|
||||
<span class="emoji">😀</span>
|
||||
|
|
Loading…
Reference in New Issue