Scan hundreds of SQL Saturday raffle tickets. Fast.

If you’re an organizer, sponsor and/or an exhibitor at a SQL Saturday event, you often collect raffle tickets from attendees. In exchange for giving you their contact information, they have the opportunity to win cool raffle prizes.

Here’s the thing, though. Raffle tickets can be a bit painful to scan on your mobile phone. You point the phone at the QR code, then click the URL that opens up the browser, after which the SQL Saturday web service takes another second or two (or three) to load. This is fine when you have just a few tickets, but it can be mindnumbing if you have hundreds.

What can I say, I’m lazy.

Scanning those tickets, fast.

In the Mac AppStore, I found an app called QR Capture that uses the computer’s camera to scan QR codes and add them to a list. I’m sure there are similar apps for Linux and Windows, but the key selling point here is that the app writes all those URLs (that’s what the raffle ticket QR codes really are) to a list that can be exported as a text file:

Scanning tickets this way is really fast if you have a decent camera – a bit like scanning groceries at the supermarket. With a little practice, you’ll go through hundreds of tickets in very little time.

Fetching all those links

So, now that you have the text file, let’s write a tiny Powershell script to open each of those URLs – without ever opening a single browser tab.

# Every file in this directory that ends in .txt is fair game.
$files=Get-ChildItem "*.txt"

# For each file...
ForEach ($f in $files){
    Write-Host $f.FullName

    # ... and for each line in that file...
    ForEach($line in Get-Content $f) {
        Write-Host $line

        # ... query that URL, return the status code (should always be 200).
        # Querying the URL will register the raffle ticket.
        $request = Invoke-WebRequest -Uri $line

        Write-Host "... " + $request.StatusCode

The script looks for every .txt files in the current directory. For each of those files, it takes each row and performs an Invoke-WebRequest to get that URL.

We don’t really care about the output of the web request – just requesting the URL is enough to register the raffle ticket (just look for the “200 OK” code).

Let me hear your thoughts!

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.