Skip to content

Commit 12a54c1

Browse files
committed
* include notes from the homework in week 4 slides
1 parent b5c1829 commit 12a54c1

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed

source/presentations/week04.rst

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,88 @@ But First
2222

2323
Review from the Assignment
2424

25+
Save Memory on Loading
26+
----------------------
27+
28+
When you are loading data from an API, you can sometimes get more than you
29+
bargained for. Both BeautifulSoup and the json library provide ways to help:
30+
31+
.. code-block:: python
32+
:class: incremental
33+
34+
page = urllib2.urlopen(url)
35+
json_string = page.read()
36+
json.loads(json_string)
37+
38+
.. code-block:: python
39+
:class: incremental
40+
41+
page = urllib2.urlopen(url)
42+
json.loads(page)
43+
44+
.. class:: incremental
45+
46+
The second form will *buffer* the input as it is read, and minimize memory
47+
consumption. If you've got really large data sets this can be very good.
48+
49+
Protect Yourself From the Net
50+
-----------------------------
51+
52+
We learned in our last class that APIs can flake. Remember that. It's *vital*!
53+
54+
.. code-block:: python
55+
:class: incremental
56+
57+
page = urllib2.urlopen(url)
58+
parsed = BeautifulSoup(page)
59+
60+
.. code-block:: python
61+
:class: incremental
62+
63+
page = urllib2.urlopen(url)
64+
if page.code == 200:
65+
parsed = BeautifulSoup(page)
66+
else:
67+
raise SomeExceptionYouCanCatch
68+
69+
.. class:: incremental
70+
71+
What happens if your desired API is offline when a user comes to see your
72+
page? Make sure you give yourself a way to be kind to your users. 500 Internal
73+
Server Errors suck!
74+
75+
What You Made
76+
-------------
77+
78+
.. class:: incremental
79+
80+
* geographic locations of our Bluebox VMs
81+
* Visualization of the popularity of Facebook Friends' first names
82+
* Restaurants near your location with recent Health Inspection data
83+
* A Last-FM user's top artists, with lists of mixcloud mixes featuring each of
84+
them
85+
* A list of Craigslist apartments with the nearest bars, pizza and sushi
86+
places and their Yelp ratings
87+
* Geographic locations of the top 20 users returned for a twitter search,
88+
along with other twitter data
89+
90+
A Note on Homeworks
91+
-------------------
92+
93+
.. class:: incremental
94+
95+
* I've been saying that only attendance counts for your grade.
96+
* It was brought to my attention this week that my own syllabus says
97+
differently
98+
* The work we've done so far is all, in some sense, foundational. We will be
99+
using tools starting next week that build upon the tools we've encountered.
100+
101+
.. class:: incremental
102+
103+
Homework from this point out should be considered required. We are now
104+
reaching the level of tools you will use on a day to day basis. Mastery comes
105+
with practice.
106+
25107
And Second
26108
----------
27109

0 commit comments

Comments
 (0)