Skip to content

Commit caaf662

Browse files
authored
Add black formatting to Jupyter Notebooks (#291)
* Add Jupyter dependencies to black * Reformat Jupyter Notebooks
1 parent 66f13a7 commit caaf662

File tree

15 files changed

+289
-308
lines changed

15 files changed

+289
-308
lines changed

build-a-web-scraper/01_inspect.ipynb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1718,6 +1718,7 @@
17181718
],
17191719
"source": [
17201720
"from IPython.display import HTML\n",
1721+
"\n",
17211722
"HTML(\"https://www.indeed.com/jobs?q=python&l=new+york\")"
17221723
]
17231724
},

build-a-web-scraper/02_scrape.ipynb

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
"outputs": [],
6363
"source": [
6464
"# let's try a string search\n",
65-
"loc = str(response.content).find('python')\n",
65+
"loc = str(response.content).find(\"python\")\n",
6666
"loc"
6767
]
6868
},
@@ -72,7 +72,7 @@
7272
"metadata": {},
7373
"outputs": [],
7474
"source": [
75-
"response.content[loc-10:loc+10]"
75+
"response.content[loc - 10 : loc + 10]"
7676
]
7777
},
7878
{
@@ -83,7 +83,8 @@
8383
"source": [
8484
"# what about regex?\n",
8585
"import re\n",
86-
"re.findall(r'python', str(response.content))"
86+
"\n",
87+
"re.findall(r\"python\", str(response.content))"
8788
]
8889
},
8990
{
@@ -110,7 +111,7 @@
110111
"metadata": {},
111112
"outputs": [],
112113
"source": [
113-
"res = requests.get('https://api.github.com/user')"
114+
"res = requests.get(\"https://api.github.com/user\")"
114115
]
115116
},
116117
{
@@ -148,7 +149,7 @@
148149
"metadata": {},
149150
"outputs": [],
150151
"source": [
151-
"res = requests.get('https://twitter.com/search?q=realpython')"
152+
"res = requests.get(\"https://twitter.com/search?q=realpython\")"
152153
]
153154
},
154155
{

build-a-web-scraper/03_parse.ipynb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1380,7 +1380,7 @@
13801380
"metadata": {},
13811381
"outputs": [],
13821382
"source": [
1383-
"results = soup.find(id='resultsCol')"
1383+
"results = soup.find(id=\"resultsCol\")"
13841384
]
13851385
},
13861386
{
@@ -1950,7 +1950,7 @@
19501950
"metadata": {},
19511951
"outputs": [],
19521952
"source": [
1953-
"jobs = results.find_all('div', class_='result')"
1953+
"jobs = results.find_all(\"div\", class_=\"result\")"
19541954
]
19551955
},
19561956
{
@@ -2053,7 +2053,7 @@
20532053
}
20542054
],
20552055
"source": [
2056-
"title = jobs[0].find('h2')\n",
2056+
"title = jobs[0].find(\"h2\")\n",
20572057
"title"
20582058
]
20592059
},
@@ -2075,7 +2075,7 @@
20752075
}
20762076
],
20772077
"source": [
2078-
"title_link = title.find('a')\n",
2078+
"title_link = title.find(\"a\")\n",
20792079
"title_link"
20802080
]
20812081
},
@@ -2134,7 +2134,7 @@
21342134
"metadata": {},
21352135
"outputs": [],
21362136
"source": [
2137-
"job_titles = [job.find('h2').find('a').text.strip() for job in jobs]"
2137+
"job_titles = [job.find(\"h2\").find(\"a\").text.strip() for job in jobs]"
21382138
]
21392139
},
21402140
{
@@ -2213,7 +2213,7 @@
22132213
}
22142214
],
22152215
"source": [
2216-
"title_link['href']"
2216+
"title_link[\"href\"]"
22172217
]
22182218
},
22192219
{
@@ -2241,7 +2241,7 @@
22412241
],
22422242
"source": [
22432243
"base_url = \"https://www.indeed.com\"\n",
2244-
"job_url = base_url + title_link['href']\n",
2244+
"job_url = base_url + title_link[\"href\"]\n",
22452245
"job_url"
22462246
]
22472247
},

build-a-web-scraper/05_pipeline_solution.ipynb

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
"metadata": {},
7070
"outputs": [],
7171
"source": [
72-
"page = requests.get('https://www.indeed.com/jobs?q=python&l=new+york')"
72+
"page = requests.get(\"https://www.indeed.com/jobs?q=python&l=new+york\")"
7373
]
7474
},
7575
{
@@ -101,7 +101,9 @@
101101
"metadata": {},
102102
"outputs": [],
103103
"source": [
104-
"page_2 = requests.get('https://www.indeed.com/jobs?q=python&l=new+york&start=20')"
104+
"page_2 = requests.get(\n",
105+
" \"https://www.indeed.com/jobs?q=python&l=new+york&start=20\"\n",
106+
")"
105107
]
106108
},
107109
{
@@ -119,9 +121,9 @@
119121
"source": [
120122
"def get_jobs(page=1):\n",
121123
" \"\"\"Fetches the HTML from a search for Python jobs in New York on Indeed.com from a specified page.\"\"\"\n",
122-
" base_url_indeed = 'https://www.indeed.com/jobs?q=python&l=new+york&start='\n",
123-
" results_start_num = page*10\n",
124-
" url = f'{base_url_indeed}{results_start_num}'\n",
124+
" base_url_indeed = \"https://www.indeed.com/jobs?q=python&l=new+york&start=\"\n",
125+
" results_start_num = page * 10\n",
126+
" url = f\"{base_url_indeed}{results_start_num}\"\n",
125127
" page = requests.get(url)\n",
126128
" return page"
127129
]
@@ -159,10 +161,10 @@
159161
"source": [
160162
"def get_jobs(title, location, page=1):\n",
161163
" \"\"\"Fetches the HTML from a search for Python jobs in New York on Indeed.com from a specified page.\"\"\"\n",
162-
" loc = location.replace(' ', '+') # for multi-part locations\n",
163-
" base_url_indeed = f'https://www.indeed.com/jobs?q={title}&l={loc}&start='\n",
164-
" results_start_num = page*10\n",
165-
" url = f'{base_url_indeed}{results_start_num}'\n",
164+
" loc = location.replace(\" \", \"+\") # for multi-part locations\n",
165+
" base_url_indeed = f\"https://www.indeed.com/jobs?q={title}&l={loc}&start=\"\n",
166+
" results_start_num = page * 10\n",
167+
" url = f\"{base_url_indeed}{results_start_num}\"\n",
166168
" page = requests.get(url)\n",
167169
" return page"
168170
]
@@ -173,7 +175,7 @@
173175
"metadata": {},
174176
"outputs": [],
175177
"source": [
176-
"get_jobs('python', 'new york', 3)"
178+
"get_jobs(\"python\", \"new york\", 3)"
177179
]
178180
},
179181
{
@@ -209,7 +211,7 @@
209211
"metadata": {},
210212
"outputs": [],
211213
"source": [
212-
"site = get_jobs('python', 'new york')"
214+
"site = get_jobs(\"python\", \"new york\")"
213215
]
214216
},
215217
{
@@ -227,7 +229,7 @@
227229
"metadata": {},
228230
"outputs": [],
229231
"source": [
230-
"results = soup.find(id='resultsCol')"
232+
"results = soup.find(id=\"resultsCol\")"
231233
]
232234
},
233235
{
@@ -236,7 +238,7 @@
236238
"metadata": {},
237239
"outputs": [],
238240
"source": [
239-
"jobs = results.find_all('div', class_='result')"
241+
"jobs = results.find_all(\"div\", class_=\"result\")"
240242
]
241243
},
242244
{
@@ -252,7 +254,7 @@
252254
"metadata": {},
253255
"outputs": [],
254256
"source": [
255-
"job_titles = [job.find('h2').find('a').text.strip() for job in jobs]"
257+
"job_titles = [job.find(\"h2\").find(\"a\").text.strip() for job in jobs]"
256258
]
257259
},
258260
{
@@ -277,7 +279,7 @@
277279
"metadata": {},
278280
"outputs": [],
279281
"source": [
280-
"base_url = 'https://www.indeed.com'"
282+
"base_url = \"https://www.indeed.com\""
281283
]
282284
},
283285
{
@@ -286,7 +288,7 @@
286288
"metadata": {},
287289
"outputs": [],
288290
"source": [
289-
"job_links = [base_url + job.find('h2').find('a')['href'] for job in jobs]"
291+
"job_links = [base_url + job.find(\"h2\").find(\"a\")[\"href\"] for job in jobs]"
290292
]
291293
},
292294
{
@@ -311,7 +313,7 @@
311313
"metadata": {},
312314
"outputs": [],
313315
"source": [
314-
"job_locations = [job.find(class_='location').text for job in jobs]"
316+
"job_locations = [job.find(class_=\"location\").text for job in jobs]"
315317
]
316318
},
317319
{
@@ -339,23 +341,23 @@
339341
"def parse_info(soup):\n",
340342
" \"\"\"\n",
341343
" Parses HTML containing job postings and picks out job title, location, and link.\n",
342-
" \n",
344+
"\n",
343345
" args:\n",
344346
" soup (BeautifulSoup object): A parsed bs4.BeautifulSoup object of a search results page on indeed.com\n",
345-
" \n",
347+
"\n",
346348
" returns:\n",
347349
" job_list (list): A list of dictionaries containing the title, link, and location of each job posting\n",
348350
" \"\"\"\n",
349-
" results = soup.find(id='resultsCol')\n",
350-
" jobs = results.find_all('div', class_='result')\n",
351-
" base_url = 'https://www.indeed.com'\n",
351+
" results = soup.find(id=\"resultsCol\")\n",
352+
" jobs = results.find_all(\"div\", class_=\"result\")\n",
353+
" base_url = \"https://www.indeed.com\"\n",
352354
"\n",
353355
" job_list = list()\n",
354356
" for job in jobs:\n",
355-
" title = job.find('h2').find('a').text.strip()\n",
356-
" link = base_url + job.find('h2').find('a')['href']\n",
357-
" location = job.find(class_='location').text\n",
358-
" job_list.append({'title': title, 'link': link, 'location': location})\n",
357+
" title = job.find(\"h2\").find(\"a\").text.strip()\n",
358+
" link = base_url + job.find(\"h2\").find(\"a\")[\"href\"]\n",
359+
" location = job.find(class_=\"location\").text\n",
360+
" job_list.append({\"title\": title, \"link\": link, \"location\": location})\n",
359361
"\n",
360362
" return job_list"
361363
]
@@ -373,7 +375,7 @@
373375
"metadata": {},
374376
"outputs": [],
375377
"source": [
376-
"page = get_jobs('python', 'new_york')"
378+
"page = get_jobs(\"python\", \"new_york\")"
377379
]
378380
},
379381
{
@@ -418,7 +420,7 @@
418420
"source": [
419421
"def get_job_listings(title, location, amount=100):\n",
420422
" results = list()\n",
421-
" for page in range(amount//10):\n",
423+
" for page in range(amount // 10):\n",
422424
" site = get_jobs(title, location, page=page)\n",
423425
" soup = BeautifulSoup(site.content)\n",
424426
" page_results = parse_info(soup)\n",
@@ -432,7 +434,7 @@
432434
"metadata": {},
433435
"outputs": [],
434436
"source": [
435-
"r = get_job_listings('python', 'new york', 100)"
437+
"r = get_job_listings(\"python\", \"new york\", 100)"
436438
]
437439
},
438440
{

complex-numbers/bermuda.ipynb

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
"\n",
5050
"plt.style.use(\"seaborn\")\n",
5151
"\n",
52+
"\n",
5253
"def draw(\n",
5354
" vertices,\n",
5455
" xlim=(-90, 20),\n",
@@ -201,7 +202,10 @@
201202
}
202203
],
203204
"source": [
204-
"@interact(xoffset=IntSlider(min=-20, max=20, value=0, step=1), yoffset=IntSlider(min=-20, max=20, value=0, step=1))\n",
205+
"@interact(\n",
206+
" xoffset=IntSlider(min=-20, max=20, value=0, step=1),\n",
207+
" yoffset=IntSlider(min=-20, max=20, value=0, step=1),\n",
208+
")\n",
205209
"def translate(xoffset, yoffset):\n",
206210
" offset = complex(xoffset, yoffset)\n",
207211
" scaled_triangle = [vertex + offset for vertex in centered_triangle]\n",
@@ -243,16 +247,22 @@
243247
"def flip_horizontally(z: complex) -> complex:\n",
244248
" return complex(-z.real, z.imag)\n",
245249
"\n",
250+
"\n",
246251
"def flip_vertically(z: complex) -> complex:\n",
247252
" return z.conjugate() # Alternatively: complex(z.real, -z.imag)\n",
248253
"\n",
254+
"\n",
249255
"@interact(horizontally=False, vertically=False)\n",
250256
"def flip(horizontally, vertically):\n",
251257
" flipped_triangle = centered_triangle\n",
252258
" if horizontally:\n",
253-
" flipped_triangle = [flip_horizontally(vertex) for vertex in flipped_triangle]\n",
259+
" flipped_triangle = [\n",
260+
" flip_horizontally(vertex) for vertex in flipped_triangle\n",
261+
" ]\n",
254262
" if vertically:\n",
255-
" flipped_triangle = [flip_vertically(vertex) for vertex in flipped_triangle]\n",
263+
" flipped_triangle = [\n",
264+
" flip_vertically(vertex) for vertex in flipped_triangle\n",
265+
" ]\n",
256266
" lim = (-20, 20)\n",
257267
" draw(flipped_triangle, xlim=lim, ylim=lim, letters=True)"
258268
]
@@ -328,15 +338,25 @@
328338
],
329339
"source": [
330340
"def rotate(z: complex, degrees: float) -> complex:\n",
331-
" return z * 1j**(degrees/90)\n",
341+
" return z * 1j ** (degrees / 90)\n",
342+
"\n",
332343
"\n",
333344
"@interact(angle=IntSlider(min=0, max=360, value=90, step=1))\n",
334345
"def show_rotate(angle):\n",
335-
" plt.gca().add_patch(plt.Circle((0, 0), 85, lw=1, edgecolor=\"silver\", facecolor=\"None\"))\n",
346+
" plt.gca().add_patch(\n",
347+
" plt.Circle((0, 0), 85, lw=1, edgecolor=\"silver\", facecolor=\"None\")\n",
348+
" )\n",
336349
" lim = (-100, 100)\n",
337350
" rotated_triangle = [rotate(vertex, angle) for vertex in triangle]\n",
338351
" draw(triangle, xlim=lim, ylim=lim, letters=True)\n",
339-
" draw(rotated_triangle, xlim=lim, ylim=lim, fill=\"firebrick\", stroke=\"maroon\", letters=True)"
352+
" draw(\n",
353+
" rotated_triangle,\n",
354+
" xlim=lim,\n",
355+
" ylim=lim,\n",
356+
" fill=\"firebrick\",\n",
357+
" stroke=\"maroon\",\n",
358+
" letters=True,\n",
359+
" )"
340360
]
341361
}
342362
],

0 commit comments

Comments
 (0)