cjwatson: (Default)
I'm very lazy. Rather than having to keep track of Cambridge bin collection days manually, especially around holidays, I wrote a thing to convert it into an iCalendar file for me so that I could import it into Google Calendar. Here it is in case it's useful to anyone else:
#! /usr/bin/python3

from argparse import ArgumentParser
from datetime import datetime
import os.path
import re

from bs4 import BeautifulSoup
import dateutil.parser
from icalendar import (
import requests

parser = ArgumentParser(
    description="Generate iCalendar file for Cambridge bin collection days.")
        "Unique identifier for this calendar, normally your host name.  Make "
        "sure that this does not collide with any other calendars."))
parser.add_argument("address", help="Your street address in Cambridge.")
parser.add_argument("postcode", help="Your postcode.")
args = parser.parse_args()

now = datetime.now()
req = requests.get(
    params={"address": args.address, "postcode": args.postcode})
soup = BeautifulSoup(req.text)
cal = Calendar()
cal.add("prodid", "-//riva.pelham.vpn.ucam.org//bin-days//EN")
cal.add("version", "2.0")
cal.add("calscale", "GREGORIAN")
cal.add("x-wr-calname", "Bin days")
cal.add("x-wr-timezone", "Europe/London")
for div in soup.find_all("div", style=re.compile(r"^text-align:center")):
    desc = div.contents[0]
    when = dateutil.parser.parse(div.b.get_text(" ").rstrip("*"))
    while when < now:
        when = when.replace(year=when.year + 1)
    event = Event()
    event.add("uid", "bin-days/{:%Y%m%d}@{}".format(when, args.id))
    event.add("dtstart", when.date())
    event.add("summary", desc.capitalize())
    event.add("transp", "TRANSPARENT")
with open(os.path.expanduser("~/public_html/bin-days.ics"), "wb") as out:
On Debian, this requires the python3-bs4, python3-dateutil, python3-icalendar, and python3-requests packages. You'll probably want to change the output path to somewhere that your calendar software can see (so if it's a web service such as Google Calendar then it needs to be something that corresponds to an accessible URL). The web-scraping is pretty gross, but it's the best I can do given the council's published data. Ideally this would itself be a web service that could generate calendars on demand for a given address and postcode, but like I say I'm lazy.

cjwatson: (Default)
As a follow-up to my post about my personal history of programming languages, [livejournal.com profile] cartesiandaemon asked me to expand on "which language(s) do you use most now (C and Python?) and what improvements would you like to see in them?"

from __future__ import delorean )

This post is part of my December days series. Please prompt me!
cjwatson: (Default)
As a follow-up to my post about programming languages, [personal profile] liv asked me: "can you talk about whether you're planning to teach your children programming, and if so how?"

I'd very much like to teach my children programming, yes, for a variety of reasons. One is that it's a thing I'm personally enthusiastic about that I want to share with them. Another is that it's an increasingly useful secondary skill in all kinds of other academic disciplines, whether that's for data analysis or driving complex machinery or whatever, and I'd like them to have that be accessible to them if at all possible. And of course I think it's a worthwhile skill in its own right, as computers become more and more a part of everyday life.

On the other hand, I don't want to teach them just single bespoke skills, such as just one programming language: what I really want to impart is the mental discipline of ordering your thoughts in order to instruct a computer accurately in how to do them, which I think is an aptitude that transfers itself well to all kinds of other things, even though doing that clearly involves learning the nuts and bolts of programming (preferably in more than one languages) and especially for children it needs to involve having fun along the way. There's no point trying to teach programming to children if they find it boring, or if it's too early in their development. (I tried to teach B how to program some years ago, but honestly I hadn't prepared well enough, it fell rather flat, and by the time we revisited it he wasn't really interested, so I definitely want to prepare better this time round.)

[livejournal.com profile] ghoti has been planning to start with a plan she'd previously started on while TAing at primary level, namely to start with Scratch (hmm, appropriately the top featured project there is currently a dreidel game) and move on to Rhodri James's Python course. I've generally been of the opinion that it will work better if we wait until J's reading is a fair bit more fluent, and so to be honest I hadn't yet thought much about the details yet; Scratch is more visual than a lot of languages but it still has a very significant textual component.

I think this is still an area where I very much don't think I have the answers and am listening for suggestions. My criteria are that I want them to be able to progress quickly to doing things that will interest them, I don't want them to get bogged down in syntactic vinegar, but I also want them to be using (if not necessarily as the very first step) a language that isn't a toy and that they can write real non-trivial programs in, and preferably one that won't get them stuck in particularly bad habits. Python seems like a pretty good thing to aim for with the support of some decent code libraries and teaching materials, so [livejournal.com profile] ghoti's plan generally seems sound here, but I sort of feel the need to work through it ourselves first to make sure we aren't caught by surprise along the way.

Does anyone else reading this have experience with teaching children (other than themselves!) to program? I'd be interested in hearing about what you did.

This post is part of my December days series. Please prompt me!
cjwatson: (Default)
[livejournal.com profile] ewx prompted me to write about programming languages, and said "be as specific or general as feels appropriate".

clicky clicky )

This post is part of my December days series. Please prompt me!

September 2017



RSS Atom

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags