Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix typos/grammar in DataViz and APIs tutorials #186

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions apis/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def load_from_file(self, fp):
reached_dataset = True
continue
# Each line ends with a new-line character which we strip here
# to make the data easier usable.
# to make the data easier to use.
data = line.rstrip().split()

# While we are dealing with calendar data the format is simple
Expand Down Expand Up @@ -296,7 +296,7 @@ def generate_plot(platforms, output_file):
ax.bar(ind, values, width, align='center')

# Format the X and Y axis labels. Also set the ticks on the x-axis slightly
# farther apart and give then a slight tilting effect.
# farther apart and give them a slight tilting effect.
plt.ylabel('Adjusted price')
plt.xlabel('Year / Console')
ax.set_xticks(ind + 0.3)
Expand Down Expand Up @@ -424,9 +424,8 @@ def main():
platform['adjusted_price'] = adjusted_price
platforms.append(platform)

# We limit the resultset on this end since we can only here check
# if the dataset actually contains all the data we need and therefor
# can't filter on the API level.
# We can't filter on the API level, so we limit the dataset here to
# check if it contains all of the data we need.
if opts.limit is not None and counter + 1 >= opts.limit:
break
counter += 1
Expand Down
6 changes: 3 additions & 3 deletions website/_containers/apis/2013-02-01-extended.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ Examples of APIs being used in real life, and where to go from here.

## In action

* Applications & clients for Twitter, Facebook, Instagram, Flickr, etc all interact with the respective API built for developers
* [Lyft](http://lyft.me) uses [Twilio](http://www.twilio.com/blog/2012/10/lyft-and-twilio.html) to send SMS messagesfor to let passengers know their ride was on its way and to communicate with drivers.
* [Trulia](http://corp.truliablog.com/2008/10/10/social-media-synergy-trulia-integrates-yelp-reviews-into-google-maps/), [Yellow Pages](http://cbsyellowpages.com/), [GrubHub](http://www.grubhub.com) all use [Yelp](http://www.yelp.com/developers/documentation/examples)’s API for integrating reviews into their websites.
* Applications & clients for Twitter, Facebook, Instagram, Flickr, etc all interact with the respective API built for developers.
* [Lyft](http://lyft.me) uses [Twilio](http://www.twilio.com/blog/2012/10/lyft-and-twilio.html) to send SMS messages to let passengers know their ride is on its way and to communicate with drivers.
* [Trulia](http://corp.truliablog.com/2008/10/10/social-media-synergy-trulia-integrates-yelp-reviews-into-google-maps/), [Yellow Pages](http://cbsyellowpages.com/), and [GrubHub](http://www.grubhub.com) all use [Yelp](http://www.yelp.com/developers/documentation/examples)’s API for integrating reviews into their websites.

## Where to go from here

Expand Down
40 changes: 20 additions & 20 deletions website/_containers/apis/2013-02-02-part-4.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,24 @@ When running a python file in the command line, Python has the ability to take a
(APIProj)$ python a_python_file.py --debug --output-file ~/MyDocuments/MyLogs/python_file.log
```

Certainly, we’d need to put some logic into our script in order to be able to parse arguments. Let’s think of all the arguments that we could possibly want to pass to our API Python script are:
Certainly, we’d need to put some logic into our script in order to be able to parse arguments. Let’s think of all the arguments that we could possibly want to pass to our API Python script:

* API key for Giantbomb
* path to CPI file
* Path to CPI file
* URL to get CPI data (default will be our global `CPI_DATA_URL` we defined earlier)
* Path to CSV file which will contain the data output
* Path to PNG file which will contain the graphed data output
* Output level for logging (whether just informational, or debugging, etc)
* Output level for logging (whether just informational, debugging, etc)
* Maximum number of platforms we want to look at, if any


Python’s standard library has a great module, `argparse` that we’ll use. We’ll create separate parsing function as a helper to our main function that we’ll write out after this.
Python’s standard library has a great module, `argparse` that we’ll use. We’ll create a separate parsing function as a helper to our main function that we’ll write out after this.

First, import argparse,
First, import argparse and os,

```python
import argparse
import os
```

then let’s define our parsing function, and use `argparse`’s `ArgumentParser` to initialize a `parser` class:
Expand All @@ -40,9 +41,9 @@ def parse_args():
parser = argparse.ArgumentParser()
```

The `ArgumentParser` class implicitly gives us an argument for free, the `-h` and `--help` flags for showing the usage of the script, `python platform_pricing.py [options] [args]`, as well as a list of available commands and their `help` strings we assign.
The `ArgumentParser` class implicitly gives us an argument for free, the `-h` and `--help` flags for showing the usage of the script, `python api.py [options] [args]`, as well as a list of available commands and their `help` strings we assign.

Now we should add all the arguments that could possibly be passed through from the command line with the `add_argument` method that `ArgumentParser` class gives us:
Now we should add all the arguments that could possibly be passed through from the command line with the `add_argument` method that the `ArgumentParser` class gives us:

```python
def parse_args():
Expand All @@ -54,7 +55,7 @@ def parse_args():
The first parameter that we feed to `add_argument` is the flag that is used in the command line:

```bash
(APIProj)$ python platform_pricing.py --giantbomb-api-key <YOUR_API_KEY>
(APIProj)$ python api.py --giantbomb-api-key <YOUR_API_KEY>
```

We also tell `add_argument` that this is a required field by passing the `required=True` parameter. The `ArgumentParser` class will take care of erroring out for us if that argument isn't given in the command line.
Expand Down Expand Up @@ -99,7 +100,7 @@ The Python docs have a great [tutorial](http://docs.python.org/2/howto/argparse.

### Main function

The `CPIData` and `GiantbombAPI` classes have been defined with their methods, as well as functions `generate_plot`, `generate_csv`, and `is_valid_dataset`. Let’s now make one `main()` function that runs whenever we call our `platform_pricing.py` file (with arguments) that instantiates (uses) everything.
The `CPIData` and `GiantbombAPI` classes have been defined with their methods, as well as functions `generate_plot`, `generate_csv`, and `is_valid_dataset`. Let’s now make one `main()` function that runs whenever we call our `api.py` file (with arguments) that instantiates (uses) everything.

We’ll first want to take care of the arguments passed through the command line by calling our `parse_args` function.

Expand All @@ -120,7 +121,7 @@ Since we did not specify any file to save our logs to, it will just write our lo

Next, we’ll instantiate both the `CPIData` class and the `GiantbombAPI` class and use some of the arguments that we parsed to pass the API key, the CPI URL (if we don't want to use the default defined in our global variable, `CPI_DATA_URL`, and CPI file (if we gave it a file).

We also print to the console – using the print _function_ imported from future (Python 3), rather than the print _keyword_ in Python 2 – that gives a disclaimer to the user what the script will be doing.
We also print to the console – using the print _function_ imported from future (Python 3), rather than the print _keyword_ in Python 2 – that gives a disclaimer to the user about what the script will be doing.

```python
# <-- snip -->
Expand Down Expand Up @@ -158,8 +159,8 @@ We then take our `platforms` list and pass it to either `generate_plot` or `gene
field_list=['release_date',
'original_price', 'name',
'abbreviation']):
# Some platforms don't have a release date or price yet. These we have
# to skip.
# Some platforms don't have a release date or price yet. We have to
# skip these.
if not is_valid_dataset(platform):
continue

Expand All @@ -171,9 +172,8 @@ We then take our `platforms` list and pass it to either `generate_plot` or `gene
platform['adjusted_price'] = adjusted_price
platforms.append(platform)

# We limit the resultset on this end since we can only here check
# if the dataset actually contains all the data we need and therefor
# can't filter on the API level.
# We can't filter on the API level, so we limit the dataset here to
# check if it contains all of the data we need.
if opts.limit is not None and counter + 1 >= opts.limit:
break
counter += 1
Expand All @@ -196,14 +196,14 @@ if __name__ == '__main__':
In your terminal, with your `APIProj` virtual environment activated, and from within your API project directory, try your new script with different arguments (be sure to use your own directory paths instead of `~/Projects/new-coder/apis/*` unless you have that exact directory setup):

```bash
(APIProj)$ python platform_pricing.py --giantbomb-api-key [YOUR_KEY] --plot-file ~/Projects/new-coder/apis/my_plot.png
(APIProj)$ python platform_pricing.py --giantbomb-api-key [YOUR_KEY] --csv-file ~/Projects/new-coder/apis/my_csv.csv
(APIProj)$ python platform_pricing.py --giantbomb-api-key [YOUR_KEY] --plot-file ~/Projects/new-coder/apis/my_plot.png --csv-file ~/Projects/new-coder/apis/my_csv.csv
(APIProj)$ python platform_pricing.py --giantbomb-api-key [YOUR_KEY] --debug --limit 40 --csv-file ~/Projects/new-coder/apis/my_csv.csv
(APIProj)$ python api.py --giantbomb-api-key [YOUR_KEY] --plot-file ~/Projects/new-coder/apis/my_plot.png
(APIProj)$ python api.py --giantbomb-api-key [YOUR_KEY] --csv-file ~/Projects/new-coder/apis/my_csv.csv
(APIProj)$ python api.py --giantbomb-api-key [YOUR_KEY] --plot-file ~/Projects/new-coder/apis/my_plot.png --csv-file ~/Projects/new-coder/apis/my_csv.csv
(APIProj)$ python api.py --giantbomb-api-key [YOUR_KEY] --debug --limit 40 --csv-file ~/Projects/new-coder/apis/my_csv.csv
```

<div class="well">
On a Mac and got a pop-up regarding X11 not installed? Just click “Cancel” - no need to worry. (It may pop up more than once, too).
On a Mac and got a pop-up regarding X11 not installed? Just click “Cancel” - no need to worry (it may pop up more than once, too).
</div>


Expand Down
6 changes: 3 additions & 3 deletions website/_containers/apis/2013-02-03-part-3.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def generate_plot(platforms, output_file):
ax.bar(ind, values, width, align='center')

# Format the X and Y axis labels. Also set the ticks on the x-axis slightly
# farther apart and give then a slight tilting effect.
# farther apart and give them a slight tilting effect.
plt.ylabel('Adjusted price')
plt.xlabel('Year / Console')
ax.set_xticks(ind + 0.3)
Expand All @@ -78,15 +78,15 @@ You can elect to have `plt.show(dpi=72)` instead of `plt.savefig(output_file, dp

We can also make a function that takes the yielded data and produces a CSV file for us.

Let’s use a new library, `tablib` to help handle the CSV production. [tablib](http://docs.python-tablib.org/en/latest/), written in Python by the same author of [requests](http://twitter.com/kennethreitz) that allows you to format the output of data into a tabular dataset (among other things).
Let’s use a new library, `tablib` to help handle the CSV production. [tablib](http://docs.python-tablib.org/en/latest/), written in Python by the same author of [requests](http://twitter.com/kennethreitz), allows you to format the output of data into a tabular dataset (among other things).

We should add an import statement for it too:

```python
import tablib
```

Similiar to `generate_plot` function, we’ll take two parameters: `platforms` which is the yielded data from our API class, and `output_file` to save the formatted data where we want to. We use the `tablib` module to assign headers to a dataset, then append each item of our platform data to the dataset. Last, we write to a file that passed in as a parameter using the `.csv` method that `tablib` gives us. Comments on process are inline:
Similiar to our `generate_plot` function, we’ll take two parameters: `platforms` which is the yielded data from our API class, and `output_file` to save the formatted data where we want to. We use the `tablib` module to assign headers to a dataset, then append each item of our platform data to the dataset. Lastly, we write to a file that is passed in as a parameter using the `.csv` method that `tablib` gives us. Comments on process are inline:

```python
def generate_csv(platforms, output_file):
Expand Down
6 changes: 3 additions & 3 deletions website/_containers/apis/2013-02-04-part-2.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Next, we’ll define one method (our class’s only method besides our construct

This method is a generator function (a clue is the `yield` statement instead of a `return` statement).

Follow the inline comments to undestand the process flow of `get_platforms`:
Follow the inline comments to understand the process flow of `get_platforms`:

```python
def get_platforms(self, sort=None, filter=None, field_list=None):
Expand All @@ -53,7 +53,7 @@ Follow the inline comments to undestand the process flow of `get_platforms`:
# The following lines also do value-format conversions from what's
# common in Python (lists, dictionaries) into what the API requires.
# This is especially apparent with the filter-parameter where we
# need to convert a dictionary of criteria into a comma-seperated
# need to convert a dictionary of criteria into a comma-separated
# list of key:value pairs.
params = {}
if sort is not None:
Expand Down Expand Up @@ -118,7 +118,7 @@ Follow the inline comments to undestand the process flow of `get_platforms`:
<div class="panel panel-default">
<div class="panel-heading">For the Curious</div>
<div class="panel-body">
The <code>yield</code> keyword is similar to <code>return</code>. The <code>get_platforms</code> function, specifically the <code>while incomplete</code> bit, we’ve essentially built a generator (it will generate data on the fly). StackOverflow has a good <a href="http://stackoverflow.com/questions/231767/the-python-yield-keyword-explained">explanation</a> of what’s happening in our function: The first time the function will run, it will run from the beginning until it hits yield, then it’ll return the first value of the loop. Then, each other call will run the loop you have written in the function one more time, and return the next value, until there is no value to return. The generator is considered empty once the function runs but does not hit yield anymore. It can be because the loop had come to ends, or because you do not satisfy a “if/else” anymore.
The <code>yield</code> keyword is similar to <code>return</code>. In the <code>get_platforms</code> function, specifically the <code>while incomplete</code> bit, we’ve essentially built a generator (it will generate data on the fly). StackOverflow has a good <a href="http://stackoverflow.com/questions/231767/the-python-yield-keyword-explained">explanation</a> of what’s happening in our function: The first time the function will run, it will run from the beginning until it hits yield, then it’ll return the first value of the loop. Then, each other call will run the loop you have written in the function one more time, and return the next value, until there is no value to return. The generator is considered empty once the function runs but does not hit yield anymore. It can be because the loop had come to ends, or because you do not satisfy an “if/else” anymore.
</div></div>


Expand Down
4 changes: 2 additions & 2 deletions website/_containers/apis/2013-02-05-part-1.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ def load_from_file(self, fp):
pass

# Each line ends with a new-line character which we strip here
# to make the data easier usable.
# to make the data easier to use.
data = line.rstrip().split()

# While we are dealing with calendar data the format is simple
Expand Down Expand Up @@ -284,7 +284,7 @@ def get_adjusted_price(self, price, year, current_year=None):
return float(price) / year_cpi * current_cpi
```

In review, we’ve essentially defined the container, our `CPIData` class, to handle the the processing of our CPI data. We initialize each field for a piece of CPI data in `__init__`, we define how to load data from a given URL (of which we define as a global variable, `CPI_DATA_URL` before we defined our class), we define how to load and parse that data that we just grabbed from the URL and saved, and lastly, we define a method to grab the price for a given year (adjusted if we didn’t grab that specific year from the FRED earlier).
In review, we’ve essentially defined the container, our `CPIData` class, to handle the processing of our CPI data. We initialize each field for a piece of CPI data in `__init__`, we define how to load data from a given URL (of which we define as a global variable, `CPI_DATA_URL` before we defined our class), we define how to load and parse that data that we just grabbed from the URL and saved, and lastly, we define a method to grab the price for a given year (adjusted if we didn’t grab that specific year from the FRED earlier).

<br/>
<nav>
Expand Down
2 changes: 1 addition & 1 deletion website/_containers/apis/2013-02-06-part-0.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ You should now see `(APIProj)` before your prompt. Now, from within the `new-cod
```bash
(APIProj) $ pip install -r requirements.txt
```
Your virtual environment will store the required packages in a self-contained area to not mess up with other Python projects.
Your virtual environment will store the required packages in a self-contained area to not mess up other Python projects.

Lastly, navigate to *your* project workspace that you setup earlier from the [machine setup]({{ get_url("/begin/setup-your-machine")}}):

Expand Down
2 changes: 1 addition & 1 deletion website/_containers/apis/2013-02-07-intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ category: intro

Video games have always been a pricy hobby. With the next generation of consoles just being announced (or about to be) it makes sense to look at how pricing has changed on that front over time.

During the course of this tutorial you will get more familiar with some non-core Python libraries: [requests][requests] for making interactions with HTTP much more easier, [matplotlib][matplotlib] for generating graphs and charts of various kinds and [tablib][tablib] for easily generating CSV datasets.
During the course of this tutorial you will get more familiar with some non-core Python libraries: [requests][requests] for making interactions with HTTP much easier, [matplotlib][matplotlib] for generating graphs and charts of various kinds and [tablib][tablib] for easily generating CSV datasets.

### Project

Expand Down
2 changes: 1 addition & 1 deletion website/_containers/dataviz/2013-01-02-part-3.md
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ Make sure to name your gist file with the `.geojson` ending:

<img class="displayed" src="http://dl.dropboxusercontent.com/s/2f77zi0nw2jagcy/2014-02-01%20at%203.28%20PM%202x%20(1).png" width="750px" height="500px"/>

Then select either “Create Private Gist” or “Create Public Gist”, your choice:
Then select either “Create Secret Gist” or “Create Public Gist”, your choice:

<img class="displayed" src="http://dl.dropboxusercontent.com/s/lgvgd358a9avjke/2014-02-01%20at%203.28%20PM%202x%20(2).png" width="750px" height="500px" />

Expand Down
Loading