Spaces:
Running
Running
Commit ·
d2711ff
1
Parent(s): 3444b30
Implemented table search functionality
Browse files- .gitignore +1 -0
- 01_main.ipynb +100 -14
- __pycache__/main.cpython-312.pyc +0 -0
- _quarto.yml +1 -2
- _site/01_main.html +82 -33
- _site/search.json +1 -1
- main.py +15 -7
.gitignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
/.quarto/
|
01_main.ipynb
CHANGED
|
@@ -9,7 +9,7 @@
|
|
| 9 |
},
|
| 10 |
{
|
| 11 |
"cell_type": "code",
|
| 12 |
-
"execution_count":
|
| 13 |
"metadata": {},
|
| 14 |
"outputs": [
|
| 15 |
{
|
|
@@ -28,20 +28,20 @@
|
|
| 28 |
},
|
| 29 |
{
|
| 30 |
"cell_type": "code",
|
| 31 |
-
"execution_count":
|
| 32 |
"metadata": {},
|
| 33 |
"outputs": [],
|
| 34 |
"source": [
|
| 35 |
"#|export\n",
|
| 36 |
"import pandas as pd\n",
|
| 37 |
-
"from flask import Flask, redirect\n",
|
| 38 |
"from flask import render_template\n",
|
| 39 |
"import json"
|
| 40 |
]
|
| 41 |
},
|
| 42 |
{
|
| 43 |
"cell_type": "code",
|
| 44 |
-
"execution_count":
|
| 45 |
"metadata": {},
|
| 46 |
"outputs": [
|
| 47 |
{
|
|
@@ -50,7 +50,7 @@
|
|
| 50 |
"'contactdb.json'"
|
| 51 |
]
|
| 52 |
},
|
| 53 |
-
"execution_count":
|
| 54 |
"metadata": {},
|
| 55 |
"output_type": "execute_result"
|
| 56 |
}
|
|
@@ -129,7 +129,7 @@
|
|
| 129 |
},
|
| 130 |
{
|
| 131 |
"cell_type": "code",
|
| 132 |
-
"execution_count":
|
| 133 |
"metadata": {},
|
| 134 |
"outputs": [
|
| 135 |
{
|
|
@@ -177,7 +177,7 @@
|
|
| 177 |
" 'email': 'hannah.rodriguez@example.com'}]"
|
| 178 |
]
|
| 179 |
},
|
| 180 |
-
"execution_count":
|
| 181 |
"metadata": {},
|
| 182 |
"output_type": "execute_result"
|
| 183 |
}
|
|
@@ -189,7 +189,71 @@
|
|
| 189 |
},
|
| 190 |
{
|
| 191 |
"cell_type": "code",
|
| 192 |
-
"execution_count":
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 193 |
"metadata": {},
|
| 194 |
"outputs": [],
|
| 195 |
"source": [
|
|
@@ -199,7 +263,12 @@
|
|
| 199 |
" self.db = pd.read_json('contactdb.json')\n",
|
| 200 |
"\n",
|
| 201 |
" def search(self, q):\n",
|
| 202 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 203 |
"\n",
|
| 204 |
" def all(self):\n",
|
| 205 |
" return self.db.to_dict('records')"
|
|
@@ -207,7 +276,7 @@
|
|
| 207 |
},
|
| 208 |
{
|
| 209 |
"cell_type": "code",
|
| 210 |
-
"execution_count":
|
| 211 |
"metadata": {},
|
| 212 |
"outputs": [],
|
| 213 |
"source": [
|
|
@@ -218,7 +287,7 @@
|
|
| 218 |
},
|
| 219 |
{
|
| 220 |
"cell_type": "code",
|
| 221 |
-
"execution_count":
|
| 222 |
"metadata": {},
|
| 223 |
"outputs": [],
|
| 224 |
"source": [
|
|
@@ -231,7 +300,7 @@
|
|
| 231 |
},
|
| 232 |
{
|
| 233 |
"cell_type": "code",
|
| 234 |
-
"execution_count":
|
| 235 |
"metadata": {},
|
| 236 |
"outputs": [],
|
| 237 |
"source": [
|
|
@@ -239,14 +308,17 @@
|
|
| 239 |
"\n",
|
| 240 |
"@app.get(\"/contacts\")\n",
|
| 241 |
"def contacts():\n",
|
| 242 |
-
"
|
|
|
|
|
|
|
|
|
|
| 243 |
" # print(contact_set)\n",
|
| 244 |
" return render_template(\"index.html\", contact_set=contact_set)"
|
| 245 |
]
|
| 246 |
},
|
| 247 |
{
|
| 248 |
"cell_type": "code",
|
| 249 |
-
"execution_count":
|
| 250 |
"metadata": {},
|
| 251 |
"outputs": [],
|
| 252 |
"source": [
|
|
@@ -255,6 +327,20 @@
|
|
| 255 |
"nb_export(\"01_main.ipynb\", lib_path=\".\", name='main')"
|
| 256 |
]
|
| 257 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 258 |
{
|
| 259 |
"cell_type": "code",
|
| 260 |
"execution_count": null,
|
|
|
|
| 9 |
},
|
| 10 |
{
|
| 11 |
"cell_type": "code",
|
| 12 |
+
"execution_count": 55,
|
| 13 |
"metadata": {},
|
| 14 |
"outputs": [
|
| 15 |
{
|
|
|
|
| 28 |
},
|
| 29 |
{
|
| 30 |
"cell_type": "code",
|
| 31 |
+
"execution_count": 56,
|
| 32 |
"metadata": {},
|
| 33 |
"outputs": [],
|
| 34 |
"source": [
|
| 35 |
"#|export\n",
|
| 36 |
"import pandas as pd\n",
|
| 37 |
+
"from flask import Flask, redirect, request\n",
|
| 38 |
"from flask import render_template\n",
|
| 39 |
"import json"
|
| 40 |
]
|
| 41 |
},
|
| 42 |
{
|
| 43 |
"cell_type": "code",
|
| 44 |
+
"execution_count": 57,
|
| 45 |
"metadata": {},
|
| 46 |
"outputs": [
|
| 47 |
{
|
|
|
|
| 50 |
"'contactdb.json'"
|
| 51 |
]
|
| 52 |
},
|
| 53 |
+
"execution_count": 57,
|
| 54 |
"metadata": {},
|
| 55 |
"output_type": "execute_result"
|
| 56 |
}
|
|
|
|
| 129 |
},
|
| 130 |
{
|
| 131 |
"cell_type": "code",
|
| 132 |
+
"execution_count": 58,
|
| 133 |
"metadata": {},
|
| 134 |
"outputs": [
|
| 135 |
{
|
|
|
|
| 177 |
" 'email': 'hannah.rodriguez@example.com'}]"
|
| 178 |
]
|
| 179 |
},
|
| 180 |
+
"execution_count": 58,
|
| 181 |
"metadata": {},
|
| 182 |
"output_type": "execute_result"
|
| 183 |
}
|
|
|
|
| 189 |
},
|
| 190 |
{
|
| 191 |
"cell_type": "code",
|
| 192 |
+
"execution_count": 79,
|
| 193 |
+
"metadata": {},
|
| 194 |
+
"outputs": [
|
| 195 |
+
{
|
| 196 |
+
"data": {
|
| 197 |
+
"text/html": [
|
| 198 |
+
"<div>\n",
|
| 199 |
+
"<style scoped>\n",
|
| 200 |
+
" .dataframe tbody tr th:only-of-type {\n",
|
| 201 |
+
" vertical-align: middle;\n",
|
| 202 |
+
" }\n",
|
| 203 |
+
"\n",
|
| 204 |
+
" .dataframe tbody tr th {\n",
|
| 205 |
+
" vertical-align: top;\n",
|
| 206 |
+
" }\n",
|
| 207 |
+
"\n",
|
| 208 |
+
" .dataframe thead th {\n",
|
| 209 |
+
" text-align: right;\n",
|
| 210 |
+
" }\n",
|
| 211 |
+
"</style>\n",
|
| 212 |
+
"<table border=\"1\" class=\"dataframe\">\n",
|
| 213 |
+
" <thead>\n",
|
| 214 |
+
" <tr style=\"text-align: right;\">\n",
|
| 215 |
+
" <th></th>\n",
|
| 216 |
+
" <th>firstname</th>\n",
|
| 217 |
+
" <th>lastname</th>\n",
|
| 218 |
+
" <th>phone</th>\n",
|
| 219 |
+
" <th>email</th>\n",
|
| 220 |
+
" </tr>\n",
|
| 221 |
+
" </thead>\n",
|
| 222 |
+
" <tbody>\n",
|
| 223 |
+
" <tr>\n",
|
| 224 |
+
" <th>0</th>\n",
|
| 225 |
+
" <td>John</td>\n",
|
| 226 |
+
" <td>Doe</td>\n",
|
| 227 |
+
" <td>555-1234</td>\n",
|
| 228 |
+
" <td>john.doe@example.com</td>\n",
|
| 229 |
+
" </tr>\n",
|
| 230 |
+
" </tbody>\n",
|
| 231 |
+
"</table>\n",
|
| 232 |
+
"</div>"
|
| 233 |
+
],
|
| 234 |
+
"text/plain": [
|
| 235 |
+
" firstname lastname phone email\n",
|
| 236 |
+
"0 John Doe 555-1234 john.doe@example.com"
|
| 237 |
+
]
|
| 238 |
+
},
|
| 239 |
+
"execution_count": 79,
|
| 240 |
+
"metadata": {},
|
| 241 |
+
"output_type": "execute_result"
|
| 242 |
+
}
|
| 243 |
+
],
|
| 244 |
+
"source": [
|
| 245 |
+
"q = '1234'\n",
|
| 246 |
+
"# db[db['firstname'].str.lower().str.contains(q)]\n",
|
| 247 |
+
"predicate_firstname = db['firstname'].str.lower().str.contains(q.lower())\n",
|
| 248 |
+
"predicate_lastname = db['lastname'].str.lower().str.contains(q.lower())\n",
|
| 249 |
+
"predicate_phone = db['phone'].str.lower().str.contains(q.lower())\n",
|
| 250 |
+
"predicate_email= db['email'].str.lower().str.contains(q.lower())\n",
|
| 251 |
+
"db[predicate_firstname|predicate_lastname|predicate_phone|predicate_email]"
|
| 252 |
+
]
|
| 253 |
+
},
|
| 254 |
+
{
|
| 255 |
+
"cell_type": "code",
|
| 256 |
+
"execution_count": 80,
|
| 257 |
"metadata": {},
|
| 258 |
"outputs": [],
|
| 259 |
"source": [
|
|
|
|
| 263 |
" self.db = pd.read_json('contactdb.json')\n",
|
| 264 |
"\n",
|
| 265 |
" def search(self, q):\n",
|
| 266 |
+
" predicate_firstname = self.db['firstname'].str.lower().str.contains(q.lower())\n",
|
| 267 |
+
" predicate_lastname = self.db['lastname'].str.lower().str.contains(q.lower())\n",
|
| 268 |
+
" predicate_phone = self.db['phone'].str.lower().str.contains(q.lower())\n",
|
| 269 |
+
" predicate_email= self.db['email'].str.lower().str.contains(q.lower())\n",
|
| 270 |
+
" filter_df = self.db[predicate_firstname|predicate_lastname|predicate_phone|predicate_email]\n",
|
| 271 |
+
" return filter_df.to_dict('records')\n",
|
| 272 |
"\n",
|
| 273 |
" def all(self):\n",
|
| 274 |
" return self.db.to_dict('records')"
|
|
|
|
| 276 |
},
|
| 277 |
{
|
| 278 |
"cell_type": "code",
|
| 279 |
+
"execution_count": 81,
|
| 280 |
"metadata": {},
|
| 281 |
"outputs": [],
|
| 282 |
"source": [
|
|
|
|
| 287 |
},
|
| 288 |
{
|
| 289 |
"cell_type": "code",
|
| 290 |
+
"execution_count": 82,
|
| 291 |
"metadata": {},
|
| 292 |
"outputs": [],
|
| 293 |
"source": [
|
|
|
|
| 300 |
},
|
| 301 |
{
|
| 302 |
"cell_type": "code",
|
| 303 |
+
"execution_count": 83,
|
| 304 |
"metadata": {},
|
| 305 |
"outputs": [],
|
| 306 |
"source": [
|
|
|
|
| 308 |
"\n",
|
| 309 |
"@app.get(\"/contacts\")\n",
|
| 310 |
"def contacts():\n",
|
| 311 |
+
" search = request.args.get(\"q\")\n",
|
| 312 |
+
" contact_set = None\n",
|
| 313 |
+
" if search is not None: contact_set = Contact().search(search)\n",
|
| 314 |
+
" else: contact_set = Contact().all()\n",
|
| 315 |
" # print(contact_set)\n",
|
| 316 |
" return render_template(\"index.html\", contact_set=contact_set)"
|
| 317 |
]
|
| 318 |
},
|
| 319 |
{
|
| 320 |
"cell_type": "code",
|
| 321 |
+
"execution_count": 84,
|
| 322 |
"metadata": {},
|
| 323 |
"outputs": [],
|
| 324 |
"source": [
|
|
|
|
| 327 |
"nb_export(\"01_main.ipynb\", lib_path=\".\", name='main')"
|
| 328 |
]
|
| 329 |
},
|
| 330 |
+
{
|
| 331 |
+
"cell_type": "code",
|
| 332 |
+
"execution_count": null,
|
| 333 |
+
"metadata": {},
|
| 334 |
+
"outputs": [],
|
| 335 |
+
"source": []
|
| 336 |
+
},
|
| 337 |
+
{
|
| 338 |
+
"cell_type": "code",
|
| 339 |
+
"execution_count": null,
|
| 340 |
+
"metadata": {},
|
| 341 |
+
"outputs": [],
|
| 342 |
+
"source": []
|
| 343 |
+
},
|
| 344 |
{
|
| 345 |
"cell_type": "code",
|
| 346 |
"execution_count": null,
|
__pycache__/main.cpython-312.pyc
CHANGED
|
Binary files a/__pycache__/main.cpython-312.pyc and b/__pycache__/main.cpython-312.pyc differ
|
|
|
_quarto.yml
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
ipynb-filters:
|
| 2 |
- nbdev_filter.py
|
| 3 |
-
|
| 4 |
project:
|
| 5 |
type: website
|
| 6 |
|
|
@@ -21,7 +21,6 @@ website:
|
|
| 21 |
- sidebar:API
|
| 22 |
- about.qmd
|
| 23 |
|
| 24 |
-
|
| 25 |
sidebar:
|
| 26 |
- id: API
|
| 27 |
title: API
|
|
|
|
| 1 |
ipynb-filters:
|
| 2 |
- nbdev_filter.py
|
| 3 |
+
|
| 4 |
project:
|
| 5 |
type: website
|
| 6 |
|
|
|
|
| 21 |
- sidebar:API
|
| 22 |
- about.qmd
|
| 23 |
|
|
|
|
| 24 |
sidebar:
|
| 25 |
- id: API
|
| 26 |
title: API
|
_site/01_main.html
CHANGED
|
@@ -57,7 +57,7 @@ pre > code.sourceCode > span > a:first-child::before { text-decoration: underlin
|
|
| 57 |
</style>
|
| 58 |
|
| 59 |
|
| 60 |
-
<script src="site_libs/quarto-nav/quarto-nav.js"></script>
|
| 61 |
<script src="site_libs/quarto-nav/headroom.min.js"></script>
|
| 62 |
<script src="site_libs/clipboard/clipboard.min.js"></script>
|
| 63 |
<script src="site_libs/quarto-search/autocomplete.umd.js"></script>
|
|
@@ -100,6 +100,9 @@ pre > code.sourceCode > span > a:first-child::before { text-decoration: underlin
|
|
| 100 |
"search-label": "Search"
|
| 101 |
}
|
| 102 |
}</script>
|
|
|
|
|
|
|
|
|
|
| 103 |
|
| 104 |
|
| 105 |
<link rel="stylesheet" href="styles.css">
|
|
@@ -195,20 +198,20 @@ pre > code.sourceCode > span > a:first-child::before { text-decoration: underlin
|
|
| 195 |
|
| 196 |
|
| 197 |
<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->
|
| 198 |
-
<div id="cell-2" class="cell" data-execution_count="
|
| 199 |
<div class="sourceCode cell-code" id="cb1"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
| 200 |
<div class="cell-output cell-output-stdout">
|
| 201 |
<pre><code>The autoreload extension is already loaded. To reload it, use:
|
| 202 |
%reload_ext autoreload</code></pre>
|
| 203 |
</div>
|
| 204 |
</div>
|
| 205 |
-
<div id="cell-3" class="cell" data-execution_count="
|
| 206 |
<div class="sourceCode cell-code" id="cb3"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a><span class="im">import</span> pandas <span class="im">as</span> pd</span>
|
| 207 |
-
<span id="cb3-2"><a href="#cb3-2" aria-hidden="true" tabindex="-1"></a><span class="im">from</span> flask <span class="im">import</span> Flask, redirect</span>
|
| 208 |
<span id="cb3-3"><a href="#cb3-3" aria-hidden="true" tabindex="-1"></a><span class="im">from</span> flask <span class="im">import</span> render_template</span>
|
| 209 |
<span id="cb3-4"><a href="#cb3-4" aria-hidden="true" tabindex="-1"></a><span class="im">import</span> json</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
| 210 |
</div>
|
| 211 |
-
<div id="cell-4" class="cell" data-execution_count="
|
| 212 |
<div class="sourceCode cell-code" id="cb4"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a>people <span class="op">=</span> [</span>
|
| 213 |
<span id="cb4-2"><a href="#cb4-2" aria-hidden="true" tabindex="-1"></a> {</span>
|
| 214 |
<span id="cb4-3"><a href="#cb4-3" aria-hidden="true" tabindex="-1"></a> <span class="st">"firstname"</span>: <span class="st">"John"</span>,</span>
|
|
@@ -278,14 +281,14 @@ pre > code.sourceCode > span > a:first-child::before { text-decoration: underlin
|
|
| 278 |
<span id="cb4-67"><a href="#cb4-67" aria-hidden="true" tabindex="-1"></a> json.dump(people, json_file, indent<span class="op">=</span><span class="dv">4</span>)</span>
|
| 279 |
<span id="cb4-68"><a href="#cb4-68" aria-hidden="true" tabindex="-1"></a></span>
|
| 280 |
<span id="cb4-69"><a href="#cb4-69" aria-hidden="true" tabindex="-1"></a>file_path</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
| 281 |
-
<div class="cell-output cell-output-display" data-execution_count="
|
| 282 |
<pre><code>'contactdb.json'</code></pre>
|
| 283 |
</div>
|
| 284 |
</div>
|
| 285 |
-
<div id="cell-5" class="cell" data-execution_count="
|
| 286 |
<div class="sourceCode cell-code" id="cb6"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a>db <span class="op">=</span> pd.read_json(<span class="st">'contactdb.json'</span>)</span>
|
| 287 |
<span id="cb6-2"><a href="#cb6-2" aria-hidden="true" tabindex="-1"></a>db.to_dict(<span class="st">'records'</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
| 288 |
-
<div class="cell-output cell-output-display" data-execution_count="
|
| 289 |
<pre><code>[{'firstname': 'John',
|
| 290 |
'lastname': 'Doe',
|
| 291 |
'phone': '555-1234',
|
|
@@ -328,35 +331,81 @@ pre > code.sourceCode > span > a:first-child::before { text-decoration: underlin
|
|
| 328 |
'email': 'hannah.rodriguez@example.com'}]</code></pre>
|
| 329 |
</div>
|
| 330 |
</div>
|
| 331 |
-
<div id="cell-6" class="cell" data-execution_count="
|
| 332 |
-
<div class="sourceCode cell-code" id="cb8"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb8-1"><a href="#cb8-1" aria-hidden="true" tabindex="-1"></a><span class="
|
| 333 |
-
<span id="cb8-2"><a href="#cb8-2" aria-hidden="true" tabindex="-1"></a>
|
| 334 |
-
<span id="cb8-3"><a href="#cb8-3" aria-hidden="true" tabindex="-1"></a>
|
| 335 |
-
<span id="cb8-4"><a href="#cb8-4" aria-hidden="true" tabindex="-1"></a></span>
|
| 336 |
-
<span id="cb8-5"><a href="#cb8-5" aria-hidden="true" tabindex="-1"></a>
|
| 337 |
-
<span id="cb8-6"><a href="#cb8-6" aria-hidden="true" tabindex="-1"></a>
|
| 338 |
-
<span id="cb8-7"><a href="#cb8-7" aria-hidden="true" tabindex="-1"></a></span>
|
| 339 |
-
<
|
| 340 |
-
<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 341 |
</div>
|
| 342 |
-
<div id="cell-
|
| 343 |
-
<div class="sourceCode cell-code" id="
|
| 344 |
</div>
|
| 345 |
-
<div id="cell-
|
| 346 |
-
<div class="sourceCode cell-code" id="
|
| 347 |
-
<span id="
|
| 348 |
-
<span id="
|
| 349 |
</div>
|
| 350 |
-
<div id="cell-
|
| 351 |
-
<div class="sourceCode cell-code" id="
|
| 352 |
-
<span id="
|
| 353 |
-
<span id="
|
| 354 |
-
<span id="
|
| 355 |
-
<span id="
|
|
|
|
|
|
|
|
|
|
| 356 |
</div>
|
| 357 |
-
<div id="cell-
|
| 358 |
-
<div class="sourceCode cell-code" id="
|
| 359 |
-
<span id="
|
| 360 |
</div>
|
| 361 |
|
| 362 |
|
|
|
|
| 57 |
</style>
|
| 58 |
|
| 59 |
|
| 60 |
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js" integrity="sha512-bLT0Qm9VnAYZDflyKcBaQ2gg0hSYNQrJ8RilYldYQ1FxQYoCLtUjuuRuZo+fjqhx/qtq/1itJ0C2ejDxltZVFg==" crossorigin="anonymous"></script><script src="site_libs/quarto-nav/quarto-nav.js"></script>
|
| 61 |
<script src="site_libs/quarto-nav/headroom.min.js"></script>
|
| 62 |
<script src="site_libs/clipboard/clipboard.min.js"></script>
|
| 63 |
<script src="site_libs/quarto-search/autocomplete.umd.js"></script>
|
|
|
|
| 100 |
"search-label": "Search"
|
| 101 |
}
|
| 102 |
}</script>
|
| 103 |
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.6/require.min.js" integrity="sha512-c3Nl8+7g4LMSTdrm621y7kf9v3SDPnhxLNhcjFJbKECVnmZHTdo+IRO05sNLTH/D3vA6u1X32ehoLC7WFVdheg==" crossorigin="anonymous"></script>
|
| 104 |
+
|
| 105 |
+
<script type="application/javascript">define('jquery', [],function() {return window.jQuery;})</script>
|
| 106 |
|
| 107 |
|
| 108 |
<link rel="stylesheet" href="styles.css">
|
|
|
|
| 198 |
|
| 199 |
|
| 200 |
<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->
|
| 201 |
+
<div id="cell-2" class="cell" data-execution_count="55">
|
| 202 |
<div class="sourceCode cell-code" id="cb1"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
| 203 |
<div class="cell-output cell-output-stdout">
|
| 204 |
<pre><code>The autoreload extension is already loaded. To reload it, use:
|
| 205 |
%reload_ext autoreload</code></pre>
|
| 206 |
</div>
|
| 207 |
</div>
|
| 208 |
+
<div id="cell-3" class="cell" data-execution_count="56">
|
| 209 |
<div class="sourceCode cell-code" id="cb3"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a><span class="im">import</span> pandas <span class="im">as</span> pd</span>
|
| 210 |
+
<span id="cb3-2"><a href="#cb3-2" aria-hidden="true" tabindex="-1"></a><span class="im">from</span> flask <span class="im">import</span> Flask, redirect, request</span>
|
| 211 |
<span id="cb3-3"><a href="#cb3-3" aria-hidden="true" tabindex="-1"></a><span class="im">from</span> flask <span class="im">import</span> render_template</span>
|
| 212 |
<span id="cb3-4"><a href="#cb3-4" aria-hidden="true" tabindex="-1"></a><span class="im">import</span> json</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
| 213 |
</div>
|
| 214 |
+
<div id="cell-4" class="cell" data-execution_count="57">
|
| 215 |
<div class="sourceCode cell-code" id="cb4"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a>people <span class="op">=</span> [</span>
|
| 216 |
<span id="cb4-2"><a href="#cb4-2" aria-hidden="true" tabindex="-1"></a> {</span>
|
| 217 |
<span id="cb4-3"><a href="#cb4-3" aria-hidden="true" tabindex="-1"></a> <span class="st">"firstname"</span>: <span class="st">"John"</span>,</span>
|
|
|
|
| 281 |
<span id="cb4-67"><a href="#cb4-67" aria-hidden="true" tabindex="-1"></a> json.dump(people, json_file, indent<span class="op">=</span><span class="dv">4</span>)</span>
|
| 282 |
<span id="cb4-68"><a href="#cb4-68" aria-hidden="true" tabindex="-1"></a></span>
|
| 283 |
<span id="cb4-69"><a href="#cb4-69" aria-hidden="true" tabindex="-1"></a>file_path</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
| 284 |
+
<div class="cell-output cell-output-display" data-execution_count="57">
|
| 285 |
<pre><code>'contactdb.json'</code></pre>
|
| 286 |
</div>
|
| 287 |
</div>
|
| 288 |
+
<div id="cell-5" class="cell" data-execution_count="58">
|
| 289 |
<div class="sourceCode cell-code" id="cb6"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a>db <span class="op">=</span> pd.read_json(<span class="st">'contactdb.json'</span>)</span>
|
| 290 |
<span id="cb6-2"><a href="#cb6-2" aria-hidden="true" tabindex="-1"></a>db.to_dict(<span class="st">'records'</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
| 291 |
+
<div class="cell-output cell-output-display" data-execution_count="58">
|
| 292 |
<pre><code>[{'firstname': 'John',
|
| 293 |
'lastname': 'Doe',
|
| 294 |
'phone': '555-1234',
|
|
|
|
| 331 |
'email': 'hannah.rodriguez@example.com'}]</code></pre>
|
| 332 |
</div>
|
| 333 |
</div>
|
| 334 |
+
<div id="cell-6" class="cell" data-execution_count="79">
|
| 335 |
+
<div class="sourceCode cell-code" id="cb8"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb8-1"><a href="#cb8-1" aria-hidden="true" tabindex="-1"></a>q <span class="op">=</span> <span class="st">'1234'</span></span>
|
| 336 |
+
<span id="cb8-2"><a href="#cb8-2" aria-hidden="true" tabindex="-1"></a><span class="co"># db[db['firstname'].str.lower().str.contains(q)]</span></span>
|
| 337 |
+
<span id="cb8-3"><a href="#cb8-3" aria-hidden="true" tabindex="-1"></a>predicate_firstname <span class="op">=</span> db[<span class="st">'firstname'</span>].<span class="bu">str</span>.lower().<span class="bu">str</span>.contains(q.lower())</span>
|
| 338 |
+
<span id="cb8-4"><a href="#cb8-4" aria-hidden="true" tabindex="-1"></a>predicate_lastname <span class="op">=</span> db[<span class="st">'lastname'</span>].<span class="bu">str</span>.lower().<span class="bu">str</span>.contains(q.lower())</span>
|
| 339 |
+
<span id="cb8-5"><a href="#cb8-5" aria-hidden="true" tabindex="-1"></a>predicate_phone <span class="op">=</span> db[<span class="st">'phone'</span>].<span class="bu">str</span>.lower().<span class="bu">str</span>.contains(q.lower())</span>
|
| 340 |
+
<span id="cb8-6"><a href="#cb8-6" aria-hidden="true" tabindex="-1"></a>predicate_email<span class="op">=</span> db[<span class="st">'email'</span>].<span class="bu">str</span>.lower().<span class="bu">str</span>.contains(q.lower())</span>
|
| 341 |
+
<span id="cb8-7"><a href="#cb8-7" aria-hidden="true" tabindex="-1"></a>db[predicate_firstname<span class="op">|</span>predicate_lastname<span class="op">|</span>predicate_phone<span class="op">|</span>predicate_email]</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
| 342 |
+
<div class="cell-output cell-output-display" data-execution_count="79">
|
| 343 |
+
<div>
|
| 344 |
+
<div>
|
| 345 |
+
|
| 346 |
+
|
| 347 |
+
<table class="dataframe table table-sm table-striped small" data-quarto-postprocess="true" data-border="1">
|
| 348 |
+
<thead>
|
| 349 |
+
<tr class="header">
|
| 350 |
+
<th data-quarto-table-cell-role="th"></th>
|
| 351 |
+
<th data-quarto-table-cell-role="th">firstname</th>
|
| 352 |
+
<th data-quarto-table-cell-role="th">lastname</th>
|
| 353 |
+
<th data-quarto-table-cell-role="th">phone</th>
|
| 354 |
+
<th data-quarto-table-cell-role="th">email</th>
|
| 355 |
+
</tr>
|
| 356 |
+
</thead>
|
| 357 |
+
<tbody>
|
| 358 |
+
<tr class="odd">
|
| 359 |
+
<td data-quarto-table-cell-role="th">0</td>
|
| 360 |
+
<td>John</td>
|
| 361 |
+
<td>Doe</td>
|
| 362 |
+
<td>555-1234</td>
|
| 363 |
+
<td>john.doe@example.com</td>
|
| 364 |
+
</tr>
|
| 365 |
+
</tbody>
|
| 366 |
+
</table>
|
| 367 |
+
|
| 368 |
+
</div>
|
| 369 |
+
</div>
|
| 370 |
+
</div>
|
| 371 |
+
</div>
|
| 372 |
+
<div id="cell-7" class="cell" data-execution_count="80">
|
| 373 |
+
<div class="sourceCode cell-code" id="cb9"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb9-1"><a href="#cb9-1" aria-hidden="true" tabindex="-1"></a><span class="kw">class</span> Contact(<span class="bu">object</span>):</span>
|
| 374 |
+
<span id="cb9-2"><a href="#cb9-2" aria-hidden="true" tabindex="-1"></a> <span class="kw">def</span> <span class="fu">__init__</span>(<span class="va">self</span>) <span class="op">-></span> <span class="va">None</span>:</span>
|
| 375 |
+
<span id="cb9-3"><a href="#cb9-3" aria-hidden="true" tabindex="-1"></a> <span class="va">self</span>.db <span class="op">=</span> pd.read_json(<span class="st">'contactdb.json'</span>)</span>
|
| 376 |
+
<span id="cb9-4"><a href="#cb9-4" aria-hidden="true" tabindex="-1"></a></span>
|
| 377 |
+
<span id="cb9-5"><a href="#cb9-5" aria-hidden="true" tabindex="-1"></a> <span class="kw">def</span> search(<span class="va">self</span>, q):</span>
|
| 378 |
+
<span id="cb9-6"><a href="#cb9-6" aria-hidden="true" tabindex="-1"></a> predicate_firstname <span class="op">=</span> <span class="va">self</span>.db[<span class="st">'firstname'</span>].<span class="bu">str</span>.lower().<span class="bu">str</span>.contains(q.lower())</span>
|
| 379 |
+
<span id="cb9-7"><a href="#cb9-7" aria-hidden="true" tabindex="-1"></a> predicate_lastname <span class="op">=</span> <span class="va">self</span>.db[<span class="st">'lastname'</span>].<span class="bu">str</span>.lower().<span class="bu">str</span>.contains(q.lower())</span>
|
| 380 |
+
<span id="cb9-8"><a href="#cb9-8" aria-hidden="true" tabindex="-1"></a> predicate_phone <span class="op">=</span> <span class="va">self</span>.db[<span class="st">'phone'</span>].<span class="bu">str</span>.lower().<span class="bu">str</span>.contains(q.lower())</span>
|
| 381 |
+
<span id="cb9-9"><a href="#cb9-9" aria-hidden="true" tabindex="-1"></a> predicate_email<span class="op">=</span> <span class="va">self</span>.db[<span class="st">'email'</span>].<span class="bu">str</span>.lower().<span class="bu">str</span>.contains(q.lower())</span>
|
| 382 |
+
<span id="cb9-10"><a href="#cb9-10" aria-hidden="true" tabindex="-1"></a> filter_df <span class="op">=</span> <span class="va">self</span>.db[predicate_firstname<span class="op">|</span>predicate_lastname<span class="op">|</span>predicate_phone<span class="op">|</span>predicate_email]</span>
|
| 383 |
+
<span id="cb9-11"><a href="#cb9-11" aria-hidden="true" tabindex="-1"></a> <span class="cf">return</span> filter_df.to_dict(<span class="st">'records'</span>)</span>
|
| 384 |
+
<span id="cb9-12"><a href="#cb9-12" aria-hidden="true" tabindex="-1"></a></span>
|
| 385 |
+
<span id="cb9-13"><a href="#cb9-13" aria-hidden="true" tabindex="-1"></a> <span class="kw">def</span> <span class="bu">all</span>(<span class="va">self</span>):</span>
|
| 386 |
+
<span id="cb9-14"><a href="#cb9-14" aria-hidden="true" tabindex="-1"></a> <span class="cf">return</span> <span class="va">self</span>.db.to_dict(<span class="st">'records'</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
| 387 |
</div>
|
| 388 |
+
<div id="cell-8" class="cell" data-execution_count="81">
|
| 389 |
+
<div class="sourceCode cell-code" id="cb10"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb10-1"><a href="#cb10-1" aria-hidden="true" tabindex="-1"></a>app <span class="op">=</span> Flask(<span class="va">__name__</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
| 390 |
</div>
|
| 391 |
+
<div id="cell-9" class="cell" data-execution_count="82">
|
| 392 |
+
<div class="sourceCode cell-code" id="cb11"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb11-1"><a href="#cb11-1" aria-hidden="true" tabindex="-1"></a><span class="at">@app.get</span>(<span class="st">"/"</span>)</span>
|
| 393 |
+
<span id="cb11-2"><a href="#cb11-2" aria-hidden="true" tabindex="-1"></a><span class="kw">def</span> index():</span>
|
| 394 |
+
<span id="cb11-3"><a href="#cb11-3" aria-hidden="true" tabindex="-1"></a> <span class="cf">return</span> redirect(<span class="st">"/contacts"</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
| 395 |
</div>
|
| 396 |
+
<div id="cell-10" class="cell" data-execution_count="83">
|
| 397 |
+
<div class="sourceCode cell-code" id="cb12"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb12-1"><a href="#cb12-1" aria-hidden="true" tabindex="-1"></a><span class="at">@app.get</span>(<span class="st">"/contacts"</span>)</span>
|
| 398 |
+
<span id="cb12-2"><a href="#cb12-2" aria-hidden="true" tabindex="-1"></a><span class="kw">def</span> contacts():</span>
|
| 399 |
+
<span id="cb12-3"><a href="#cb12-3" aria-hidden="true" tabindex="-1"></a> search <span class="op">=</span> request.args.get(<span class="st">"q"</span>)</span>
|
| 400 |
+
<span id="cb12-4"><a href="#cb12-4" aria-hidden="true" tabindex="-1"></a> contact_set <span class="op">=</span> <span class="va">None</span></span>
|
| 401 |
+
<span id="cb12-5"><a href="#cb12-5" aria-hidden="true" tabindex="-1"></a> <span class="cf">if</span> search <span class="kw">is</span> <span class="kw">not</span> <span class="va">None</span>: contact_set <span class="op">=</span> Contact().search(search)</span>
|
| 402 |
+
<span id="cb12-6"><a href="#cb12-6" aria-hidden="true" tabindex="-1"></a> <span class="cf">else</span>: contact_set <span class="op">=</span> Contact().<span class="bu">all</span>()</span>
|
| 403 |
+
<span id="cb12-7"><a href="#cb12-7" aria-hidden="true" tabindex="-1"></a> <span class="co"># print(contact_set)</span></span>
|
| 404 |
+
<span id="cb12-8"><a href="#cb12-8" aria-hidden="true" tabindex="-1"></a> <span class="cf">return</span> render_template(<span class="st">"index.html"</span>, contact_set<span class="op">=</span>contact_set)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
| 405 |
</div>
|
| 406 |
+
<div id="cell-11" class="cell" data-execution_count="84">
|
| 407 |
+
<div class="sourceCode cell-code" id="cb13"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb13-1"><a href="#cb13-1" aria-hidden="true" tabindex="-1"></a><span class="im">from</span> nbdev.export <span class="im">import</span> nb_export</span>
|
| 408 |
+
<span id="cb13-2"><a href="#cb13-2" aria-hidden="true" tabindex="-1"></a>nb_export(<span class="st">"01_main.ipynb"</span>, lib_path<span class="op">=</span><span class="st">"."</span>, name<span class="op">=</span><span class="st">'main'</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
| 409 |
</div>
|
| 410 |
|
| 411 |
|
_site/search.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
| 4 |
"href": "01_main.html",
|
| 5 |
"title": "Main App",
|
| 6 |
"section": "",
|
| 7 |
-
"text": "The autoreload extension is already loaded. To reload it, use:\n %reload_ext autoreload\n\n\n\nimport pandas as pd\nfrom flask import Flask, redirect\nfrom flask import render_template\nimport json\n\n\npeople = [\n {\n \"firstname\": \"John\",\n \"lastname\": \"Doe\",\n \"phone\": \"555-1234\",\n \"email\": \"john.doe@example.com\"\n },\n {\n \"firstname\": \"Jane\",\n \"lastname\": \"Smith\",\n \"phone\": \"555-5678\",\n \"email\": \"jane.smith@example.com\"\n },\n {\n \"firstname\": \"Alice\",\n \"lastname\": \"Johnson\",\n \"phone\": \"555-8765\",\n \"email\": \"alice.johnson@example.com\"\n },\n {\n \"firstname\": \"Bob\",\n \"lastname\": \"Williams\",\n \"phone\": \"555-4321\",\n \"email\": \"bob.williams@example.com\"\n },\n {\n \"firstname\": \"Charlie\",\n \"lastname\": \"Brown\",\n \"phone\": \"555-9876\",\n \"email\": \"charlie.brown@example.com\"\n },\n {\n \"firstname\": \"Diana\",\n \"lastname\": \"Miller\",\n \"phone\": \"555-6543\",\n \"email\": \"diana.miller@example.com\"\n },\n {\n \"firstname\": \"Edward\",\n \"lastname\": \"Davis\",\n \"phone\": \"555-3456\",\n \"email\": \"edward.davis@example.com\"\n },\n {\n \"firstname\": \"Fiona\",\n \"lastname\": \"Garcia\",\n \"phone\": \"555-6789\",\n \"email\": \"fiona.garcia@example.com\"\n },\n {\n \"firstname\": \"George\",\n \"lastname\": \"Martinez\",\n \"phone\": \"555-7890\",\n \"email\": \"george.martinez@example.com\"\n },\n {\n \"firstname\": \"Hannah\",\n \"lastname\": \"Rodriguez\",\n \"phone\": \"555-8901\",\n \"email\": \"hannah.rodriguez@example.com\"\n }\n]\n\n# Writing the JSON data to a file\nfile_path = 'contactdb.json'\nwith open(file_path, 'w') as json_file:\n json.dump(people, json_file, indent=4)\n\nfile_path\n\n'contactdb.json'\n\n\n\ndb = pd.read_json('contactdb.json')\ndb.to_dict('records')\n\n[{'firstname': 'John',\n 'lastname': 'Doe',\n 'phone': '555-1234',\n 'email': 'john.doe@example.com'},\n {'firstname': 'Jane',\n 'lastname': 'Smith',\n 'phone': '555-5678',\n 'email': 'jane.smith@example.com'},\n {'firstname': 'Alice',\n 'lastname': 'Johnson',\n 'phone': '555-8765',\n 'email': 'alice.johnson@example.com'},\n {'firstname': 'Bob',\n 'lastname': 'Williams',\n 'phone': '555-4321',\n 'email': 'bob.williams@example.com'},\n {'firstname': 'Charlie',\n 'lastname': 'Brown',\n 'phone': '555-9876',\n 'email': 'charlie.brown@example.com'},\n {'firstname': 'Diana',\n 'lastname': 'Miller',\n 'phone': '555-6543',\n 'email': 'diana.miller@example.com'},\n {'firstname': 'Edward',\n 'lastname': 'Davis',\n 'phone': '555-3456',\n 'email': 'edward.davis@example.com'},\n {'firstname': 'Fiona',\n 'lastname': 'Garcia',\n 'phone': '555-6789',\n 'email': 'fiona.garcia@example.com'},\n {'firstname': 'George',\n 'lastname': 'Martinez',\n 'phone': '555-7890',\n 'email': 'george.martinez@example.com'},\n {'firstname': 'Hannah',\n 'lastname': 'Rodriguez',\n 'phone': '555-8901',\n 'email': 'hannah.rodriguez@example.com'}]\n\n\n\nclass Contact(object):\n def __init__(self) -> None:\n self.db = pd.read_json('contactdb.json')\n\n def search(self, q):\n
|
| 8 |
"crumbs": [
|
| 9 |
"Main App"
|
| 10 |
]
|
|
|
|
| 4 |
"href": "01_main.html",
|
| 5 |
"title": "Main App",
|
| 6 |
"section": "",
|
| 7 |
+
"text": "The autoreload extension is already loaded. To reload it, use:\n %reload_ext autoreload\n\n\n\nimport pandas as pd\nfrom flask import Flask, redirect, request\nfrom flask import render_template\nimport json\n\n\npeople = [\n {\n \"firstname\": \"John\",\n \"lastname\": \"Doe\",\n \"phone\": \"555-1234\",\n \"email\": \"john.doe@example.com\"\n },\n {\n \"firstname\": \"Jane\",\n \"lastname\": \"Smith\",\n \"phone\": \"555-5678\",\n \"email\": \"jane.smith@example.com\"\n },\n {\n \"firstname\": \"Alice\",\n \"lastname\": \"Johnson\",\n \"phone\": \"555-8765\",\n \"email\": \"alice.johnson@example.com\"\n },\n {\n \"firstname\": \"Bob\",\n \"lastname\": \"Williams\",\n \"phone\": \"555-4321\",\n \"email\": \"bob.williams@example.com\"\n },\n {\n \"firstname\": \"Charlie\",\n \"lastname\": \"Brown\",\n \"phone\": \"555-9876\",\n \"email\": \"charlie.brown@example.com\"\n },\n {\n \"firstname\": \"Diana\",\n \"lastname\": \"Miller\",\n \"phone\": \"555-6543\",\n \"email\": \"diana.miller@example.com\"\n },\n {\n \"firstname\": \"Edward\",\n \"lastname\": \"Davis\",\n \"phone\": \"555-3456\",\n \"email\": \"edward.davis@example.com\"\n },\n {\n \"firstname\": \"Fiona\",\n \"lastname\": \"Garcia\",\n \"phone\": \"555-6789\",\n \"email\": \"fiona.garcia@example.com\"\n },\n {\n \"firstname\": \"George\",\n \"lastname\": \"Martinez\",\n \"phone\": \"555-7890\",\n \"email\": \"george.martinez@example.com\"\n },\n {\n \"firstname\": \"Hannah\",\n \"lastname\": \"Rodriguez\",\n \"phone\": \"555-8901\",\n \"email\": \"hannah.rodriguez@example.com\"\n }\n]\n\n# Writing the JSON data to a file\nfile_path = 'contactdb.json'\nwith open(file_path, 'w') as json_file:\n json.dump(people, json_file, indent=4)\n\nfile_path\n\n'contactdb.json'\n\n\n\ndb = pd.read_json('contactdb.json')\ndb.to_dict('records')\n\n[{'firstname': 'John',\n 'lastname': 'Doe',\n 'phone': '555-1234',\n 'email': 'john.doe@example.com'},\n {'firstname': 'Jane',\n 'lastname': 'Smith',\n 'phone': '555-5678',\n 'email': 'jane.smith@example.com'},\n {'firstname': 'Alice',\n 'lastname': 'Johnson',\n 'phone': '555-8765',\n 'email': 'alice.johnson@example.com'},\n {'firstname': 'Bob',\n 'lastname': 'Williams',\n 'phone': '555-4321',\n 'email': 'bob.williams@example.com'},\n {'firstname': 'Charlie',\n 'lastname': 'Brown',\n 'phone': '555-9876',\n 'email': 'charlie.brown@example.com'},\n {'firstname': 'Diana',\n 'lastname': 'Miller',\n 'phone': '555-6543',\n 'email': 'diana.miller@example.com'},\n {'firstname': 'Edward',\n 'lastname': 'Davis',\n 'phone': '555-3456',\n 'email': 'edward.davis@example.com'},\n {'firstname': 'Fiona',\n 'lastname': 'Garcia',\n 'phone': '555-6789',\n 'email': 'fiona.garcia@example.com'},\n {'firstname': 'George',\n 'lastname': 'Martinez',\n 'phone': '555-7890',\n 'email': 'george.martinez@example.com'},\n {'firstname': 'Hannah',\n 'lastname': 'Rodriguez',\n 'phone': '555-8901',\n 'email': 'hannah.rodriguez@example.com'}]\n\n\n\nq = '1234'\n# db[db['firstname'].str.lower().str.contains(q)]\npredicate_firstname = db['firstname'].str.lower().str.contains(q.lower())\npredicate_lastname = db['lastname'].str.lower().str.contains(q.lower())\npredicate_phone = db['phone'].str.lower().str.contains(q.lower())\npredicate_email= db['email'].str.lower().str.contains(q.lower())\ndb[predicate_firstname|predicate_lastname|predicate_phone|predicate_email]\n\n\n\n\n\n\n\n\n\nfirstname\nlastname\nphone\nemail\n\n\n\n\n0\nJohn\nDoe\n555-1234\njohn.doe@example.com\n\n\n\n\n\n\n\n\n\nclass Contact(object):\n def __init__(self) -> None:\n self.db = pd.read_json('contactdb.json')\n\n def search(self, q):\n predicate_firstname = self.db['firstname'].str.lower().str.contains(q.lower())\n predicate_lastname = self.db['lastname'].str.lower().str.contains(q.lower())\n predicate_phone = self.db['phone'].str.lower().str.contains(q.lower())\n predicate_email= self.db['email'].str.lower().str.contains(q.lower())\n filter_df = self.db[predicate_firstname|predicate_lastname|predicate_phone|predicate_email]\n return filter_df.to_dict('records')\n\n def all(self):\n return self.db.to_dict('records')\n\n\napp = Flask(__name__)\n\n\n@app.get(\"/\")\ndef index():\n return redirect(\"/contacts\")\n\n\n@app.get(\"/contacts\")\ndef contacts():\n search = request.args.get(\"q\")\n contact_set = None\n if search is not None: contact_set = Contact().search(search)\n else: contact_set = Contact().all()\n # print(contact_set)\n return render_template(\"index.html\", contact_set=contact_set)\n\n\nfrom nbdev.export import nb_export\nnb_export(\"01_main.ipynb\", lib_path=\".\", name='main')",
|
| 8 |
"crumbs": [
|
| 9 |
"Main App"
|
| 10 |
]
|
main.py
CHANGED
|
@@ -5,32 +5,40 @@ __all__ = ['app', 'Contact', 'index', 'contacts']
|
|
| 5 |
|
| 6 |
# %% 01_main.ipynb 2
|
| 7 |
import pandas as pd
|
| 8 |
-
from flask import Flask, redirect
|
| 9 |
from flask import render_template
|
| 10 |
import json
|
| 11 |
|
| 12 |
-
# %% 01_main.ipynb
|
| 13 |
class Contact(object):
|
| 14 |
def __init__(self) -> None:
|
| 15 |
self.db = pd.read_json('contactdb.json')
|
| 16 |
|
| 17 |
def search(self, q):
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
def all(self):
|
| 21 |
return self.db.to_dict('records')
|
| 22 |
|
| 23 |
-
# %% 01_main.ipynb
|
| 24 |
app = Flask(__name__)
|
| 25 |
|
| 26 |
-
# %% 01_main.ipynb
|
| 27 |
@app.get("/")
|
| 28 |
def index():
|
| 29 |
return redirect("/contacts")
|
| 30 |
|
| 31 |
-
# %% 01_main.ipynb
|
| 32 |
@app.get("/contacts")
|
| 33 |
def contacts():
|
| 34 |
-
|
|
|
|
|
|
|
|
|
|
| 35 |
# print(contact_set)
|
| 36 |
return render_template("index.html", contact_set=contact_set)
|
|
|
|
| 5 |
|
| 6 |
# %% 01_main.ipynb 2
|
| 7 |
import pandas as pd
|
| 8 |
+
from flask import Flask, redirect, request
|
| 9 |
from flask import render_template
|
| 10 |
import json
|
| 11 |
|
| 12 |
+
# %% 01_main.ipynb 6
|
| 13 |
class Contact(object):
|
| 14 |
def __init__(self) -> None:
|
| 15 |
self.db = pd.read_json('contactdb.json')
|
| 16 |
|
| 17 |
def search(self, q):
|
| 18 |
+
predicate_firstname = self.db['firstname'].str.lower().str.contains(q.lower())
|
| 19 |
+
predicate_lastname = self.db['lastname'].str.lower().str.contains(q.lower())
|
| 20 |
+
predicate_phone = self.db['phone'].str.lower().str.contains(q.lower())
|
| 21 |
+
predicate_email= self.db['email'].str.lower().str.contains(q.lower())
|
| 22 |
+
filter_df = self.db[predicate_firstname|predicate_lastname|predicate_phone|predicate_email]
|
| 23 |
+
return filter_df.to_dict('records')
|
| 24 |
|
| 25 |
def all(self):
|
| 26 |
return self.db.to_dict('records')
|
| 27 |
|
| 28 |
+
# %% 01_main.ipynb 7
|
| 29 |
app = Flask(__name__)
|
| 30 |
|
| 31 |
+
# %% 01_main.ipynb 8
|
| 32 |
@app.get("/")
|
| 33 |
def index():
|
| 34 |
return redirect("/contacts")
|
| 35 |
|
| 36 |
+
# %% 01_main.ipynb 9
|
| 37 |
@app.get("/contacts")
|
| 38 |
def contacts():
|
| 39 |
+
search = request.args.get("q")
|
| 40 |
+
contact_set = None
|
| 41 |
+
if search is not None: contact_set = Contact().search(search)
|
| 42 |
+
else: contact_set = Contact().all()
|
| 43 |
# print(contact_set)
|
| 44 |
return render_template("index.html", contact_set=contact_set)
|