Skip to content

Commit

Permalink
Fall 2023 updates to lessons
Browse files Browse the repository at this point in the history
  • Loading branch information
dolsysmith committed Sep 25, 2023
1 parent e212162 commit f91b6a6
Show file tree
Hide file tree
Showing 13 changed files with 103 additions and 27 deletions.
4 changes: 2 additions & 2 deletions course_utils/bookstore_scraper.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,11 @@ def fetch_data(self, headers):
'''
:param headers: should be a dict of request headers, mimicking those of a specific browser
'''
response = response = httpx.post(self.base_url,
try:
response = httpx.post(self.base_url,
params=self.params,
headers=headers,
json=self.json_data)
try:
resp_data = response.json()
if 'blockScript' in resp_data:
raise CaptchaError
Expand Down
2 changes: 1 addition & 1 deletion homework-modules/python-camp-hw-2-gr
16 changes: 16 additions & 0 deletions textbook/notebooks/homework/HW_2_GR.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,22 @@
"#Your code here"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"````{hint}\n",
"\n",
"Make sure you create each course dictionary **inside** the `for` loop, like so:\n",
"```\n",
"for course in courses:\n",
" course_dict = {}\n",
" ...\n",
"```\n",
"\n",
"````"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down
11 changes: 7 additions & 4 deletions textbook/notebooks/homework/HW_2_programming_techniques.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,10 @@
"metadata": {},
"outputs": [],
"source": [
"from urllib.request import urlretrieve\n",
"import json\n",
"with open('../../../data/bookstore-data-summer-2023.json') as f:\n",
"urlretrieve('https://go.gwu.edu/pythoncampdata', 'bookstore-data.json')\n",
"with open('bookstore-data.json') as f:\n",
" bkst_data = json.load(f)"
]
},
Expand Down Expand Up @@ -150,7 +152,9 @@
"execution_count": null,
"metadata": {
"solution2": "hidden",
"tags": ["hide-cell"]
"tags": [
"hide-cell"
]
},
"outputs": [],
"source": [
Expand Down Expand Up @@ -237,8 +241,7 @@
},
"source": [
"````{hint}\n",
":class: dropdown",
"\n",
":class: dropdown\n",
"The crucial line of the Python documentation for methods is the first, called the **method signature**. For `str.split()` the method signature looks like this:\n",
"```\n",
"str.split(sep=None, maxsplit=-1)\n",
Expand Down
41 changes: 38 additions & 3 deletions textbook/notebooks/homework/HW_3_GR.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,12 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"metadata": {
"editable": true,
"slideshow": {
"slide_type": ""
},
"tags": [
"setup:ex1"
]
Expand Down Expand Up @@ -71,8 +75,12 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"metadata": {
"editable": true,
"slideshow": {
"slide_type": ""
},
"tags": [
"solution:ex1"
]
Expand Down Expand Up @@ -100,6 +108,10 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"editable": true,
"slideshow": {
"slide_type": ""
},
"tags": [
"test-case:ex1"
]
Expand Down Expand Up @@ -133,6 +145,10 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"editable": true,
"slideshow": {
"slide_type": ""
},
"tags": [
"setup:ex2"
]
Expand Down Expand Up @@ -165,7 +181,13 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"editable": true,
"slideshow": {
"slide_type": ""
},
"tags": []
},
"outputs": [],
"source": [
"create_isbn_dict(more_books)"
Expand All @@ -178,10 +200,23 @@
"Your task now: modify `create_isbn_dict` so that it works on `more_books` as well as `books`. Enter your new version of the function in the cell below. "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"````{hint}\n",
"For books without an ISBN, the function should simply skip them. \n",
"````"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"editable": true,
"slideshow": {
"slide_type": ""
},
"tags": [
"solution:ex2"
]
Expand Down
4 changes: 3 additions & 1 deletion textbook/notebooks/homework/HW_3_error_stories.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,10 @@
"metadata": {},
"outputs": [],
"source": [
"from urllib.request import urlretrieve\n",
"import json\n",
"with open('../../../data/bookstore-data-summer-2023.json') as f:\n",
"urlretrieve('https://go.gwu.edu/pythoncampdata', 'bookstore-data.json')\n",
"with open('bookstore-data.json') as f:\n",
" bkst_data = json.load(f)"
]
},
Expand Down
4 changes: 2 additions & 2 deletions textbook/notebooks/lessons/1_1_choreographing_code.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@
"source": [
"course_info = \"CHEM 1012\"\n",
"dept_code = course_info[0:4]\n",
"print(dept_code)"
"dept_code"
]
},
{
Expand Down Expand Up @@ -459,5 +459,5 @@
}
},
"nbformat": 4,
"nbformat_minor": 1
"nbformat_minor": 4
}
28 changes: 20 additions & 8 deletions textbook/notebooks/lessons/1_2_from_data_to_code.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,17 @@
"\n",
"Over the next few days, we'll be working together on a dataset containing information about textbooks assigned by courses at GW for the Summer 2023 semester. \n",
"\n",
"This dataset might lend itself to uses like the following:\n",
" - Identifying courses with particularly high-cost textbooks\n",
" - Calculating the average cost of textbooks by instructor, department, etc.\n",
" - Identifying the publishers that supply the majority of textbooks used at GW\n",
" - Identifying instructors who assign textbooks they themselves have authored\n",
"\n",
"As you work through this exercise, make a note of any additional uses you can imagine for this data. These notes will come in handy later!\n",
"\n",
"### Source\n",
"\n",
"This dataset was obtained by scraping the [GW Bookstore](https://www.bkstr.com/georgewashingtonstore/shop/textbooks-and-course-materials) website. Because [web scraping](https://library.gwu.edu/events/web-scraping-what-you-need-know-2023-10-03) is a rather advanced topic, we won't be covering that process in Python Camp.\n",
"This dataset was obtained by scraping the [GW Bookstore](https://www.bkstr.com/georgewashingtonstore/shop/textbooks-and-course-materials) website. Because [web scraping](https://learning.oreilly.com/library/view/web-scraping-with/9781098145347/) is a rather advanced topic, we won't be covering that process in Python Camp.\n",
"\n",
"The dataset was also pre-processed to simplify it somewhat (removing extraneous and redundant elements, etc.).\n",
"\n",
Expand All @@ -166,13 +174,15 @@
"source": [
"### Loading the data\n",
"\n",
"The code below will load data from an external file located in a directory called `data`. The directory is relative to the current directory (in which this notebook lives).\n",
"The code below will fetch data from a URL and save it locally as a file before loading the data in your notebook.\n",
"\n",
"1. We {term}`import` a Python module called `json`. A module is just some external Python code that provides a particular functionality. The `json` module allows us to convert data in JSON format to Python types. (More on types below).\n",
"2. We use the `open` function to open a file in a directory called `data`. The file is called `bookstore-data-summer-2023.json`, where the `.json` extension indicates that this is a JSON-formatted file. (The file extension is part of the filename, like `docx` for Word documents or `.xlsx` for Excel spreadsheets.) \n",
"3. The file is assigned to the temporary variable `f`.\n",
"4. We use the `json.load` {term}`method` to read the file (`f`). This method is specifically designed for JSON files; it won't work if the file does not contain data in valid JSON format. \n",
"5. The contents of the file, as processed by `json.load`, are assigned to a new variable, `bkst_data`."
"1. We {term}`import` a Python function called `urlretrieve` and a Python module called `json`. A module is just some external Python code that provides a particular functionality.\n",
" - The `urlretrieve` function allows us to fetch data from a remote source and save a local copy.\n",
" - The `json` module allows us to convert data in JSON format to Python types. (More on types below).\n",
"3. We use the `open` function to open a file in a directory called `data`. The file is called `bookstore-data-summer-2023.json`, where the `.json` extension indicates that this is a JSON-formatted file. (The file extension is part of the filename, like `docx` for Word documents or `.xlsx` for Excel spreadsheets.) \n",
"4. The file is assigned to the temporary variable `f`.\n",
"5. We use the `json.load` {term}`method` to read the file (`f`). This method is specifically designed for JSON files; it won't work if the file does not contain data in valid JSON format. \n",
"6. The contents of the file, as processed by `json.load`, are assigned to a new variable, `bkst_data`."
]
},
{
Expand All @@ -181,8 +191,10 @@
"metadata": {},
"outputs": [],
"source": [
"from urllib.request import urlretrieve\n",
"import json\n",
"with open('../../../data/bookstore-data-summer-2023.json') as f:\n",
"urlretrieve('https://go.gwu.edu/pythoncampdata', 'bookstore-data.json')\n",
"with open('bookstore-data.json') as f:\n",
" bkst_data = json.load(f)"
]
},
Expand Down
4 changes: 2 additions & 2 deletions textbook/notebooks/lessons/2_1_describing_the_team.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
"#### Dictionary template\n",
"\n",
"```\n",
"dolsy = {'name': 'Dolsy Smith,\n",
"dolsy = {'name': 'Dolsy Smith',\n",
" 'job_title': 'Software Developer/Librarian',\n",
" 'gw_unit': 'GW Libraries & Academic Innovation',\n",
" 'email_address': '[email protected]'}\n",
Expand Down Expand Up @@ -342,7 +342,7 @@
"source": [
"### Saving a list of dictionaries in JSON format\n",
"\n",
"Now let's save our database to disk. We'll use the `json` library and the `open` function as we did on Day 1 (to load the GW Bookstore dataset), except that this time we'll be **writing** to the file, not reading from it.\n",
"Now let's save our database to disk. We'll use the `json` module and the `open` function as we did on Day 1 (to load the GW Bookstore dataset), except that this time we'll be **writing** to the file, not reading from it.\n",
"\n",
"First we {term}`import` the `json` library."
]
Expand Down
4 changes: 3 additions & 1 deletion textbook/notebooks/lessons/2_2_querying_data.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -377,8 +377,10 @@
"metadata": {},
"outputs": [],
"source": [
"from urllib.request import urlretrieve\n",
"import json\n",
"with open('../../../data/bookstore-data-summer-2023.json') as f:\n",
"urlretrieve('https://go.gwu.edu/pythoncampdata', 'bookstore-data.json')\n",
"with open('bookstore-data.json') as f:\n",
" bkst_data = json.load(f)"
]
},
Expand Down
4 changes: 3 additions & 1 deletion textbook/notebooks/lessons/3_1_from_story_to_code.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,10 @@
"outputs": [],
"source": [
"# As usual, we need to load the bookstore dataset as JSON before we can work with it\n",
"from urllib.request import urlretrieve\n",
"import json\n",
"with open('../../../data/bookstore-data-summer-2023.json') as f:\n",
"urlretrieve('https://go.gwu.edu/pythoncampdata', 'bookstore-data.json')\n",
"with open('bookstore-data.json') as f:\n",
" bkst_data = json.load(f)"
]
},
Expand Down
4 changes: 3 additions & 1 deletion textbook/notebooks/lessons/4_1_modeling_the_world.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -626,8 +626,10 @@
"metadata": {},
"outputs": [],
"source": [
"from urllib.request import urlretrieve\n",
"import json\n",
"with open('../../../data/bookstore-data-summer-2023.json') as f:\n",
"urlretrieve('https://go.gwu.edu/pythoncampdata', 'bookstore-data.json')\n",
"with open('bookstore-data.json') as f:\n",
" bkst_data = json.load(f)"
]
},
Expand Down
4 changes: 3 additions & 1 deletion textbook/parsons-yaml/homework-2-GR.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
python_setup: |
courses = ['CHEM 1001 10', 'CHEM 1002, 10', 'CHEM 1002 11', 'BISC 1100 10', 'BISC 1102 10', 'PSC 2001 10',
'PSC 2001 11', 'PSC 2001 12', 'WSTU 6999 10', 'WSTU 6999 11']
python_code: |
courses = ['CHEM 1001 10', 'CHEM 1002, 10', 'CHEM 1002 11', 'BISC 1100 10']
courses_db = []
for course in courses:
course_info = course.split()
Expand Down

0 comments on commit f91b6a6

Please sign in to comment.