$ req = web.tx.request $if req.method == "GET": <p>Bookmarklet: <a href="javascript:(function(){ window.location.href='https://ragt.ag/bookmark?url='+ encodeURIComponent(window.location.href) })()">Bookmark</a> <small>(drag to browser toolbar to install)</small></p> $ url = req.uri.query.get('url', [None])[0] <form method=post action=/bookmark> <label><small>Webpage URL:</small><br> <input name=webpage_url value="$url" style=width:30em></label><br> $if url: $ post = web.get(url).entry <p>$post["name"]</p> <fieldset> <legend>Categories:</legend> <textarea style=height:10em;width:20em></textarea> </fieldset> <button>Bookmark</button> </form> $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://wpdev.gwg.us/wp-json/micropub/1.0/endpoint", $ 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> |