$ req = web.tx.request $if req.method == "GET": <p>Bookmarklet: <a href="javascript:(function(){ window.location.href='https://ragt.ag/rsvp?url='+ encodeURIComponent(window.location.href) })()">RSVP</a> <small>(drag to browser toolbar to install)</small></p> $ url = req.uri.query.get('url', [None])[0] <form method=post action=/rsvp> <label><small>Event URL:</small><br> <input name=event_url value="$url" style=width:30em></label><br> $if url: $ event = web.get(url).entry <p>$event["name"]<br><img src="$event['photo']"></p> <fieldset> <legend>RSVP</legend> $for response in ("yes", "no", "maybe"): <label><input type=radio name=response value=$response> $response.capitalize()</label> </fieldset> <button>RSVP</button> </form> <code style=font-size:.8em>$web.tx.user.session</code> $elif req.method == "POST": $ form = web.form("event_url", "response") $if token := web.tx.user.session.get("token", [None])[0]: $ mp_resp = web.post("https://micro.blog/micropub", $ headers={ $ "Authorization": f"Bearer {token}", $ "Content-Type": "application/x-www-form-urlencoded", $ }, $ data={ $ "h": "entry", $ "in_reply_to": form.event_url, $ "rsvp": form.response, $ }) $mp_resp.text <p>RSVP'd to <code>$form.event_url</code></p> $else: <p>Your host does not support access tokens.</p> |