8000 Add more sections. · dmirand/complete-python-course@d1141ac · GitHub
[go: up one dir, main page]

Skip to content

Commit d1141ac

Browse files
committed
Add more sections.
1 parent 23f1275 commit d1141ac

File tree

54 files changed

+1309
-152
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+1309
-152
lines changed
Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,208 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8" />
5+
<meta
6+
name="viewport"
7+
content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"
8+
/>
9+
10+
<title>Code</title>
11+
12+
<link rel="stylesheet" href="../css/reset.css" />
13+
<link rel="stylesheet" href="../css/reveal.css" />
14+
<link rel="stylesheet" href="../css/theme/teclado.css" />
15+
16+
<!-- Theme used for syntax highlighting of code -->
17+
<link rel="stylesheet" href="../lib/css/monokai.css" />
18+
19+
<!-- Printing and PDF exports -->
20+
<script>
21+
var link = document.createElement("link");
22+
link.rel = "stylesheet";
23+
link.type = "text/css";
24+
link.href = window.location.search.match(/print-pdf/gi)
25+
? "../css/print/pdf.css"
26+
: "../css/print/paper.css";
27+
document.getElementsByTagName("head")[0].appendChild(link);
28+
</script>
29+
</head>
30+
<body>
31+
<div class="reveal">
32+
<img src="../img/logo.svg" class="logo" />
33+
<div class="blog-link">https://blog.tecla.do</div>
34+
<div class="slides">
35+
<!-- Each slide is a `section`. Duplicate the whole thing and modify the code and `data-line-numbers` for highlighting. -->
36+
<section data-transition="none">
37+
<h1>Explicit waits</h1>
38+
<pre><code data-trim data-line-numbers>
39+
import time
40+
41+
time.sleep(5) # 5 seconds
42+
</code></pre>
43+
</section>
44+
<!-- End duplication -->
45+
46+
<section data-transition="slide-in none">
47+
<h1>Explicit waits</h1>
48+
<pre><code data-trim data-line-numbers="1-3">
49+
from selenium.webdriver.common.by import By
50+
from selenium.webdriver.support import expected_conditions
51+
from selenium.webdriver.support.wait import WebDriverWait
52+
53+
WebDriverWait(self.browser, 10).until(
54+
expected_conditions.presence_of_element_located(
55+
(By.CSS_SELECTOR, QuotesPageLocators.TAG_DROPDOWN_VALUE_OPTION)
56+
)
57+
)
58+
</code></pre>
59+
</section>
60+
61+
<section data-transition="none">
62+
<h1>Explicit waits</h1>
63+
<pre><code data-trim data-line-numbers="5">
64+
from selenium.webdriver.common.by import By
65+
from selenium.webdriver.support import expected_conditions
66+
from selenium.webdriver.support.wait import WebDriverWait
67+
68+
WebDriverWait(self.browser, 10).until(
69+
expected_conditions.presence_of_element_located(
70+
(By.CSS_SELECTOR, QuotesPageLocators.TAG_DROPDOWN_VALUE_OPTION)
71+
)
72+
)
73+
</code></pre>
74+
</section>
75+
76+
<section data-transition="none">
77+
<h1>Explicit waits</h1>
78+
<pre><code data-trim data-line-numbers="6">
79+
from selenium.webdriver.common.by import By
80+
from selenium.webdriver.support import expected_conditions
81+
from selenium.webdriver.support.wait import WebDriverWait
82+
83+
WebDriverWait(self.browser, 10).until(
84+
expected_conditions.presence_of_element_located(
85+
(By.CSS_SELECTOR, QuotesPageLocators.TAG_DROPDOWN_VALUE_OPTION)
86+
)
87+
)
88+
</code></pre>
89+
</section>
90+
91+
<section data-transition="none">
92+
<h1>Explicit waits</h1>
93+
<pre><code data-trim data-line-numbers="7">
94+
from selenium.webdriver.common.by import By
95+
from selenium.webdriver.support import expected_conditions
96+
from selenium.webdriver.support.wait import WebDriverWait
97+
98+
WebDriverWait(self.browser, 10).until(
99+
expected_conditions.presence_of_element_located(
100+
(By.CSS_SELECTOR, QuotesPageLocators.TAG_DROPDOWN_VALUE_OPTION)
101+
)
102+
)
103+
</code></pre>
104+
</section>
105+
106+
<section data-transition="slide-in none">
107+
<h1>Locators using By</h1>
108+
<pre><code data-trim data-line-numbers="3,8">
109+
from selenium.webdriver.common.by import By
110+
111+
TAG_DROPDOWN = "select#tag"
112+
JUST_ID = By.ID, "tag"
113+
114+
...
115+
116+
self.browser.find_element_by_css_selector(TAG_DROPDOWN)
117+
self.browser.find_element(By.CSS_SELECTOR, TAG_DROPDOWN)
118+
119+
self.browser.find_element_by_id("tag")
120+
self.browser.find_element(By.ID, "tag")
121+
self.browser.find_element(*JUST_ID)
122+
</code></pre>
123+
</section>
124+
125+
<section data-transition="none">
126+
<h1>Locators using By</h1>
127+
<pre><code data-trim data-line-numbers="3,9">
128+
from selenium.webdriver.common.by import By
129+
130+
TAG_DROPDOWN = "select#tag"
131+
JUST_ID = By.ID, "tag"
132+
133+
...
134+
135+
self.browser.find_element_by_css_selector(TAG_DROPDOWN)
136+
self.browser.find_element(By.CSS_SELECTOR, TAG_DROPDOWN)
137+
138+
self.browser.find_element_by_id("tag")
139+
self.browser.find_element(By.ID, "tag")
140+
self.browser.find_element(*JUST_ID)
141+
</code></pre>
142+
</section>
143+
144+
<section data-transition="none">
145+
<h1>Locators using By</h1>
146+
<pre><code data-trim data-line-numbers="4, 11-13">
147+
from selenium.webdriver.common.by import By
148+
149+
TAG_DROPDOWN = "select#tag"
150+
JUST_ID = By.ID, "tag"
151+
152+
...
153+
154+
self.browser.find_element_by_css_selector(TAG_DROPDOWN)
155+
self.browser.find_element(By.CSS_SELECTOR, TAG_DROPDOWN)
156+
157+
self.browser.find_element_by_id("tag")
158+
self.browser.find_element(By.ID, "tag")
159+
self.browser.find_element(*JUST_ID)
160+
</code></pre>
161+
</section>
162+
163+
<section>
164+
<h1>Other uses of By</h1>
165+
<pre><code data-trim>
166+
ID = "id"
167+
XPATH = "xpath"
168+
LINK_TEXT = "link text"
169+
PARTIAL_LINK_TEXT = "partial link text"
170+
NAME = "name"
171+
TAG_NAME = "tag name"
172+
CLASS_NAME = "class name"
173+
CSS_SELECTOR = "css selector"
174+
</code></pre>
175+
</section>
176+
177+
<section>
178+
<h1>Implicit waits</h1>
179+
<pre><code data-trim data-line-numbers="4">
180+
from selenium import webdriver
181+
182+
driver = webdriver.Chrome()
183+
driver.implicitly_wait(10) # seconds
184+
</code></pre>
185+
</section>
186+
</div>
187+
</div>
188+
189+
<script src="../js/reveal.js"></script>
190+
191+
<script>
192+
// More info about config & dependencies:
193+
// - https://github.com/hakimel/reveal.js#configuration
194+
// - https://github.com/hakimel/reveal.js#dependencies
195+
Reveal.initialize({
196+
width: "100%",
197+
height: "100%",
198+
margin: 0,
199+
dependencies: [
200+
{ src: "../plugin/markdown/marked.js" },
201+
{ src: "../plugin/markdown/markdown.js" },
202+
{ src: "../plugin/notes/notes.js", async: true },
203+
{ src: "../plugin/highlight/highlight.js", async: true }
204+
]
205+
});
206+
</script>
207+
</body>
208+
</html>

course_contents/12_browser_automation_selenium/lectures/11_adding_waits_to_our_code/pages/quotes_page.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import time
12
from typing import List
23
from selenium.webdriver.common.by import By
34
from selenium.webdriver.support import expected_conditions
@@ -60,8 +61,8 @@ def search_for_quotes(self, author_name: str, tag_name: str) -> List[QuoteParser
6061
)
6162
)
6263

63-
# Alternatively, implicit wait
64-
self.browser.implicitly_wait(10)
64+
# Alternatively, explicit wait
65+
time.sleep(10)
6566

6667
try:
6768
self.select_tag(tag_name)
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,2 @@
11
class QuotesPageLocators:
22
QUOTE = "div.quote"
3-
AUTHOR_DROPDOWN = "select#author"
4-
TAG_DROPDOWN = "select#tag"
5-
SEARCH_BUTTON = 'input[name="submit_button"]'
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
class QuotesPageLocators:
2-
QUOTE = 'div.quote'
2+
QUOTE = "div.quote"

course_contents/12_browser_automation_selenium/lectures/5_interacting_with_dropdowns/pages/quotes_page.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from typing import List
12
from selenium.webdriver.support.ui import Select
23

34
from locators.quotes_page_locators import QuotesPageLocators

course_contents/12_browser_automation_selenium/lectures/9_adding_some_error_handling/app.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@
1313
print(page.search_for_quotes(author, tag))
1414
except InvalidTagForAuthorError as e:
1515
print(e)
16-
except Exception:
16+
except Exception as e:
17+
print(e)
1718
print("An unknown error occurred. Please try again.")
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import requests
2+
3+
APP_ID = "c640347fae594fc5add36046c807b282"
4+
ENDPOINT = "https://openexchangerates.org/api/latest.json"
5+
6+
response = requests.get(f"{ENDPOINT}?app_id={APP_ID}")
7+
exchange_rates = response.json()
8+
9+
usd_amount = 1000
10+
gbp_amount = usd_amount * exchange_rates["rates"]["GBP"]
11+
12+
print(f"USD{usd_amount} is GBP{gbp_amount}")
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from libs.openexchange import OpenExchangeClient
2+
3+
APP_ID = "72dba35060b54cf9ad3ffbdc68de9174"
4+
5+
client = OpenExchangeClient(APP_ID)
6+
7+
usd_amount = 1000
8+
gbp_amount = client.convert(usd_amount, 'USD', 'GBP')
9+
10+
print(f"USD{usd_amount} is GBP{gbp_amount}")

course_contents/16_interacting_with_apis/lectures/4_creating_a_currency_exchange_library/libs/__init__.py

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import requests
2+
import functools
3+
4+
5+
class OpenExchangeClient:
6+
BASE_URL = "https://openexchangerates.org/api/"
7+
8+
def __init__(self, app_id):
9+
self.app_id = app_id
10+
11+
@property
12+
def latest(self):
13+
return requests.get(f"{self.BASE_URL}/latest.json?app_id={self.app_id}").json()
14+
15+
def convert(self, from_amount, from_currency, to_currency):
16+
rates = self.latest['rates']
17+
to_rate = rates[to_currency]
18+
19+
if from_currency == 'USD':
20+
return from_amount * to_rate
21+
else:
22+
from_in_usd = from_amount / rates[from_currency]
23+
return from_in_usd * to_rate
24+
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from libs.openexchange import OpenExchangeClient
2+
import time
3+
4+
5+
6+
APP_ID = "72dba35060b54cf9ad3ffbdc68de9174"
7+
8+
client = OpenExchangeClient(APP_ID)
9+
10+
usd_amount = 1000
11+
start = time.time()
12+
gbp_amount = client.convert(usd_amount, 'USD', 'GBP')
13+
print(f'First call took {time.time() - start} seconds.')
14+
15+
start = time.time()
16+
gbp_amount = client.convert(usd_amount, 'USD', 'GBP')
17+
gbp_amount = client.convert(usd_amount, 'USD', 'GBP')
18+
gbp_amount = client.convert(usd_amount, 'USD', 'GBP')
19+
gbp_amount = client.convert(usd_amount, 'USD', 'GBP')
20+
gbp_amount = client.convert(usd_amount, 'USD', 'GBP')
21+
gbp_amount = client.convert(usd_amount, 'USD', 'GBP')
22+
gbp_amount = client.convert(usd_amount, 'USD', 'GBP')
23+
gbp_amount = client.convert(usd_amount, 'USD', 'GBP')
24+
gbp_amount = client.convert(usd_amount, 'USD', 'GBP')
25+
gbp_amount = client.convert(usd_amount, 'USD', 'GBP')
26+
print(f'After, 10 calls took {time.time() - start} seconds.')
27+
28+
print(f"USD{usd_amount} is GBP{gbp_amount}")

course_contents/16_interacting_with_apis/lectures/5_caching_with_cachetools/libs/__init__.py

Whitespace-only changes.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import requests
2+
from cachetools import cached, TTLCache
3+
4+
5+
class OpenExchangeClient:
6+
BASE_URL = "https://openexchangerates.org/api/"
7+
8+
def __init__(self, app_id):
9+
self.app_id = app_id
10+
11+
@property
12+
@cached(cache=TTLCache(maxsize=2, ttl=900))
13+
def latest(self):
14+
return requests.get(f"{self.BASE_URL}/latest.json?app_id={self.app_id}").json()
15+
16+
def convert(self, from_amount, from_currency, to_currency):
17+
rates = self.latest['rates']
18+
to_rate = rates[to_currency]
19+
20+
if from_currency == 'USD':
21+
return from_amount * to_rate
22+
else:
23+
from_in_usd = from_amount / rates[from_currency]
24+
return from_in_usd * to_rate
25+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import functools
2+
import time
3+
4+
5+
@functools.lru_cache(2)
6+
def cached_function(value):
7+
for i in range(value):
8+
i ** value
9+
10+
11+
def timed():
12+
start = time.time()
13+
cached_function(4647)
14+
print(time.time() - start)
15+
16+
17+
timed()
18+
timed()

course_contents/19_gui_development_tkinter/lectures/10_saving_files/app.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ def create_file():
77
text_area.pack(fill="both", expand=True)
88

99
notebook.add(text_area, text="Untitled")
10-
notebook.pack(fill="both", expand=True)
1110
notebook.select(text_area)
1211

1312

@@ -16,8 +15,8 @@ def save_file():
1615

1716
try:
1817
filename = file_path.split("/")[-1]
19-
current = root.nametowidget(notebook.select())
20-
content = current.get("1.0", "end-1c")
18+
text_widget = root.nametowidget(notebook.select())
19+
content = text_widget.get("1.0", "end-1c")
2120

2221
with open(file_path, "w") as file:
2322
file.write(content)
@@ -47,6 +46,7 @@ def save_file():
4746
file_menu.add_command(label="Save", command=save_file)
4847

4948
notebook = ttk.Notebook(main)
49+
notebook.pack(fill="both", expand=True)
5050

5151
create_file()
5252

0 commit comments

Comments
 (0)
0