File size: 36,374 Bytes
03072a6 2636412 03072a6 2636412 03072a6 2636412 03072a6 2636412 c50e8c0 e5ce045 c50e8c0 e5ce045 c50e8c0 e5ce045 bc34042 52dd5fa bc34042 c50e8c0 bc34042 c50e8c0 bc34042 fc704ee 03072a6 093776c 03072a6 fc704ee 093776c bc34042 52dd5fa 753c675 52dd5fa 753c675 52dd5fa 753c675 52dd5fa 753c675 52dd5fa bc34042 093776c 52dd5fa 753c675 52dd5fa 753c675 52dd5fa 753c675 52dd5fa 093776c bc34042 52dd5fa 2636412 52dd5fa bc34042 093776c bc34042 093776c bc34042 52dd5fa bc34042 52dd5fa 093776c fc704ee 093776c 9a0691a 2636412 9a0691a 2636412 9a0691a 2636412 9a0691a 093776c 52dd5fa 2636412 03072a6 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 |
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"cmpsc\n",
"bfjps\n"
]
}
],
"source": [
"def removeVowels(s):\n",
" vowels = \"aeiouAEIOU\"\n",
" sWithoutVowels = \"\"\n",
" for eachChar in s:\n",
" if eachChar not in vowels:\n",
" sWithoutVowels = sWithoutVowels + eachChar\n",
" return sWithoutVowels\n",
"\n",
"print(removeVowels(\"compsci\"))\n",
"print(removeVowels(\"aAbEefIijOopUus\"))\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"\n",
"import smtplib\n",
"from email.mime.multipart import MIMEMultipart \n",
"server = smtplib.SMTP(\"smtp.office365.com\", 587)\n",
"server.starttls()\n",
"server.login('fyenneyenn@hotmail.com', 'NOmoreuse7-') \n",
"print('connecting...')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"try:\n",
" del config\n",
"except:\n",
" pass\n"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"try:\n",
" del config\n",
"except:\n",
" pass\n",
"from mail_sender import config\n",
"import smtplib\n",
"from email.mime.multipart import MIMEMultipart\n",
"from email.mime.text import MIMEText \n",
"from email.mime.base import MIMEBase\n",
"from email import encoders"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<smtplib.SMTP at 0x2425836deb0>"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"a = config()\n",
"a.server"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"def parchecker(str1):\n",
" s = []\n",
" bal = True\n",
" index = 0\n",
" while index < len(str1) and bal:\n",
" symbol = str1[index]\n",
" print(s, symbol, 'aaaaaaaa')\n",
" if symbol == \"(\":\n",
" s.append(symbol) # -- 只有 ( 入栈\n",
" else:\n",
" if s == []:\n",
" bal = False\n",
" else:\n",
" s.pop() # -- 有一个 ) 则pop 一个\n",
" index += 1\n",
" \n",
" if bal and s == []:\n",
" return True \n",
" else:\n",
" return False"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [],
"source": [
"def parchecker(str1):\n",
" s = []\n",
" bal = True\n",
" index = 0\n",
" while index < len(str1) and bal:\n",
" symbol = str1[index] \n",
" # ============================================================================ #\n",
" # 前括号 #\n",
" # ============================================================================ #\n",
" if symbol in \"([{\":\n",
" s.append(symbol) # -- 只有 ([{ 入栈\n",
" # ============================================================================ #\n",
" # 后括号 #\n",
" # ============================================================================ #\n",
" else: \n",
" if s == []:\n",
" bal = False\n",
" else:\n",
" top = s.pop() # -- 有一个 \")]}\" 则 pop 一个 ([{\n",
" if not matches(top, symbol):\n",
" bal = False # 因为顺序是固定的, 所以top and pop应该match, 否则返回 unbalanced.\n",
" index += 1\n",
" # ============================================================================ #\n",
" # next #\n",
" # ============================================================================ #\n",
" if bal and s == []:\n",
" return True \n",
" else:\n",
" return False\n",
" \n",
"def matches(open, close):\n",
" opens = \"([{\"\n",
" closes = \")]}\"\n",
" return opens.index(open) == closes.index(close)\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"parchecker(\"((({})))\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### 中序表达式转换后序, 前序\n",
"\n",
"中序表达式: $(1 + 4) * 3 + 10 / 5$\n",
"\n",
"前序表达式: $+ * + 1 4 3 / 10 5$\n",
"\n",
"后序表达式: $1 4 + 3 * 10 5 / +$"
]
},
{
"cell_type": "code",
"execution_count": 196,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"4"
]
},
"execution_count": 196,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import string \n",
"import time\n",
"(lambda x: x+2)(2)\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"infixexp = '( A + B ) * C + D / E'\n",
"# 'A B + C * D E / +' \n",
"# 1. 优先括号.\n",
"# 2. 优先乘除.\n",
"# "
]
},
{
"cell_type": "code",
"execution_count": 210,
"metadata": {},
"outputs": [],
"source": [
"def func_(infixexp):\n",
" token_list = infixexp.split()\n",
" opstack = [] #\n",
" postfixlist = [] # 输出\n",
" prec = {}\n",
" prec['*'] = 3\n",
" prec['/'] = 3\n",
" prec['+'] = 2\n",
" prec['-'] = 2\n",
" prec['('] = 1\n",
"\n",
" for token in token_list:\n",
" \n",
" if token in string.ascii_uppercase: # all letter in upper form.\n",
" postfixlist.append(token) # num group\n",
" elif token == '(': \n",
" opstack.append(token) # operator group \n",
" elif token == ')': \n",
" toptoken = opstack.pop() # \n",
" while toptoken != '(': # reversed append calculation marks., before meeting the earlier parenthesis.\n",
" postfixlist.append(toptoken) # reversed append calculation marks.\n",
" toptoken = opstack.pop() # remove parenthesis\n",
" else:\n",
" while (not opstack == []) and \\\n",
" (prec[opstack[-1]] >= prec[token]): # 当前符号比上一个符号等级低或同.\n",
" postfixlist.append(opstack.pop())\n",
" \n",
" opstack.append(token)\n",
"\n",
" while not opstack == []:\n",
" postfixlist.append(opstack.pop())\n",
" \n",
" print(postfixlist, opstack)\n",
" print(\n",
" \"\"\"\n",
" # ============================================================================ # \n",
" # ============================================================================ #\n",
" \"\"\"\n",
" )\n",
" time.sleep(1)\n",
" \n",
"\n",
" return \" \".join(postfixlist)"
]
},
{
"cell_type": "code",
"execution_count": 212,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['A', 'B', '+', 'C', '*', 'D', 'E', '/'] ['+']\n",
"\n",
" # ============================================================================ # \n",
" # ============================================================================ #\n",
" \n",
"['A', 'B', '+', 'C', '*', 'D', 'E', '/', '+'] []\n",
"\n",
" # ============================================================================ # \n",
" # ============================================================================ #\n",
" \n"
]
},
{
"data": {
"text/plain": [
"'A B + C * D E / +'"
]
},
"execution_count": 212,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"func_(infixexp)"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"# a dp pract"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Python3 program to find a maximum\n",
"# product of a triplet in array\n",
"# of integers\n",
"import sys\n",
"\n",
"# Function to find a maximum\n",
"# product of a triplet in array\n",
"# of integers of size n\n",
"def maxProduct(arr, n):\n",
"\n",
"\t# if size is less than 3,\n",
"\t# no triplet exists\n",
"\tif n < 3:\n",
"\t\treturn -1\n",
"\n",
"\t# will contain max product\n",
"\tmax_product = -(sys.maxsize - 1)\n",
"\t\n",
"\tfor i in range(0, n - 2):\n",
"\t\tfor j in range(i + 1, n - 1):\n",
"\t\t\tfor k in range(j + 1, n):\n",
"\t\t\t\tmax_product = max(\n",
"\t\t\t\t\tmax_product, arr[i]\n",
"\t\t\t\t\t* arr[j] * arr[k])\n",
"\n",
"\treturn max_product\n",
"\n",
"# Driver Program\n",
"arr = [10, 3, 5, 6, 20]\n",
"n = len(arr)\n",
"\n",
"max = maxProduct(arr, n)\n",
"\n",
"if max == -1:\n",
"\tprint(\"No Tripplet Exits\")\n",
"else:\n",
"\tprint(\"Maximum product is\", max)\n",
"\n",
"# This code is contributed by Shrikant13\n"
]
},
{
"cell_type": "code",
"execution_count": 175,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>message</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>asd</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>ijijf</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" message\n",
"0 asd\n",
"1 ijijf"
]
},
"execution_count": 175,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"message = pd.Series([i.strip() for i in \"asd\\001ijijf\".split('\\001')])\n",
"import pandas as pd\n",
"pd.DataFrame(\n",
" {\n",
" 'message': message,\n",
" \n",
" }, \n",
" index=range(len(message))).head(20)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"ename": "ConnectTimeout",
"evalue": "HTTPConnectionPool(host='quotes.toscrape.com', port=80): Max retries exceeded with url: /author/Albert-Einstein/ (Caused by ConnectTimeoutError(<urllib3.connection.HTTPConnection object at 0x0000022B063F5AC0>, 'Connection to quotes.toscrape.com timed out. (connect timeout=5)'))",
"output_type": "error",
"traceback": [
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[1;31mtimeout\u001b[0m Traceback (most recent call last)",
"File \u001b[1;32mc:\\Users\\dscshap3808\\Miniconda3\\envs\\siming\\lib\\site-packages\\urllib3\\connection.py:174\u001b[0m, in \u001b[0;36mHTTPConnection._new_conn\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m 173\u001b[0m \u001b[39mtry\u001b[39;00m:\n\u001b[1;32m--> 174\u001b[0m conn \u001b[39m=\u001b[39m connection\u001b[39m.\u001b[39;49mcreate_connection(\n\u001b[0;32m 175\u001b[0m (\u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_dns_host, \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mport), \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mtimeout, \u001b[39m*\u001b[39;49m\u001b[39m*\u001b[39;49mextra_kw\n\u001b[0;32m 176\u001b[0m )\n\u001b[0;32m 178\u001b[0m \u001b[39mexcept\u001b[39;00m SocketTimeout:\n",
"File \u001b[1;32mc:\\Users\\dscshap3808\\Miniconda3\\envs\\siming\\lib\\site-packages\\urllib3\\util\\connection.py:96\u001b[0m, in \u001b[0;36mcreate_connection\u001b[1;34m(address, timeout, source_address, socket_options)\u001b[0m\n\u001b[0;32m 95\u001b[0m \u001b[39mif\u001b[39;00m err \u001b[39mis\u001b[39;00m \u001b[39mnot\u001b[39;00m \u001b[39mNone\u001b[39;00m:\n\u001b[1;32m---> 96\u001b[0m \u001b[39mraise\u001b[39;00m err\n\u001b[0;32m 98\u001b[0m \u001b[39mraise\u001b[39;00m socket\u001b[39m.\u001b[39merror(\u001b[39m\"\u001b[39m\u001b[39mgetaddrinfo returns an empty list\u001b[39m\u001b[39m\"\u001b[39m)\n",
"File \u001b[1;32mc:\\Users\\dscshap3808\\Miniconda3\\envs\\siming\\lib\\site-packages\\urllib3\\util\\connection.py:86\u001b[0m, in \u001b[0;36mcreate_connection\u001b[1;34m(address, timeout, source_address, socket_options)\u001b[0m\n\u001b[0;32m 85\u001b[0m sock\u001b[39m.\u001b[39mbind(source_address)\n\u001b[1;32m---> 86\u001b[0m sock\u001b[39m.\u001b[39;49mconnect(sa)\n\u001b[0;32m 87\u001b[0m \u001b[39mreturn\u001b[39;00m sock\n",
"\u001b[1;31mtimeout\u001b[0m: timed out",
"\nDuring handling of the above exception, another exception occurred:\n",
"\u001b[1;31mConnectTimeoutError\u001b[0m Traceback (most recent call last)",
"File \u001b[1;32mc:\\Users\\dscshap3808\\Miniconda3\\envs\\siming\\lib\\site-packages\\urllib3\\connectionpool.py:699\u001b[0m, in \u001b[0;36mHTTPConnectionPool.urlopen\u001b[1;34m(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, **response_kw)\u001b[0m\n\u001b[0;32m 698\u001b[0m \u001b[39m# Make the request on the httplib connection object.\u001b[39;00m\n\u001b[1;32m--> 699\u001b[0m httplib_response \u001b[39m=\u001b[39m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_make_request(\n\u001b[0;32m 700\u001b[0m conn,\n\u001b[0;32m 701\u001b[0m method,\n\u001b[0;32m 702\u001b[0m url,\n\u001b[0;32m 703\u001b[0m timeout\u001b[39m=\u001b[39;49mtimeout_obj,\n\u001b[0;32m 704\u001b[0m body\u001b[39m=\u001b[39;49mbody,\n\u001b[0;32m 705\u001b[0m headers\u001b[39m=\u001b[39;49mheaders,\n\u001b[0;32m 706\u001b[0m chunked\u001b[39m=\u001b[39;49mchunked,\n\u001b[0;32m 707\u001b[0m )\n\u001b[0;32m 709\u001b[0m \u001b[39m# If we're going to release the connection in ``finally:``, then\u001b[39;00m\n\u001b[0;32m 710\u001b[0m \u001b[39m# the response doesn't need to know about the connection. Otherwise\u001b[39;00m\n\u001b[0;32m 711\u001b[0m \u001b[39m# it will also try to release it and we'll have a double-release\u001b[39;00m\n\u001b[0;32m 712\u001b[0m \u001b[39m# mess.\u001b[39;00m\n",
"File \u001b[1;32mc:\\Users\\dscshap3808\\Miniconda3\\envs\\siming\\lib\\site-packages\\urllib3\\connectionpool.py:394\u001b[0m, in \u001b[0;36mHTTPConnectionPool._make_request\u001b[1;34m(self, conn, method, url, timeout, chunked, **httplib_request_kw)\u001b[0m\n\u001b[0;32m 393\u001b[0m \u001b[39melse\u001b[39;00m:\n\u001b[1;32m--> 394\u001b[0m conn\u001b[39m.\u001b[39;49mrequest(method, url, \u001b[39m*\u001b[39;49m\u001b[39m*\u001b[39;49mhttplib_request_kw)\n\u001b[0;32m 396\u001b[0m \u001b[39m# We are swallowing BrokenPipeError (errno.EPIPE) since the server is\u001b[39;00m\n\u001b[0;32m 397\u001b[0m \u001b[39m# legitimately able to close the connection after sending a valid response.\u001b[39;00m\n\u001b[0;32m 398\u001b[0m \u001b[39m# With this behaviour, the received response is still readable.\u001b[39;00m\n",
"File \u001b[1;32mc:\\Users\\dscshap3808\\Miniconda3\\envs\\siming\\lib\\site-packages\\urllib3\\connection.py:239\u001b[0m, in \u001b[0;36mHTTPConnection.request\u001b[1;34m(self, method, url, body, headers)\u001b[0m\n\u001b[0;32m 238\u001b[0m headers[\u001b[39m\"\u001b[39m\u001b[39mUser-Agent\u001b[39m\u001b[39m\"\u001b[39m] \u001b[39m=\u001b[39m _get_default_user_agent()\n\u001b[1;32m--> 239\u001b[0m \u001b[39msuper\u001b[39;49m(HTTPConnection, \u001b[39mself\u001b[39;49m)\u001b[39m.\u001b[39;49mrequest(method, url, body\u001b[39m=\u001b[39;49mbody, headers\u001b[39m=\u001b[39;49mheaders)\n",
"File \u001b[1;32mc:\\Users\\dscshap3808\\Miniconda3\\envs\\siming\\lib\\http\\client.py:1255\u001b[0m, in \u001b[0;36mHTTPConnection.request\u001b[1;34m(self, method, url, body, headers, encode_chunked)\u001b[0m\n\u001b[0;32m 1254\u001b[0m \u001b[39m\"\"\"Send a complete request to the server.\"\"\"\u001b[39;00m\n\u001b[1;32m-> 1255\u001b[0m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_send_request(method, url, body, headers, encode_chunked)\n",
"File \u001b[1;32mc:\\Users\\dscshap3808\\Miniconda3\\envs\\siming\\lib\\http\\client.py:1301\u001b[0m, in \u001b[0;36mHTTPConnection._send_request\u001b[1;34m(self, method, url, body, headers, encode_chunked)\u001b[0m\n\u001b[0;32m 1300\u001b[0m body \u001b[39m=\u001b[39m _encode(body, \u001b[39m'\u001b[39m\u001b[39mbody\u001b[39m\u001b[39m'\u001b[39m)\n\u001b[1;32m-> 1301\u001b[0m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mendheaders(body, encode_chunked\u001b[39m=\u001b[39;49mencode_chunked)\n",
"File \u001b[1;32mc:\\Users\\dscshap3808\\Miniconda3\\envs\\siming\\lib\\http\\client.py:1250\u001b[0m, in \u001b[0;36mHTTPConnection.endheaders\u001b[1;34m(self, message_body, encode_chunked)\u001b[0m\n\u001b[0;32m 1249\u001b[0m \u001b[39mraise\u001b[39;00m CannotSendHeader()\n\u001b[1;32m-> 1250\u001b[0m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_send_output(message_body, encode_chunked\u001b[39m=\u001b[39;49mencode_chunked)\n",
"File \u001b[1;32mc:\\Users\\dscshap3808\\Miniconda3\\envs\\siming\\lib\\http\\client.py:1010\u001b[0m, in \u001b[0;36mHTTPConnection._send_output\u001b[1;34m(self, message_body, encode_chunked)\u001b[0m\n\u001b[0;32m 1009\u001b[0m \u001b[39mdel\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_buffer[:]\n\u001b[1;32m-> 1010\u001b[0m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49msend(msg)\n\u001b[0;32m 1012\u001b[0m \u001b[39mif\u001b[39;00m message_body \u001b[39mis\u001b[39;00m \u001b[39mnot\u001b[39;00m \u001b[39mNone\u001b[39;00m:\n\u001b[0;32m 1013\u001b[0m \n\u001b[0;32m 1014\u001b[0m \u001b[39m# create a consistent interface to message_body\u001b[39;00m\n",
"File \u001b[1;32mc:\\Users\\dscshap3808\\Miniconda3\\envs\\siming\\lib\\http\\client.py:950\u001b[0m, in \u001b[0;36mHTTPConnection.send\u001b[1;34m(self, data)\u001b[0m\n\u001b[0;32m 949\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mauto_open:\n\u001b[1;32m--> 950\u001b[0m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mconnect()\n\u001b[0;32m 951\u001b[0m \u001b[39melse\u001b[39;00m:\n",
"File \u001b[1;32mc:\\Users\\dscshap3808\\Miniconda3\\envs\\siming\\lib\\site-packages\\urllib3\\connection.py:205\u001b[0m, in \u001b[0;36mHTTPConnection.connect\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m 204\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39mconnect\u001b[39m(\u001b[39mself\u001b[39m):\n\u001b[1;32m--> 205\u001b[0m conn \u001b[39m=\u001b[39m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_new_conn()\n\u001b[0;32m 206\u001b[0m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_prepare_conn(conn)\n",
"File \u001b[1;32mc:\\Users\\dscshap3808\\Miniconda3\\envs\\siming\\lib\\site-packages\\urllib3\\connection.py:179\u001b[0m, in \u001b[0;36mHTTPConnection._new_conn\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m 178\u001b[0m \u001b[39mexcept\u001b[39;00m SocketTimeout:\n\u001b[1;32m--> 179\u001b[0m \u001b[39mraise\u001b[39;00m ConnectTimeoutError(\n\u001b[0;32m 180\u001b[0m \u001b[39mself\u001b[39m,\n\u001b[0;32m 181\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mConnection to \u001b[39m\u001b[39m%s\u001b[39;00m\u001b[39m timed out. (connect timeout=\u001b[39m\u001b[39m%s\u001b[39;00m\u001b[39m)\u001b[39m\u001b[39m\"\u001b[39m\n\u001b[0;32m 182\u001b[0m \u001b[39m%\u001b[39m (\u001b[39mself\u001b[39m\u001b[39m.\u001b[39mhost, \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mtimeout),\n\u001b[0;32m 183\u001b[0m )\n\u001b[0;32m 185\u001b[0m \u001b[39mexcept\u001b[39;00m SocketError \u001b[39mas\u001b[39;00m e:\n",
"\u001b[1;31mConnectTimeoutError\u001b[0m: (<urllib3.connection.HTTPConnection object at 0x0000022B063F5AC0>, 'Connection to quotes.toscrape.com timed out. (connect timeout=5)')",
"\nDuring handling of the above exception, another exception occurred:\n",
"\u001b[1;31mMaxRetryError\u001b[0m Traceback (most recent call last)",
"File \u001b[1;32mc:\\Users\\dscshap3808\\Miniconda3\\envs\\siming\\lib\\site-packages\\requests\\adapters.py:439\u001b[0m, in \u001b[0;36mHTTPAdapter.send\u001b[1;34m(self, request, stream, timeout, verify, cert, proxies)\u001b[0m\n\u001b[0;32m 438\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39mnot\u001b[39;00m chunked:\n\u001b[1;32m--> 439\u001b[0m resp \u001b[39m=\u001b[39m conn\u001b[39m.\u001b[39;49murlopen(\n\u001b[0;32m 440\u001b[0m method\u001b[39m=\u001b[39;49mrequest\u001b[39m.\u001b[39;49mmethod,\n\u001b[0;32m 441\u001b[0m url\u001b[39m=\u001b[39;49murl,\n\u001b[0;32m 442\u001b[0m body\u001b[39m=\u001b[39;49mrequest\u001b[39m.\u001b[39;49mbody,\n\u001b[0;32m 443\u001b[0m headers\u001b[39m=\u001b[39;49mrequest\u001b[39m.\u001b[39;49mheaders,\n\u001b[0;32m 444\u001b[0m redirect\u001b[39m=\u001b[39;49m\u001b[39mFalse\u001b[39;49;00m,\n\u001b[0;32m 445\u001b[0m assert_same_host\u001b[39m=\u001b[39;49m\u001b[39mFalse\u001b[39;49;00m,\n\u001b[0;32m 446\u001b[0m preload_content\u001b[39m=\u001b[39;49m\u001b[39mFalse\u001b[39;49;00m,\n\u001b[0;32m 447\u001b[0m decode_content\u001b[39m=\u001b[39;49m\u001b[39mFalse\u001b[39;49;00m,\n\u001b[0;32m 448\u001b[0m retries\u001b[39m=\u001b[39;49m\u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mmax_retries,\n\u001b[0;32m 449\u001b[0m timeout\u001b[39m=\u001b[39;49mtimeout\n\u001b[0;32m 450\u001b[0m )\n\u001b[0;32m 452\u001b[0m \u001b[39m# Send the request.\u001b[39;00m\n\u001b[0;32m 453\u001b[0m \u001b[39melse\u001b[39;00m:\n",
"File \u001b[1;32mc:\\Users\\dscshap3808\\Miniconda3\\envs\\siming\\lib\\site-packages\\urllib3\\connectionpool.py:755\u001b[0m, in \u001b[0;36mHTTPConnectionPool.urlopen\u001b[1;34m(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, **response_kw)\u001b[0m\n\u001b[0;32m 753\u001b[0m e \u001b[39m=\u001b[39m ProtocolError(\u001b[39m\"\u001b[39m\u001b[39mConnection aborted.\u001b[39m\u001b[39m\"\u001b[39m, e)\n\u001b[1;32m--> 755\u001b[0m retries \u001b[39m=\u001b[39m retries\u001b[39m.\u001b[39;49mincrement(\n\u001b[0;32m 756\u001b[0m method, url, error\u001b[39m=\u001b[39;49me, _pool\u001b[39m=\u001b[39;49m\u001b[39mself\u001b[39;49m, _stacktrace\u001b[39m=\u001b[39;49msys\u001b[39m.\u001b[39;49mexc_info()[\u001b[39m2\u001b[39;49m]\n\u001b[0;32m 757\u001b[0m )\n\u001b[0;32m 758\u001b[0m retries\u001b[39m.\u001b[39msleep()\n",
"File \u001b[1;32mc:\\Users\\dscshap3808\\Miniconda3\\envs\\siming\\lib\\site-packages\\urllib3\\util\\retry.py:574\u001b[0m, in \u001b[0;36mRetry.increment\u001b[1;34m(self, method, url, response, error, _pool, _stacktrace)\u001b[0m\n\u001b[0;32m 573\u001b[0m \u001b[39mif\u001b[39;00m new_retry\u001b[39m.\u001b[39mis_exhausted():\n\u001b[1;32m--> 574\u001b[0m \u001b[39mraise\u001b[39;00m MaxRetryError(_pool, url, error \u001b[39mor\u001b[39;00m ResponseError(cause))\n\u001b[0;32m 576\u001b[0m log\u001b[39m.\u001b[39mdebug(\u001b[39m\"\u001b[39m\u001b[39mIncremented Retry for (url=\u001b[39m\u001b[39m'\u001b[39m\u001b[39m%s\u001b[39;00m\u001b[39m'\u001b[39m\u001b[39m): \u001b[39m\u001b[39m%r\u001b[39;00m\u001b[39m\"\u001b[39m, url, new_retry)\n",
"\u001b[1;31mMaxRetryError\u001b[0m: HTTPConnectionPool(host='quotes.toscrape.com', port=80): Max retries exceeded with url: /author/Albert-Einstein/ (Caused by ConnectTimeoutError(<urllib3.connection.HTTPConnection object at 0x0000022B063F5AC0>, 'Connection to quotes.toscrape.com timed out. (connect timeout=5)'))",
"\nDuring handling of the above exception, another exception occurred:\n",
"\u001b[1;31mConnectTimeout\u001b[0m Traceback (most recent call last)",
"\u001b[1;32mc:\\Users\\dscshap3808\\Documents\\my_scripts_new\\stlit\\leetcodemore.ipynb Cell 17\u001b[0m in \u001b[0;36m<cell line: 5>\u001b[1;34m()\u001b[0m\n\u001b[0;32m <a href='vscode-notebook-cell:/c%3A/Users/dscshap3808/Documents/my_scripts_new/stlit/leetcodemore.ipynb#ch0000019?line=2'>3</a>\u001b[0m \u001b[39m# fetch the page to train\u001b[39;00m\n\u001b[0;32m <a href='vscode-notebook-cell:/c%3A/Users/dscshap3808/Documents/my_scripts_new/stlit/leetcodemore.ipynb#ch0000019?line=3'>4</a>\u001b[0m einstein_url \u001b[39m=\u001b[39m \u001b[39m'\u001b[39m\u001b[39mhttp://quotes.toscrape.com/author/Albert-Einstein/\u001b[39m\u001b[39m'\u001b[39m\n\u001b[1;32m----> <a href='vscode-notebook-cell:/c%3A/Users/dscshap3808/Documents/my_scripts_new/stlit/leetcodemore.ipynb#ch0000019?line=4'>5</a>\u001b[0m resp \u001b[39m=\u001b[39m requests\u001b[39m.\u001b[39;49mget(einstein_url, timeout \u001b[39m=\u001b[39;49m \u001b[39m5\u001b[39;49m)\n\u001b[0;32m <a href='vscode-notebook-cell:/c%3A/Users/dscshap3808/Documents/my_scripts_new/stlit/leetcodemore.ipynb#ch0000019?line=5'>6</a>\u001b[0m \u001b[39m# resp\u001b[39;00m\n\u001b[0;32m <a href='vscode-notebook-cell:/c%3A/Users/dscshap3808/Documents/my_scripts_new/stlit/leetcodemore.ipynb#ch0000019?line=6'>7</a>\u001b[0m \u001b[39massert\u001b[39;00m resp\u001b[39m.\u001b[39mstatus_code \u001b[39m==\u001b[39m \u001b[39m200\u001b[39m\n",
"File \u001b[1;32mc:\\Users\\dscshap3808\\Miniconda3\\envs\\siming\\lib\\site-packages\\requests\\api.py:75\u001b[0m, in \u001b[0;36mget\u001b[1;34m(url, params, **kwargs)\u001b[0m\n\u001b[0;32m 64\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39mget\u001b[39m(url, params\u001b[39m=\u001b[39m\u001b[39mNone\u001b[39;00m, \u001b[39m*\u001b[39m\u001b[39m*\u001b[39mkwargs):\n\u001b[0;32m 65\u001b[0m \u001b[39mr\u001b[39m\u001b[39m\"\"\"Sends a GET request.\u001b[39;00m\n\u001b[0;32m 66\u001b[0m \n\u001b[0;32m 67\u001b[0m \u001b[39m :param url: URL for the new :class:`Request` object.\u001b[39;00m\n\u001b[1;32m (...)\u001b[0m\n\u001b[0;32m 72\u001b[0m \u001b[39m :rtype: requests.Response\u001b[39;00m\n\u001b[0;32m 73\u001b[0m \u001b[39m \"\"\"\u001b[39;00m\n\u001b[1;32m---> 75\u001b[0m \u001b[39mreturn\u001b[39;00m request(\u001b[39m'\u001b[39;49m\u001b[39mget\u001b[39;49m\u001b[39m'\u001b[39;49m, url, params\u001b[39m=\u001b[39;49mparams, \u001b[39m*\u001b[39;49m\u001b[39m*\u001b[39;49mkwargs)\n",
"File \u001b[1;32mc:\\Users\\dscshap3808\\Miniconda3\\envs\\siming\\lib\\site-packages\\requests\\api.py:61\u001b[0m, in \u001b[0;36mrequest\u001b[1;34m(method, url, **kwargs)\u001b[0m\n\u001b[0;32m 57\u001b[0m \u001b[39m# By using the 'with' statement we are sure the session is closed, thus we\u001b[39;00m\n\u001b[0;32m 58\u001b[0m \u001b[39m# avoid leaving sockets open which can trigger a ResourceWarning in some\u001b[39;00m\n\u001b[0;32m 59\u001b[0m \u001b[39m# cases, and look like a memory leak in others.\u001b[39;00m\n\u001b[0;32m 60\u001b[0m \u001b[39mwith\u001b[39;00m sessions\u001b[39m.\u001b[39mSession() \u001b[39mas\u001b[39;00m session:\n\u001b[1;32m---> 61\u001b[0m \u001b[39mreturn\u001b[39;00m session\u001b[39m.\u001b[39;49mrequest(method\u001b[39m=\u001b[39;49mmethod, url\u001b[39m=\u001b[39;49murl, \u001b[39m*\u001b[39;49m\u001b[39m*\u001b[39;49mkwargs)\n",
"File \u001b[1;32mc:\\Users\\dscshap3808\\Miniconda3\\envs\\siming\\lib\\site-packages\\requests\\sessions.py:542\u001b[0m, in \u001b[0;36mSession.request\u001b[1;34m(self, method, url, params, data, headers, cookies, files, auth, timeout, allow_redirects, proxies, hooks, stream, verify, cert, json)\u001b[0m\n\u001b[0;32m 537\u001b[0m send_kwargs \u001b[39m=\u001b[39m {\n\u001b[0;32m 538\u001b[0m \u001b[39m'\u001b[39m\u001b[39mtimeout\u001b[39m\u001b[39m'\u001b[39m: timeout,\n\u001b[0;32m 539\u001b[0m \u001b[39m'\u001b[39m\u001b[39mallow_redirects\u001b[39m\u001b[39m'\u001b[39m: allow_redirects,\n\u001b[0;32m 540\u001b[0m }\n\u001b[0;32m 541\u001b[0m send_kwargs\u001b[39m.\u001b[39mupdate(settings)\n\u001b[1;32m--> 542\u001b[0m resp \u001b[39m=\u001b[39m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49msend(prep, \u001b[39m*\u001b[39;49m\u001b[39m*\u001b[39;49msend_kwargs)\n\u001b[0;32m 544\u001b[0m \u001b[39mreturn\u001b[39;00m resp\n",
"File \u001b[1;32mc:\\Users\\dscshap3808\\Miniconda3\\envs\\siming\\lib\\site-packages\\requests\\sessions.py:655\u001b[0m, in \u001b[0;36mSession.send\u001b[1;34m(self, request, **kwargs)\u001b[0m\n\u001b[0;32m 652\u001b[0m start \u001b[39m=\u001b[39m preferred_clock()\n\u001b[0;32m 654\u001b[0m \u001b[39m# Send the request\u001b[39;00m\n\u001b[1;32m--> 655\u001b[0m r \u001b[39m=\u001b[39m adapter\u001b[39m.\u001b[39;49msend(request, \u001b[39m*\u001b[39;49m\u001b[39m*\u001b[39;49mkwargs)\n\u001b[0;32m 657\u001b[0m \u001b[39m# Total elapsed time of the request (approximately)\u001b[39;00m\n\u001b[0;32m 658\u001b[0m elapsed \u001b[39m=\u001b[39m preferred_clock() \u001b[39m-\u001b[39m start\n",
"File \u001b[1;32mc:\\Users\\dscshap3808\\Miniconda3\\envs\\siming\\lib\\site-packages\\requests\\adapters.py:504\u001b[0m, in \u001b[0;36mHTTPAdapter.send\u001b[1;34m(self, request, stream, timeout, verify, cert, proxies)\u001b[0m\n\u001b[0;32m 501\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39misinstance\u001b[39m(e\u001b[39m.\u001b[39mreason, ConnectTimeoutError):\n\u001b[0;32m 502\u001b[0m \u001b[39m# TODO: Remove this in 3.0.0: see #2811\u001b[39;00m\n\u001b[0;32m 503\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39mnot\u001b[39;00m \u001b[39misinstance\u001b[39m(e\u001b[39m.\u001b[39mreason, NewConnectionError):\n\u001b[1;32m--> 504\u001b[0m \u001b[39mraise\u001b[39;00m ConnectTimeout(e, request\u001b[39m=\u001b[39mrequest)\n\u001b[0;32m 506\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39misinstance\u001b[39m(e\u001b[39m.\u001b[39mreason, ResponseError):\n\u001b[0;32m 507\u001b[0m \u001b[39mraise\u001b[39;00m RetryError(e, request\u001b[39m=\u001b[39mrequest)\n",
"\u001b[1;31mConnectTimeout\u001b[0m: HTTPConnectionPool(host='quotes.toscrape.com', port=80): Max retries exceeded with url: /author/Albert-Einstein/ (Caused by ConnectTimeoutError(<urllib3.connection.HTTPConnection object at 0x0000022B063F5AC0>, 'Connection to quotes.toscrape.com timed out. (connect timeout=5)'))"
]
}
],
"source": [
"import requests \n",
"from bs4 import BeautifulSoup\n",
"# fetch the page to train\n",
"einstein_url = 'http://quotes.toscrape.com/author/Albert-Einstein/'\n",
"resp = requests.get(einstein_url, timeout = 5)\n",
"# resp\n",
"assert resp.status_code == 200"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"soup = BeautifulSoup(resp.content)"
]
},
{
"cell_type": "code",
"execution_count": 125,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<p>\n",
"<a href=\"/login\">Login</a>\n",
"</p>"
]
},
"execution_count": 125,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"soup.find()"
]
},
{
"cell_type": "code",
"execution_count": 126,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'href': '/', 'style': 'text-decoration: none'}"
]
},
"execution_count": 126,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"soup.a.attrs"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 134,
"metadata": {},
"outputs": [],
"source": [
"df = pd.read_json('./dataup/world_countries.json')['features']"
]
},
{
"cell_type": "code",
"execution_count": 146,
"metadata": {},
"outputs": [],
"source": [
"# df[0]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"\n",
"import plotly.express as px\n",
"\n",
"fig = px.choropleth_mapbox(df, geojson=df, locations='fips', color='unemp',\\\n",
" color_continuous_scale=\"Viridis\",\n",
" range_color=(0, 12),\n",
" mapbox_style=\"carto-positron\",\n",
" zoom=3, \n",
" center = {\"lat\": 37.0902, \"lon\": -95.7129},\n",
" opacity=0.5,\n",
" labels={'unemp':'unemployment rate'}\n",
" )\n",
"fig.update_layout(margin={\"r\":0,\"t\":0,\"l\":0,\"b\":0})\n",
"fig.show()"
]
},
{
"cell_type": "code",
"execution_count": 157,
"metadata": {},
"outputs": [],
"source": [
"# import plotly.graph_objects as go\n",
"\n",
"# fig = go.Figure(go.Scattermapbox(\n",
"# mode = \"markers+lines\",\n",
"# lon = [10, 20, 30],\n",
"# lat = [10, 20,30],\n",
"# marker = {'size': 10}))\n",
"\n",
"# fig.add_trace(go.Scattermapbox(\n",
"# mode = \"markers+lines\",\n",
"# lon = [-50, -60,40],\n",
"# lat = [30, 10, -20],\n",
"# marker = {'size': 10}))\n",
"\n",
"# fig.update_layout(\n",
"# margin ={'l':0,'t':0,'b':0,'r':0},\n",
"# mapbox = {\n",
"# 'style': \"carto-positron\",# \"stamen-terrain\",\n",
"# 'center': {'lon': -20, 'lat': -20},\n",
"# 'zoom': 2})\n",
"\n",
"# # fig.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"vscode": {
"languageId": "javascript"
}
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3.8.8 ('siming')",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.8"
},
"orig_nbformat": 4,
"vscode": {
"interpreter": {
"hash": "2537094cdaaf8cbca77398104c426db43a9f1c17b808f90867ef58a7e69b756d"
}
}
},
"nbformat": 4,
"nbformat_minor": 2
}
|