26
django Database-driven journalism

Database-driven journalismmedia.b-list.org/presentations/2008/pycon/lightning.pdf · Database-driven journalism. Lawrence Journal-World Lawrence, KS “ ” Oh. The Django guys, right?

  • Upload
    others

  • View
    1

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Database-driven journalismmedia.b-list.org/presentations/2008/pycon/lightning.pdf · Database-driven journalism. Lawrence Journal-World Lawrence, KS “ ” Oh. The Django guys, right?

django

Database-driven journalism

Page 2: Database-driven journalismmedia.b-list.org/presentations/2008/pycon/lightning.pdf · Database-driven journalism. Lawrence Journal-World Lawrence, KS “ ” Oh. The Django guys, right?

Lawrence Journal-World

Lawrence, KS

Page 3: Database-driven journalismmedia.b-list.org/presentations/2008/pycon/lightning.pdf · Database-driven journalism. Lawrence Journal-World Lawrence, KS “ ” Oh. The Django guys, right?

“”

Oh. The Django guys, right?

Page 4: Database-driven journalismmedia.b-list.org/presentations/2008/pycon/lightning.pdf · Database-driven journalism. Lawrence Journal-World Lawrence, KS “ ” Oh. The Django guys, right?

But we do so much more

Page 5: Database-driven journalismmedia.b-list.org/presentations/2008/pycon/lightning.pdf · Database-driven journalism. Lawrence Journal-World Lawrence, KS “ ” Oh. The Django guys, right?

Lifecycle of a “data story”

Reporter gets data

Parse/normalize data into RDBMS

Build web interface

Offer cleaned data for download

Page 6: Database-driven journalismmedia.b-list.org/presentations/2008/pycon/lightning.pdf · Database-driven journalism. Lawrence Journal-World Lawrence, KS “ ” Oh. The Django guys, right?

Python every step of the way

Page 7: Database-driven journalismmedia.b-list.org/presentations/2008/pycon/lightning.pdf · Database-driven journalism. Lawrence Journal-World Lawrence, KS “ ” Oh. The Django guys, right?

Real-life exampleCrime reports on local university campus

Page 8: Database-driven journalismmedia.b-list.org/presentations/2008/pycon/lightning.pdf · Database-driven journalism. Lawrence Journal-World Lawrence, KS “ ” Oh. The Django guys, right?

Reporter got the data

Three years of reports

Organized by residence hall

Tables embedded in Microsoft Word :(

Page 9: Database-driven journalismmedia.b-list.org/presentations/2008/pycon/lightning.pdf · Database-driven journalism. Lawrence Journal-World Lawrence, KS “ ” Oh. The Django guys, right?

Google to the rescue!

Page 10: Database-driven journalismmedia.b-list.org/presentations/2008/pycon/lightning.pdf · Database-driven journalism. Lawrence Journal-World Lawrence, KS “ ” Oh. The Django guys, right?
Page 11: Database-driven journalismmedia.b-list.org/presentations/2008/pycon/lightning.pdf · Database-driven journalism. Lawrence Journal-World Lawrence, KS “ ” Oh. The Django guys, right?

Step 1

Upload MS Word to Google Docs

Export as HTML

Page 12: Database-driven journalismmedia.b-list.org/presentations/2008/pycon/lightning.pdf · Database-driven journalism. Lawrence Journal-World Lawrence, KS “ ” Oh. The Django guys, right?

Step 2

Google Docs produces almost-valid HTML

BeautifulSoup gets us the rest of the way

End result: a nicely-formatted CSV file

Page 13: Database-driven journalismmedia.b-list.org/presentations/2008/pycon/lightning.pdf · Database-driven journalism. Lawrence Journal-World Lawrence, KS “ ” Oh. The Django guys, right?

Data modelling

Build a few classes: residence hall, crime, statute, etc.

Import from the CSV files

Used Django for this, but don’t have to; any ORM is good, or just DB-API

Page 14: Database-driven journalismmedia.b-list.org/presentations/2008/pycon/lightning.pdf · Database-driven journalism. Lawrence Journal-World Lawrence, KS “ ” Oh. The Django guys, right?

Web-based views

Pick your favorite web framework/toolkit

We use Django

Mostly you’re slinging around lists of dictionaries

Page 15: Database-driven journalismmedia.b-list.org/presentations/2008/pycon/lightning.pdf · Database-driven journalism. Lawrence Journal-World Lawrence, KS “ ” Oh. The Django guys, right?

Make it fancy

geocoding of addresses with geopy (http://exogen.case.edu/projects/geopy/)

Now we have maps

Page 16: Database-driven journalismmedia.b-list.org/presentations/2008/pycon/lightning.pdf · Database-driven journalism. Lawrence Journal-World Lawrence, KS “ ” Oh. The Django guys, right?
Page 17: Database-driven journalismmedia.b-list.org/presentations/2008/pycon/lightning.pdf · Database-driven journalism. Lawrence Journal-World Lawrence, KS “ ” Oh. The Django guys, right?

Make it fancy

Google Charts API is just HTTP, we can talk to that with Python

Now we have charts

Page 18: Database-driven journalismmedia.b-list.org/presentations/2008/pycon/lightning.pdf · Database-driven journalism. Lawrence Journal-World Lawrence, KS “ ” Oh. The Django guys, right?
Page 19: Database-driven journalismmedia.b-list.org/presentations/2008/pycon/lightning.pdf · Database-driven journalism. Lawrence Journal-World Lawrence, KS “ ” Oh. The Django guys, right?

And put it all together

Page 20: Database-driven journalismmedia.b-list.org/presentations/2008/pycon/lightning.pdf · Database-driven journalism. Lawrence Journal-World Lawrence, KS “ ” Oh. The Django guys, right?
Page 22: Database-driven journalismmedia.b-list.org/presentations/2008/pycon/lightning.pdf · Database-driven journalism. Lawrence Journal-World Lawrence, KS “ ” Oh. The Django guys, right?

This took two days

Got the data on Wednesday, showed off the interface on Friday

Took less time to prepare this interface than to write the story for the newspaper

Hooray Python!

Page 24: Database-driven journalismmedia.b-list.org/presentations/2008/pycon/lightning.pdf · Database-driven journalism. Lawrence Journal-World Lawrence, KS “ ” Oh. The Django guys, right?

Python all the way

Page 26: Database-driven journalismmedia.b-list.org/presentations/2008/pycon/lightning.pdf · Database-driven journalism. Lawrence Journal-World Lawrence, KS “ ” Oh. The Django guys, right?

(and if you like this sort of stuff, we’re hiring!)