|
292 | 292 | },
|
293 | 293 | {
|
294 | 294 | "cell_type": "code",
|
295 |
| - "execution_count": null, |
| 295 | + "execution_count": 4, |
296 | 296 | "metadata": {
|
297 |
| - "collapsed": true |
| 297 | + "collapsed": false |
298 | 298 | },
|
299 | 299 | "outputs": [],
|
300 |
| - "source": [] |
| 300 | + "source": [ |
| 301 | + "import requests\n", |
| 302 | + "\n", |
| 303 | + "url = 'https://physionet.org/physiobank/database/a'\n", |
| 304 | + "\n", |
| 305 | + "r = requests.get(url)\n", |
| 306 | + "\n" |
| 307 | + ] |
301 | 308 | },
|
302 | 309 | {
|
303 | 310 | "cell_type": "code",
|
304 |
| - "execution_count": 4, |
| 311 | + "execution_count": 7, |
305 | 312 | "metadata": {
|
306 | 313 | "collapsed": false
|
307 | 314 | },
|
308 | 315 | "outputs": [
|
309 | 316 | {
|
310 | 317 | "data": {
|
311 | 318 | "text/plain": [
|
312 |
| - "<Response [200]>" |
| 319 | + "True" |
313 | 320 | ]
|
314 | 321 | },
|
315 |
| - "execution_count": 4, |
| 322 | + "execution_count": 7, |
316 | 323 | "metadata": {},
|
317 | 324 | "output_type": "execute_result"
|
318 | 325 | }
|
319 | 326 | ],
|
320 | 327 | "source": [
|
321 |
| - "import requests\n", |
322 |
| - "from IPython.display import display\n", |
323 |
| - "url = 'http://physionet.org/physiobank/database/mitdb/100.hea'\n", |
324 |
| - "r = requests.get(url)\n", |
325 |
| - "r" |
| 328 | + "r.status_code == 404" |
326 | 329 | ]
|
327 | 330 | },
|
328 | 331 | {
|
329 | 332 | "cell_type": "code",
|
330 |
| - "execution_count": 5, |
| 333 | + "execution_count": 8, |
331 | 334 | "metadata": {
|
332 | 335 | "collapsed": false
|
333 | 336 | },
|
334 | 337 | "outputs": [
|
335 | 338 | {
|
336 | 339 | "data": {
|
337 | 340 | "text/plain": [
|
338 |
| - "['__attrs__',\n", |
339 |
| - " '__bool__',\n", |
340 |
| - " '__class__',\n", |
341 |
| - " '__delattr__',\n", |
342 |
| - " '__dict__',\n", |
343 |
| - " '__dir__',\n", |
344 |
| - " '__doc__',\n", |
345 |
| - " '__eq__',\n", |
346 |
| - " '__format__',\n", |
347 |
| - " '__ge__',\n", |
348 |
| - " '__getattribute__',\n", |
349 |
| - " '__getstate__',\n", |
350 |
| - " '__gt__',\n", |
351 |
| - " '__hash__',\n", |
352 |
| - " '__init__',\n", |
353 |
| - " '__iter__',\n", |
354 |
| - " '__le__',\n", |
355 |
| - " '__lt__',\n", |
356 |
| - " '__module__',\n", |
357 |
| - " '__ne__',\n", |
358 |
| - " '__new__',\n", |
359 |
| - " '__nonzero__',\n", |
360 |
| - " '__reduce__',\n", |
361 |
| - " '__reduce_ex__',\n", |
362 |
| - " '__repr__',\n", |
363 |
| - " '__setattr__',\n", |
364 |
| - " '__setstate__',\n", |
365 |
| - " '__sizeof__',\n", |
366 |
| - " '__str__',\n", |
367 |
| - " '__subclasshook__',\n", |
368 |
| - " '__weakref__',\n", |
369 |
| - " '_content',\n", |
370 |
| - " '_content_consumed',\n", |
371 |
| - " 'apparent_encoding',\n", |
372 |
| - " 'close',\n", |
373 |
| - " 'connection',\n", |
374 |
| - " 'content',\n", |
375 |
| - " 'cookies',\n", |
376 |
| - " 'elapsed',\n", |
377 |
| - " 'encoding',\n", |
378 |
| - " 'headers',\n", |
379 |
| - " 'history',\n", |
380 |
| - " 'is_permanent_redirect',\n", |
381 |
| - " 'is_redirect',\n", |
382 |
| - " 'iter_content',\n", |
383 |
| - " 'iter_lines',\n", |
384 |
| - " 'json',\n", |
385 |
| - " 'links',\n", |
386 |
| - " 'ok',\n", |
387 |
| - " 'raise_for_status',\n", |
388 |
| - " 'raw',\n", |
389 |
| - " 'reason',\n", |
390 |
| - " 'request',\n", |
391 |
| - " 'status_code',\n", |
392 |
| - " 'text',\n", |
393 |
| - " 'url']" |
| 341 | + "'edf'" |
394 | 342 | ]
|
395 | 343 | },
|
396 |
| - "execution_count": 5, |
| 344 | + "execution_count": 8, |
397 | 345 | "metadata": {},
|
398 | 346 | "output_type": "execute_result"
|
399 | 347 | }
|
400 | 348 | ],
|
401 | 349 | "source": [
|
402 |
| - "dir(r)" |
| 350 | + "x = 'hello.edf'\n", |
| 351 | + "x[-3:]" |
403 | 352 | ]
|
404 | 353 | },
|
405 | 354 | {
|
406 | 355 | "cell_type": "code",
|
407 |
| - "execution_count": 9, |
| 356 | + "execution_count": 10, |
408 | 357 | "metadata": {
|
409 | 358 | "collapsed": false
|
410 | 359 | },
|
411 | 360 | "outputs": [
|
412 | 361 | {
|
413 | 362 | "data": {
|
414 | 363 | "text/plain": [
|
415 |
| - "'http://physionet.org/physiobank/database/mitdb/100.hea'" |
416 |
| - ] |
417 |
| - }, |
418 |
| - "metadata": {}, |
419 |
| - "output_type": "display_data" |
420 |
| - }, |
421 |
| - { |
422 |
| - "data": { |
423 |
| - "text/plain": [ |
424 |
| - "<requests.packages.urllib3.response.HTTPResponse at 0x7f93ee6a5198>" |
425 |
| - ] |
426 |
| - }, |
427 |
| - "metadata": {}, |
428 |
| - "output_type": "display_data" |
429 |
| - }, |
430 |
| - { |
431 |
| - "data": { |
432 |
| - "text/plain": [ |
433 |
| - "b'100 2 360 650000\\r\\n100.dat 212 200 11 1024 995 -22131 0 MLII\\r\\n100.dat 212 200 11 1024 1011 20052 0 V5\\r\\n# 69 M 1085 1629 x1\\r\\n# Aldomet, Inderal\\r\\n'" |
| 364 | + "8" |
434 | 365 | ]
|
435 | 366 | },
|
| 367 | + "execution_count": 10, |
436 | 368 | "metadata": {},
|
437 |
| - "output_type": "display_data" |
438 |
| - }, |
439 |
| - { |
440 |
| - "data": { |
441 |
| - "text/plain": [ |
442 |
| - "{'Server': 'Apache/2.2.22 (Debian) mod_auth_tkt/2.1.0 mod_auth_pgsql/2.0.3 mod_ssl/2.2.22 OpenSSL/1.0.1t', 'Keep-Alive': 'timeout=5, max=100', 'Last-Modified': 'Thu, 30 Jul 1992 05:36:18 GMT', 'ETag': '\"2b58628b-8f-287fdea221880\"', 'Connection': 'Keep-Alive', 'Date': 'Fri, 17 Mar 2017 19:44:43 GMT', 'Accept-Ranges': 'bytes', 'Content-Length': '143'}" |
443 |
| - ] |
444 |
| - }, |
445 |
| - "metadata": {}, |
446 |
| - "output_type": "display_data" |
447 |
| - }, |
448 |
| - { |
449 |
| - "data": { |
450 |
| - "text/plain": [ |
451 |
| - "bytes" |
452 |
| - ] |
453 |
| - }, |
454 |
| - "metadata": {}, |
455 |
| - "output_type": "display_data" |
| 369 | + "output_type": "execute_result" |
456 | 370 | }
|
457 | 371 | ],
|
458 | 372 | "source": [
|
459 |
| - "display(r.url)\n", |
460 |
| - "display(r.raw)\n", |
461 |
| - "display(r.content)\n", |
462 |
| - "display(r.headers)\n", |
463 |
| - "display(type(r.content))" |
| 373 | + "import os\n", |
| 374 | + "os.cpu_count()" |
464 | 375 | ]
|
465 | 376 | },
|
466 | 377 | {
|
467 | 378 | "cell_type": "code",
|
468 |
| - "execution_count": 15, |
| 379 | + "execution_count": 12, |
469 | 380 | "metadata": {
|
470 | 381 | "collapsed": false
|
471 | 382 | },
|
472 | 383 | "outputs": [
|
473 | 384 | {
|
474 | 385 | "data": {
|
475 | 386 | "text/plain": [
|
476 |
| - "'100 2 360 650000\\r\\n100.dat 212 200 11 1024 995 -22131 0 MLII\\r\\n100.dat 212 200 11 1024 1011 20052 0 V5\\r\\n# 69 M 1085 1629 x1\\r\\n# Aldomet, Inderal\\r\\n'" |
| 387 | + "True" |
477 | 388 | ]
|
478 | 389 | },
|
479 |
| - "execution_count": 15, |
| 390 | + "execution_count": 12, |
480 | 391 | "metadata": {},
|
481 | 392 | "output_type": "execute_result"
|
482 | 393 | }
|
483 | 394 | ],
|
484 | 395 | "source": [
|
485 |
| - "a = r.content.decode(\"ascii\") \n", |
486 |
| - "a" |
| 396 | + "'hello'.endswith('llo')" |
487 | 397 | ]
|
488 | 398 | },
|
489 | 399 | {
|
490 | 400 | "cell_type": "code",
|
491 |
| - "execution_count": 21, |
| 401 | + "execution_count": 15, |
492 | 402 | "metadata": {
|
493 | 403 | "collapsed": false
|
494 | 404 | },
|
495 | 405 | "outputs": [
|
496 | 406 | {
|
497 |
| - "name": "stdout", |
498 |
| - "output_type": "stream", |
499 |
| - "text": [ |
500 |
| - "['100 2 360 650000', '100.dat 212 200 11 1024 995 -22131 0 MLII', '100.dat 212 200 11 1024 1011 20052 0 V5']\n", |
501 |
| - "['# 69 M 1085 1629 x1', '# Aldomet, Inderal']\n" |
| 407 | + "ename": "AttributeError", |
| 408 | + "evalue": "'list' object has no attribute 'any'", |
| 409 | + "output_type": "error", |
| 410 | + "traceback": [ |
| 411 | + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", |
| 412 | + "\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)", |
| 413 | + "\u001b[0;32m<ipython-input-15-a0aa019c7e14>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0ml\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0;34m'hello'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'jello'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'coffee'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0ml\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0many\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", |
| 414 | + "\u001b[0;31mAttributeError\u001b[0m: 'list' object has no attribute 'any'" |
502 | 415 | ]
|
503 | 416 | }
|
504 | 417 | ],
|
505 | 418 | "source": [
|
506 |
| - "import os\n", |
507 |
| - "import requests\n", |
508 |
| - "\n", |
509 |
| - "def streamheader(recordname, pbdir):\n", |
510 |
| - "\n", |
511 |
| - " # Full url of header location\n", |
512 |
| - " url = 'http://physionet.org/physiobank/database/'+os.path.join(pbdir, recordname+'.hea')\n", |
513 |
| - " r = requests.get(url)\n", |
514 |
| - " \n", |
515 |
| - " # Raise HTTPError if invalid url\n", |
516 |
| - " r.raise_for_status()\n", |
517 |
| - " \n", |
518 |
| - " # Get each line as a string\n", |
519 |
| - " filelines = r.content.decode('ascii').splitlines()\n", |
520 |
| - " \n", |
521 |
| - " # Separate content into header and comment lines\n", |
522 |
| - " headerlines = []\n", |
523 |
| - " commentlines = []\n", |
524 |
| - " \n", |
525 |
| - " for line in filelines:\n", |
526 |
| - " line = line.strip()\n", |
527 |
| - " # Comment line\n", |
528 |
| - " if line.startswith('#'): \n", |
529 |
| - " commentlines.append(line)\n", |
530 |
| - " # Non-empty non-comment line = header line.\n", |
531 |
| - " elif line: \n", |
532 |
| - " # Look for a comment in the line\n", |
533 |
| - " ci = line.find('#')\n", |
534 |
| - " if ci > 0:\n", |
535 |
| - " headerlines.append(line[:ci])\n", |
536 |
| - " # comment on same line as header line\n", |
537 |
| - " commentlines.append(line[ci:])\n", |
538 |
| - " else:\n", |
539 |
| - " headerlines.append(line)\n", |
540 |
| - " \n", |
541 |
| - " return (headerlines, commentlines) \n", |
542 |
| - "\n", |
543 |
| - "#streamheader('3045253', 'mimic2wdb/30/3045253')\n", |
544 |
| - "a, b = streamheader('100', 'mitdb')\n", |
545 |
| - "\n", |
546 |
| - "print(a)\n", |
547 |
| - "\n", |
548 |
| - "print(b)\n" |
| 419 | + "l = ['hello', 'jello', 'coffee']\n" |
549 | 420 | ]
|
550 | 421 | },
|
551 | 422 | {
|
552 | 423 | "cell_type": "code",
|
553 |
| - "execution_count": 23, |
| 424 | + "execution_count": 19, |
554 | 425 | "metadata": {
|
555 | 426 | "collapsed": false
|
556 | 427 | },
|
557 | 428 | "outputs": [
|
558 | 429 | {
|
559 | 430 | "data": {
|
560 | 431 | "text/plain": [
|
561 |
| - "<Response [404]>" |
| 432 | + "'http://physionet.org/physiobank/database/mitdb'" |
562 | 433 | ]
|
563 | 434 | },
|
564 |
| - "execution_count": 23, |
| 435 | + "execution_count": 19, |
565 | 436 | "metadata": {},
|
566 | 437 | "output_type": "execute_result"
|
567 | 438 | }
|
568 | 439 | ],
|
569 | 440 | "source": [
|
570 |
| - "request" |
571 |
| - ] |
572 |
| - }, |
573 |
| - { |
574 |
| - "cell_type": "code", |
575 |
| - "execution_count": 28, |
576 |
| - "metadata": { |
577 |
| - "collapsed": false |
578 |
| - }, |
579 |
| - "outputs": [ |
580 |
| - { |
581 |
| - "data": { |
582 |
| - "text/plain": [ |
583 |
| - "requests.exceptions.HTTPError" |
584 |
| - ] |
585 |
| - }, |
586 |
| - "execution_count": 28, |
587 |
| - "metadata": {}, |
588 |
| - "output_type": "execute_result" |
589 |
| - } |
590 |
| - ], |
591 |
| - "source": [ |
592 |
| - "requests.HTTPError" |
593 |
| - ] |
594 |
| - }, |
595 |
| - { |
596 |
| - "cell_type": "code", |
597 |
| - "execution_count": 93, |
598 |
| - "metadata": { |
599 |
| - "collapsed": false |
600 |
| - }, |
601 |
| - "outputs": [ |
602 |
| - { |
603 |
| - "name": "stdout", |
604 |
| - "output_type": "stream", |
605 |
| - "text": [ |
606 |
| - "http://physionet.org/physiobank/database/mitdb/100.dat\n", |
607 |
| - "{'Accept-Encoding': '*/*', 'Range': 'bytes=0-9'}\n", |
608 |
| - "206\n", |
609 |
| - "{'Server': 'Apache/2.2.22 (Debian) mod_auth_tkt/2.1.0 mod_auth_pgsql/2.0.3 mod_ssl/2.2.22 OpenSSL/1.0.1t', 'Date': 'Mon, 20 Mar 2017 20:58:50 GMT', 'Last-Modified': 'Thu, 30 Jul 1992 05:36:18 GMT', 'Content-Range': 'bytes 0-9/1950000', 'Accept-Ranges': 'bytes', 'Vary': 'Accept-Encoding', 'Keep-Alive': 'timeout=5, max=100', 'Content-Type': 'application/octet-stream', 'Connection': 'Keep-Alive', 'Content-Length': '10', 'ETag': '\"2b58628a-1dc130-287fdea221880\"'}\n", |
610 |
| - "{'Accept': '*/*', 'User-Agent': 'python-requests/2.12.4', 'Connection': 'keep-alive', 'Range': 'bytes=0-9', 'Accept-Encoding': '*/*'}\n", |
611 |
| - "10\n" |
612 |
| - ] |
613 |
| - } |
614 |
| - ], |
615 |
| - "source": [ |
616 |
| - "r = streamdat('100.dat', 'mitdb', '212', 9, 0)\n", |
617 |
| - "\n", |
618 |
| - "print(r.status_code)\n", |
619 |
| - "\n", |
620 |
| - "# Header the server sent\n", |
621 |
| - "print(r.headers)\n", |
622 |
| - "\n", |
623 |
| - "# Header we sent\n", |
624 |
| - "print(r.request.headers)\n", |
| 441 | + "import os\n", |
625 | 442 | "\n",
|
626 |
| - "print(len(r.content))" |
627 |
| - ] |
628 |
| - }, |
629 |
| - { |
630 |
| - "cell_type": "code", |
631 |
| - "execution_count": 1, |
632 |
| - "metadata": { |
633 |
| - "collapsed": false |
634 |
| - }, |
635 |
| - "outputs": [], |
636 |
| - "source": [ |
637 |
| - "import wfdb" |
| 443 | + "os.path.join('http://physionet.org/physiobank/database/', 'mitdb')" |
638 | 444 | ]
|
639 | 445 | },
|
640 | 446 | {
|
|
0 commit comments