Find us on GitHub

Toronto - Library Carpentry

Jul 28-29, 2016

9:00 am - 4:00 pm

Instructors: Kim Pham, Leanne Trimble, Greg Wilson, Nich Worby, Thomas Guignard

Helpers: Nancy Fong, Leslie Barnes, Bella Ban, Sean Zhao, Stephanie Pegg, Andy Wagner

Introducing Library Carpentry, a Software Carpentry based workshop series aimed at librarians, archivists, museum professionals, and other information professionals. This workshop is brought to you by members of code4libtoronto and volunteers of Software Carpentry.

Register

General Information

Software Carpentry's mission is to help scientists and engineers get more research done in less time and with less pain by teaching them basic lab skills for scientific computing. Library Carpentry offers comparable training to help librarians, archivists, museums and information professionals gain computing skills relevant to their profession. Participants will be encouraged to help one another and to apply what they have learned to their own problems sets.

Who: The course is aimed at librarians, archivists, museum professionals, and other information professionals. You don't need to have any previous knowledge of the tools that will be presented at the workshop. However, we do recommend that attendees have had some exposure / familarity with the following concepts: programming logic, boolean expressions, XML.

Where: University of Toronto Robarts Library - 4th Floor - Blackburn Room. Get directions with OpenStreetMap or Google Maps.

Requirements: Participants must bring a laptop with a Mac, Linux, or Windows operating sytem (not a tablet, Chromebook, etc.) that they have administrative privileges on. They should have a few specific software packages installed (listed below). They are also required to abide by Software Carpentry's Code of Conduct.

Accessibility: We are committed to making this workshop accessible to everybody. The workshop organisers have checked that:

  • The room is wheelchair / scooter accessible.
  • Accessible restrooms are available.

Materials will be provided in advance of the workshop and large-print handouts are available if needed by notifying the organizers in advance. If we can help making learning easier for you (e.g. sign-language interpreters, lactation facilities) please get in touch and we will attempt to provide them.

Contact: Please mail kim.pham@utoronto.ca for more information.


Schedule

July 28

09:00 Welcome & Introduction
09:15 Regular Expressions (Regex)
10:15 Break
10:30 XQuery / XPath
12:00 Lunch break
13:00 Introduction to Open Refine
14:30 Coffee
16:00 Wrap-up

July 29

09:00 Introduction to Python
10:15 Break
10:30 Python and APIs
12:00 Lunch break
13:00 Introduction to Web scraping
14:30 Coffee
16:00 Wrap-up

Etherpad: http://pad.software-carpentry.org/2016-07-2829-librarycarpentry.
We will use this Etherpad for chatting, taking notes, and sharing URLs and bits of code.


Syllabus

Regular Expressions

  • Introduction
  • Basic operators
  • Anchors
  • Quantifiers
  • Practice using https://regex101.com/

Introduction to Python

  • Using libraries
  • Working with arrays
  • Reading and plotting data
  • Creating and using functions
  • Loops and conditionals
  • Defensive programming
  • Using Python from the command line
  • Reference...

Introduction to OpenRefine

  • Data format conversion
  • Transformations
  • Cluster edit data
  • Reconciliation
  • Templating data

XPath / XQuery

  • Traversing a document
  • Building queries
  • Searching through an XML document
  • Find and replace text
  • Batch editing XML documents

Introduction to Web scraping

  • What is web scraping and why it is useful
  • Scraping manually using browser extensions
  • Defining what items to extract using XPath
  • Writing scrapers to crawl a website
  • Store and reuse extracted items
  • Do's and Don'ts of web scraping

Setup

To participate in this Library Carpentry workshop, you will need access to the software described below. In addition, you will need an up-to-date web browser.

We maintain a list of common issues that occur during installation as a reference for instructors that may be useful on the Configuration Problems and Solutions wiki page.

The Bash Shell

Bash is a commonly-used shell that gives you the power to do simple tasks more quickly.

Windows

Video Tutorial
  1. Download the Git for Windows installer.
  2. Run the installer and follow the steps bellow:
    1. Click on "Next".
    2. Click on "Next".
    3. Click on "Next".
    4. Click on "Next".
    5. Click on "Next".
    6. Select "Use Git from the Windows Command Prompt" and click on "Next". If you forgot to do this programs that you need for the workshop will not work properly. If this happens rerun the installer and select the appropriate option.
    7. Click on "Next". Keep "Checkout Windows-style, commit Unix-style line endings" selected.
    8. Select "Use Windows' default console window" and click on "Next".
    9. Click on "Next".
    10. Click on "Finish".
  3. If your "HOME" environment variable is not set (or you don't know what this is):
    1. Open command prompt (Open Start Menu then type cmd and press [Enter])
    2. Type the following line into the command prompt window exactly as shown:

      setx HOME "%USERPROFILE%"

    3. Press [Enter], you should see SUCCESS: Specified value was saved.
    4. Quit command prompt by typing exit then pressing [Enter]

This will provide you with both Git and Bash in the Git Bash program.

Mac OS X

The default shell in all versions of Mac OS X is Bash, so no need to install anything. You access Bash from the Terminal (found in /Applications/Utilities). See the Git installation video tutorial for an example on how to open the Terminal. You may want to keep Terminal in your dock for this workshop.

Linux

The default shell is usually Bash, but if your machine is set up differently you can run it by opening a terminal and typing bash. There is no need to install anything.

Regular Expressions (Regex)

No installation required -- we will be using a browser-based tool during the workshop.

BaseX for XPath / XQuery

Install BaseX. You may need to install a JDK to get it to run. Once you've installed the program, in your command prompt or terminal type in the command $ basexgui to start the program.

Windows

Download the Windows Installer.

Mac OS X

Install homebrew. Run $ brew install basex

Linux

A Linux distribution of basex is available here.

OpenRefine

OpenRefine (formerly Google Refine) is a powerful tool for working with messy data: cleaning it; transforming it from one format into another; and extending it with web services and external data. Please look at the Installation Instructions from the OpenRefine project for more details on how to run OpenRefine on your machine. The instructions below are adapted from this link. We will be using version 2.6-rc2 during the workshop. A Java Runtime Environment (JRE) is required to run OpenRefine. If the installation procedure below fails, make sure you have a working JRE installed on your computer.

Windows

  1. Download OpenRefine v. 2.6-rc2 for Windows
  2. Once you have downloaded the .zip file, uncompress it into a folder wherever you want (such as in C:\Open-Refine).
  3. To launch OpenRefine, run the .exe file in that folder. You should see the Command window in which OpenRefine runs.
  4. To shut down OpenRefine, press Ctrl-C in the command window that is running OpenRefine. Wait until there's a message that says the shutdown is complete. That window might close automatically, or you can close it yourself. If you get asked, "Terminate all batch processes? Y/N", just press Y.

Mac OS X

  1. Download OpenRefine v. 2.6-rc2 for Mac
  2. Once you have downloaded the .dmg file, open it, and drag the OpenRefine icon into the Applications folder.
  3. To launch OpenRefine, double-click the OpenRefine app. You'll see the OpenRefine app appear in your dock.
  4. If you get an error message preventing you from opening the app because it's from an unidentified developer, do the following (you only have to do it once when you open the app for the first time):
    1. Press the ctrl (Control) key and click on the app icon
    2. Choose Open from the shortcut menu
    3. There should now be an Open button under the "unidentified developer" error message. Click that button to open the app.
  5. To shut down OpenRefine, right-click on its icon in the Dock and choose the Quit option.

Linux

  1. Download OpenRefine v. 2.6-rc2 for Linux
  2. Once you have downloaded the .tar.gz file, uncompress it into a folder wherever you want.
  3. To launch OpenRefine, open a shell, navigate to that folder and type ./refine
  4. To shut down OpenRefine, press Ctrl-C in the shell that is running OpenRefine.

Running OpenRefine

OpenRefine is operated from within a web browser (such as Chrome or Firefox). If your browser doesn't open automatically when you start OpenRefine (see above), navigate to http://127.0.0.1:3333/ in your favourite browser to open the OpenRefine window. Please note that even though you use a browser to operate OpenRefine, it is still run locally on your machine, and not on the web.

Text Editor

When you're writing code, it's nice to have a text editor that is optimized for writing code, with features like automatic color-coding of key words. The default text editor on Mac OS X and Linux is usually set to Vim, which is not famous for being intuitive. if you accidentally find yourself stuck in it, try typing the escape key, followed by :q! (colon, lower-case 'q', exclamation mark), then hitting Return to return to the shell.

Windows

Video Tutorial

nano is a basic editor and the default that instructors use in the workshop. To install it, download the Software Carpentry Windows installer and double click on the file to run it. This installer requires an active internet connection.

Others editors that you can use are Notepad++ or Sublime Text. Be aware that you must add its installation directory to your system path. Please ask your instructor to help you do this.

Mac OS X

nano is a basic editor and the default that instructors use in the workshop. See the Git installation video tutorial for an example on how to open nano. It should be pre-installed.

Others editors that you can use are Text Wrangler or Sublime Text.

Linux

nano is a basic editor and the default that instructors use in the workshop. It should be pre-installed.

Others editors that you can use are Gedit, Kate or Sublime Text.

Python

Python is a popular language for scientific computing, and great for general-purpose programming as well. Installing all of its scientific packages individually can be a bit difficult, so we recommend Anaconda, an all-in-one installer.

Regardless of how you choose to install it, please make sure you install Python version 3.x (e.g., 3.4 is fine).

We will teach Python using the IPython notebook, a programming environment that runs in a web browser. For this to work you will need a reasonably up-to-date browser. The current versions of the Chrome, Safari and Firefox browsers are all supported (some older browsers, including Internet Explorer version 9 and below, are not).

Windows

Video Tutorial
  1. Open http://continuum.io/downloads with your web browser.
  2. Download the Python 3 installer for Windows.
  3. Install Python 3 using all of the defaults for installation except make sure to check Make Anaconda the default Python.

Mac OS X

Video Tutorial
  1. Open http://continuum.io/downloads with your web browser.
  2. Download the Python 3 installer for OS X.
  3. Install Python 3 using all of the defaults for installation.

Linux

  1. Open http://continuum.io/downloads with your web browser.
  2. Download the Python 3 installer for Linux.
  3. Install Python 3 using all of the defaults for installation. (Installation requires using the shell. If you aren't comfortable doing the installation yourself stop here and request help at the workshop.)
  4. Open a terminal window.
  5. Type
    bash Anaconda3-
    and then press tab. The name of the file you just downloaded should appear.
  6. Press enter. You will follow the text-only prompts. When there is a colon at the bottom of the screen press the down arrow to move down through the text. Type yes and press enter to approve the license. Press enter to approve the default location for the files. Type yes and press enter to prepend Anaconda to your PATH (this makes the Anaconda distribution the default Python).

Scrapy

In the first part of the Web scraping lesson, we will use a Chrome browser extension to get started with web scraping. Please ensure you have a working copy of the Chrome browser, as well as the Scraper extension. We will also use OpenRefine to clean up extracted data.

In the second part of the lesson, we will use the Scrapy framework to build a web scraper in Python. This requires a working installation of Python, please refer to the section on installing Python for details.

Windows

Make sure you have a working copy of the Google Chrome browser on your machine. Install the Scraper extension.

We will also need a command-line tool to run Scrapy. See the section on installing GitBash if you haven't done so already. If you already have another shell installed, such as Cygwin, this should be fine too.

If you installed Python using Anaconda as recommended above, do the following:

  1. Open the Anaconda command line tool (or a shell such as GitBash)
  2. Run conda install -c scrapinghub scrapy

If you have another install of Python, you should be able to use the pip package manager to install Scrapy: pip install Scrapy. If you run into issues, refer to the official Scrapy install guide or get in touch with Thomas (@timtomch).

Mac OS X

Make sure you have a working copy of the Google Chrome browser on your machine. Install the Scraper extension.

If you installed Python using Anaconda as recommended above, do the following:

  1. Open a new Terminal session
  2. Run conda install scrapy

If you have another install of Python, you should be able to use the pip package manager to install Scrapy: pip install Scrapy. If you run into issues, refer to the official Scrapy install guide or get in touch with Thomas (@timtomch).

Linux

Make sure you have a working copy of the Google Chrome browser on your machine. Install the Scraper extension.

If you installed Python using Anaconda as recommended above, do the following:

  1. Open a new shell
  2. Run conda install scrapy

If you have another install of Python, you should be able to use the pip package manager to install Scrapy: pip install Scrapy. If you run into issues, refer to the official Scrapy install guide or get in touch with Thomas (@timtomch).