Module III - Day I

Python Foundation

Nov-Jan 2025 batch, Vikrant Patil

Date: 10 Feb 2026

Click here for All Notes

login to https://traininghub.vikrant.dev/ with your username and create a notebook with name module1-day1.ipynb

© Vikrant Patil

Classes - Recap

class Point:

    def __init__(self, x, y): # contructor of the class
        self.x = x
        self.y = y

    def get_x(self):
        return self.x

    def get_y(self):
        return self.x

        
+---------+
|         |------> get_x
|  x =    |
|  y =    |------> get_y
+---------+
nums = [1, 2, 3, 4, 5]
nums.index(5)
4
type(nums)
list
Point
__main__.Point
p = Point(10, 20) # pass the argument that are defined in the constructor
type(p)
__main__.Point
nums
[1, 2, 3, 4, 5]
p
<__main__.Point at 0x7f4ea445ae90>
class Point:

    def __init__(self, x, y): # contructor of the class
        self.x = x
        self.y = y

    def get_x(self):
        return self.x

    def get_y(self):
        return self.x

    def __repr__(self):
        """magic method that will show reprensentation of the object inside interpreter
        """
        return f"Pair({self.x}, {self.y})" # string formatting

   
    def __rmul__(self, scale):
        return Point(scale*self.x, scale*self.y)

    def __add__(self, p):
        return Point(self.x + p.x, 
                     self.y + p.y)

    def __getitem__(self, name):
        if name == "x":
            return self.x
        elif name == "y":
            return self.y
        else:
            raise NameError(f"Unknown attribute {name}")
p1 = Point(0, 0)
p1
Pair(0, 0)
p2 = Point(1, 2)
p2
Pair(1, 2)
3*p2
Pair(3, 6)
"hello"*3
'hellohellohello'
3*"hello"
'hellohellohello'
p1 + p2
Pair(1, 2)
p3 = Point(10, 20)
p2
Pair(1, 2)
p3
Pair(10, 20)
p2 + p3
Pair(11, 22)
p = p2 + p3
p['x'] # like dictionary we can access data
11
p1
Pair(0, 0)
print(p1)
Pair(0, 0)
class Point:

    def __init__(self, x, y): # contructor of the class
        self.x = x
        self.y = y

    def get_x(self):
        return self.x

    def get_y(self):
        return self.x

    def __repr__(self):
        """magic method that will show reprensentation of the object inside interpreter
        """
        return f"Pair({self.x}, {self.y})" # string formatting

    def __rmul__(self, scale):
        """ overloas the right side multiplication
        3*point
        """
        return Point(scale*self.x, scale*self.y)

    def __lmul__(self, scale):
        """ overloas the left side multiplication
        point*3
        """
        return Point(scale*self.x, scale*self.y)

    
    def __add__(self, p):
        """overrides + operator allowing us to add two points
        """
        return Point(self.x + p.x, 
                     self.y + p.y)

    def __getitem__(self, name):
        """creates a dictionary like access
        p['x'] -> will call this method
        """
        if name == "x":
            return self.x
        elif name == "y":
            return self.y
        else:
            raise NameError(f"Unknown attribute {name}")
    
    def __str__(self):
        """will be called when object is printed or converted to str
        """
        return f"({self.x},{self.x})"
    
p = Point(45, 42)
p
Pair(45, 42)
print(p)
(45,45)
f"My robot will start at location {p}" # here __str__ will be called
'My robot will start at location (45,45)'
str(p)
'(45,45)'
print(p.x)
45

Convetions for public/private - normal attribute name is public - attribute which is private we start it with _

class Pair:

    def __init__(self, x, y):
        self._x = x
        self._y = y 

    def get_x(self): # public attribute
        return self._x

    
p = Pair(45, 34)
p.get_x()
45
Pair
__main__.Pair
Pair.get_x
<function __main__.Pair.get_x(self)>
Pair.get_x()
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[74], line 1
----> 1 Pair.get_x()

TypeError: Pair.get_x() missing 1 required positional argument: 'self'
p = Pair(0, 0)
p.get_x()  # actually calls the function Pair.get_x(p)
0
Pair.get_x(p)
0
Pair(3, 4) # it will create empty instance..and that will be passed as self

Downloading from internet

pip install requests

import requests

Understanding HTTP protocol

https://vikrant.dev/python-foundation-professionals/module3-day1.html

https:// protocal name vikrant.dev is name of the machine on which webserver is running there is folder on server python-foundation-professionals inside that folder there is file module3-day1.html

  • get - get the resourse pointed by url
  • post - in addition to hidden parameters and url
  • put - put a resource at the url location
  • delete - delete a resource from given url location
url = "https://vikrant.dev/python-foundation-professionals/module3-day1.html"
r = requests.get(url)
r.status_code # status 200 means it worked!
200
print(r.text[:1000])
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head>

<meta charset="utf-8">
<meta name="generator" content="quarto-1.8.26">

<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">


<title>Module III - Day I – Python Foundation</title>
<style>
code{white-space: pre-wrap;}
span.smallcaps{font-variant: small-caps;}
div.columns{display: flex; gap: min(4vw, 1.5em);}
div.column{flex: auto; overflow-x: auto;}
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
ul.task-list{list-style: none;}
ul.task-list li input[type="checkbox"] {
  width: 0.8em;
  margin: 0 0.8em 0.2em -1em; /* quarto-specific, see https://github.com/quarto-dev/quarto-cli/issues/4556 */ 
  vertical-align: middle;
}
/* CSS for syntax highlighting */
html { -webkit-text-size-adjust: 100%; }
pre > code.sourceCode { white-space: pre; position: relative; }
pre > code.sourceCode > span { display: inline-block; line-height: 1.25; }
pre > code.sour
def download_textfile(url, filename):
    print(f"Downloading ..{url}")
    r = requests.get(url)
    if r.status_code == 200:
        print(f"Saving it to {filename}")
        with open(filename, "w") as f:
            f.write(r.text)
download_textfile(url, "sample.html")
Downloading ..https://vikrant.dev/python-foundation-professionals/module3-day1.html
Saving it to sample.html
def download(url, filename):
    print(f"Downloading {url}")
    r = requests.get(url)
    if r.status_code == 200:
        with open(filename, "wb") as f:
            print(f"Saving it to {filename}")
            f.write(r.content) # content is binary data
download(url, "sample1.html")
Downloading https://vikrant.dev/python-foundation-professionals/module3-day1.html
Saving it to sample1.html
excelurl = "https://raw.githubusercontent.com/vikipedia/python-trainings/master/online_course/source/module2/wallet.xlsx"
download(excelurl, "wallet.xlsx")
Downloading https://raw.githubusercontent.com/vikipedia/python-trainings/master/online_course/source/module2/wallet.xlsx
Saving it to wallet.xlsx

API call

url = "https://www.alphavantage.co/query"
API_KEY = "demo"  # "UKVFE0JLE0TBPDEF"
p = {"function": "TIME_SERIES_INTRADAY",
     "symbol": "IBM",
     "interval": "5min",
     "apikey": API_KEY}
r = requests.get(url, params=p)
r.status_code
200
r.json()
{'Meta Data': {'1. Information': 'Intraday (5min) open, high, low, close prices and volume',
  '2. Symbol': 'IBM',
  '3. Last Refreshed': '2026-02-09 19:55:00',
  '4. Interval': '5min',
  '5. Output Size': 'Compact',
  '6. Time Zone': 'US/Eastern'},
 'Time Series (5min)': {'2026-02-09 19:55:00': {'1. open': '296.6000',
   '2. high': '296.6000',
   '3. low': '296.3604',
   '4. close': '296.3604',
   '5. volume': '54'},
  '2026-02-09 19:50:00': {'1. open': '296.6000',
   '2. high': '296.6000',
   '3. low': '296.5900',
   '4. close': '296.5900',
   '5. volume': '21'},
  '2026-02-09 19:45:00': {'1. open': '296.5300',
   '2. high': '296.6900',
   '3. low': '296.3400',
   '4. close': '296.3400',
   '5. volume': '424'},
  '2026-02-09 19:40:00': {'1. open': '296.3400',
   '2. high': '296.5300',
   '3. low': '296.3400',
   '4. close': '296.5300',
   '5. volume': '46'},
  '2026-02-09 19:30:00': {'1. open': '296.1800',
   '2. high': '296.2590',
   '3. low': '296.1800',
   '4. close': '296.2590',
   '5. volume': '10'},
  '2026-02-09 19:25:00': {'1. open': '296.3400',
   '2. high': '296.3400',
   '3. low': '296.3399',
   '4. close': '296.3400',
   '5. volume': '297'},
  '2026-02-09 19:20:00': {'1. open': '296.3300',
   '2. high': '296.3400',
   '3. low': '296.3300',
   '4. close': '296.3400',
   '5. volume': '4'},
  '2026-02-09 19:15:00': {'1. open': '296.2800',
   '2. high': '296.3000',
   '3. low': '296.2200',
   '4. close': '296.2200',
   '5. volume': '21'},
  '2026-02-09 19:10:00': {'1. open': '296.3400',
   '2. high': '296.3400',
   '3. low': '296.3200',
   '4. close': '296.3200',
   '5. volume': '124'},
  '2026-02-09 19:05:00': {'1. open': '296.3500',
   '2. high': '296.3500',
   '3. low': '296.3500',
   '4. close': '296.3500',
   '5. volume': '14'},
  '2026-02-09 19:00:00': {'1. open': '296.3400',
   '2. high': '296.5900',
   '3. low': '296.3400',
   '4. close': '296.3544',
   '5. volume': '702177'},
  '2026-02-09 18:55:00': {'1. open': '296.3500',
   '2. high': '296.5500',
   '3. low': '296.3500',
   '4. close': '296.4100',
   '5. volume': '11'},
  '2026-02-09 18:50:00': {'1. open': '296.3700',
   '2. high': '296.6311',
   '3. low': '296.3400',
   '4. close': '296.3400',
   '5. volume': '259'},
  '2026-02-09 18:45:00': {'1. open': '296.6400',
   '2. high': '296.6900',
   '3. low': '296.3800',
   '4. close': '296.3800',
   '5. volume': '27'},
  '2026-02-09 18:40:00': {'1. open': '296.6389',
   '2. high': '296.6400',
   '3. low': '296.6389',
   '4. close': '296.6400',
   '5. volume': '26'},
  '2026-02-09 18:35:00': {'1. open': '296.6900',
   '2. high': '296.6900',
   '3. low': '296.6900',
   '4. close': '296.6900',
   '5. volume': '20'},
  '2026-02-09 18:30:00': {'1. open': '296.3400',
   '2. high': '296.6365',
   '3. low': '296.3400',
   '4. close': '296.3824',
   '5. volume': '702072'},
  '2026-02-09 18:25:00': {'1. open': '296.3800',
   '2. high': '296.3942',
   '3. low': '296.3400',
   '4. close': '296.3942',
   '5. volume': '8'},
  '2026-02-09 18:20:00': {'1. open': '296.2500',
   '2. high': '296.6800',
   '3. low': '296.2500',
   '4. close': '296.6800',
   '5. volume': '243'},
  '2026-02-09 18:15:00': {'1. open': '296.3400',
   '2. high': '296.5000',
   '3. low': '296.2500',
   '4. close': '296.2500',
   '5. volume': '20'},
  '2026-02-09 18:10:00': {'1. open': '296.6000',
   '2. high': '296.6400',
   '3. low': '296.4600',
   '4. close': '296.4900',
   '5. volume': '411'},
  '2026-02-09 18:05:00': {'1. open': '296.6400',
   '2. high': '296.6900',
   '3. low': '296.6400',
   '4. close': '296.6900',
   '5. volume': '104'},
  '2026-02-09 18:00:00': {'1. open': '296.5700',
   '2. high': '296.5700',
   '3. low': '296.5700',
   '4. close': '296.5700',
   '5. volume': '14'},
  '2026-02-09 17:55:00': {'1. open': '296.6000',
   '2. high': '296.6500',
   '3. low': '296.5012',
   '4. close': '296.6494',
   '5. volume': '20'},
  '2026-02-09 17:50:00': {'1. open': '296.5600',
   '2. high': '296.6000',
   '3. low': '296.5600',
   '4. close': '296.6000',
   '5. volume': '19'},
  '2026-02-09 17:45:00': {'1. open': '296.5232',
   '2. high': '296.5232',
   '3. low': '296.5232',
   '4. close': '296.5232',
   '5. volume': '5'},
  '2026-02-09 17:40:00': {'1. open': '296.6200',
   '2. high': '296.6200',
   '3. low': '296.5500',
   '4. close': '296.5500',
   '5. volume': '10'},
  '2026-02-09 17:35:00': {'1. open': '296.6201',
   '2. high': '296.6500',
   '3. low': '296.6201',
   '4. close': '296.6500',
   '5. volume': '30'},
  '2026-02-09 17:30:00': {'1. open': '296.5000',
   '2. high': '296.6495',
   '3. low': '296.5000',
   '4. close': '296.6100',
   '5. volume': '16'},
  '2026-02-09 17:25:00': {'1. open': '296.6494',
   '2. high': '296.6500',
   '3. low': '296.5000',
   '4. close': '296.6500',
   '5. volume': '20'},
  '2026-02-09 17:20:00': {'1. open': '296.6800',
   '2. high': '296.6800',
   '3. low': '296.5000',
   '4. close': '296.5000',
   '5. volume': '80'},
  '2026-02-09 17:15:00': {'1. open': '296.5000',
   '2. high': '296.6895',
   '3. low': '296.5000',
   '4. close': '296.6600',
   '5. volume': '61'},
  '2026-02-09 17:10:00': {'1. open': '296.5700',
   '2. high': '296.6300',
   '3. low': '296.3400',
   '4. close': '296.3400',
   '5. volume': '967'},
  '2026-02-09 17:05:00': {'1. open': '296.6690',
   '2. high': '296.7000',
   '3. low': '296.5700',
   '4. close': '296.5700',
   '5. volume': '12'},
  '2026-02-09 17:00:00': {'1. open': '296.4900',
   '2. high': '296.5800',
   '3. low': '296.4600',
   '4. close': '296.5500',
   '5. volume': '136'},
  '2026-02-09 16:55:00': {'1. open': '296.4400',
   '2. high': '296.4900',
   '3. low': '296.3000',
   '4. close': '296.4900',
   '5. volume': '18156'},
  '2026-02-09 16:50:00': {'1. open': '296.4300',
   '2. high': '296.4300',
   '3. low': '296.4300',
   '4. close': '296.4300',
   '5. volume': '1'},
  '2026-02-09 16:45:00': {'1. open': '296.3790',
   '2. high': '296.4800',
   '3. low': '296.3100',
   '4. close': '296.4800',
   '5. volume': '68'},
  '2026-02-09 16:40:00': {'1. open': '296.4700',
   '2. high': '296.5000',
   '3. low': '296.3400',
   '4. close': '296.4000',
   '5. volume': '8584'},
  '2026-02-09 16:35:00': {'1. open': '296.5000',
   '2. high': '296.5100',
   '3. low': '296.4900',
   '4. close': '296.4900',
   '5. volume': '5'},
  '2026-02-09 16:30:00': {'1. open': '296.3324',
   '2. high': '296.5000',
   '3. low': '296.3324',
   '4. close': '296.5000',
   '5. volume': '25'},
  '2026-02-09 16:25:00': {'1. open': '296.2100',
   '2. high': '296.3300',
   '3. low': '296.2100',
   '4. close': '296.2100',
   '5. volume': '34'},
  '2026-02-09 16:20:00': {'1. open': '296.3000',
   '2. high': '297.0000',
   '3. low': '296.3000',
   '4. close': '296.3000',
   '5. volume': '255'},
  '2026-02-09 16:15:00': {'1. open': '296.3400',
   '2. high': '298.9300',
   '3. low': '296.2100',
   '4. close': '296.3200',
   '5. volume': '2141'},
  '2026-02-09 16:10:00': {'1. open': '296.3400',
   '2. high': '298.9300',
   '3. low': '296.2100',
   '4. close': '298.9300',
   '5. volume': '702348'},
  '2026-02-09 16:05:00': {'1. open': '296.3400',
   '2. high': '296.5800',
   '3. low': '295.9209',
   '4. close': '296.5800',
   '5. volume': '1134'},
  '2026-02-09 16:00:00': {'1. open': '296.3600',
   '2. high': '296.6000',
   '3. low': '295.6400',
   '4. close': '296.3400',
   '5. volume': '1500937'},
  '2026-02-09 15:55:00': {'1. open': '296.4100',
   '2. high': '296.8900',
   '3. low': '296.2500',
   '4. close': '296.3200',
   '5. volume': '257505'},
  '2026-02-09 15:50:00': {'1. open': '296.9000',
   '2. high': '297.0300',
   '3. low': '296.2800',
   '4. close': '296.4400',
   '5. volume': '135844'},
  '2026-02-09 15:45:00': {'1. open': '296.7850',
   '2. high': '297.0600',
   '3. low': '296.7500',
   '4. close': '296.9100',
   '5. volume': '61653'},
  '2026-02-09 15:40:00': {'1. open': '296.7550',
   '2. high': '296.9600',
   '3. low': '296.6400',
   '4. close': '296.7600',
   '5. volume': '45662'},
  '2026-02-09 15:35:00': {'1. open': '296.6593',
   '2. high': '296.7900',
   '3. low': '296.2950',
   '4. close': '296.7550',
   '5. volume': '46918'},
  '2026-02-09 15:30:00': {'1. open': '297.0100',
   '2. high': '297.0100',
   '3. low': '296.5750',
   '4. close': '296.5900',
   '5. volume': '60736'},
  '2026-02-09 15:25:00': {'1. open': '297.4200',
   '2. high': '297.5500',
   '3. low': '296.9400',
   '4. close': '296.9750',
   '5. volume': '36754'},
  '2026-02-09 15:20:00': {'1. open': '297.1700',
   '2. high': '297.4700',
   '3. low': '297.0950',
   '4. close': '297.4200',
   '5. volume': '46148'},
  '2026-02-09 15:15:00': {'1. open': '297.5600',
   '2. high': '297.5600',
   '3. low': '297.0725',
   '4. close': '297.1700',
   '5. volume': '32640'},
  '2026-02-09 15:10:00': {'1. open': '297.4750',
   '2. high': '297.7200',
   '3. low': '297.4000',
   '4. close': '297.5480',
   '5. volume': '28309'},
  '2026-02-09 15:05:00': {'1. open': '297.0100',
   '2. high': '297.5900',
   '3. low': '296.9750',
   '4. close': '297.5000',
   '5. volume': '237402'},
  '2026-02-09 15:00:00': {'1. open': '297.1700',
   '2. high': '297.2400',
   '3. low': '296.8800',
   '4. close': '296.9750',
   '5. volume': '31310'},
  '2026-02-09 14:55:00': {'1. open': '297.1000',
   '2. high': '297.2300',
   '3. low': '296.9900',
   '4. close': '297.1350',
   '5. volume': '29220'},
  '2026-02-09 14:50:00': {'1. open': '296.8801',
   '2. high': '297.1800',
   '3. low': '296.8801',
   '4. close': '297.1000',
   '5. volume': '30047'},
  '2026-02-09 14:45:00': {'1. open': '296.9915',
   '2. high': '297.0000',
   '3. low': '296.7500',
   '4. close': '296.9400',
   '5. volume': '31926'},
  '2026-02-09 14:40:00': {'1. open': '297.3800',
   '2. high': '297.5300',
   '3. low': '296.8900',
   '4. close': '296.9750',
   '5. volume': '38999'},
  '2026-02-09 14:35:00': {'1. open': '297.5400',
   '2. high': '297.7000',
   '3. low': '297.3200',
   '4. close': '297.3800',
   '5. volume': '38613'},
  '2026-02-09 14:30:00': {'1. open': '297.3200',
   '2. high': '297.6000',
   '3. low': '297.2200',
   '4. close': '297.6000',
   '5. volume': '51778'},
  '2026-02-09 14:25:00': {'1. open': '297.3100',
   '2. high': '297.3750',
   '3. low': '297.0900',
   '4. close': '297.2700',
   '5. volume': '38721'},
  '2026-02-09 14:20:00': {'1. open': '296.5400',
   '2. high': '297.3400',
   '3. low': '296.5201',
   '4. close': '297.3400',
   '5. volume': '48695'},
  '2026-02-09 14:15:00': {'1. open': '296.2200',
   '2. high': '296.5700',
   '3. low': '296.1222',
   '4. close': '296.5700',
   '5. volume': '48274'},
  '2026-02-09 14:10:00': {'1. open': '295.9200',
   '2. high': '296.3600',
   '3. low': '295.9000',
   '4. close': '296.2200',
   '5. volume': '29424'},
  '2026-02-09 14:05:00': {'1. open': '295.5450',
   '2. high': '295.9899',
   '3. low': '295.5000',
   '4. close': '295.8700',
   '5. volume': '33886'},
  '2026-02-09 14:00:00': {'1. open': '295.1000',
   '2. high': '295.5997',
   '3. low': '295.0600',
   '4. close': '295.5900',
   '5. volume': '26693'},
  '2026-02-09 13:55:00': {'1. open': '294.9600',
   '2. high': '295.2000',
   '3. low': '294.9600',
   '4. close': '295.1150',
   '5. volume': '30817'},
  '2026-02-09 13:50:00': {'1. open': '294.7100',
   '2. high': '294.9600',
   '3. low': '294.6800',
   '4. close': '294.9300',
   '5. volume': '19793'},
  '2026-02-09 13:45:00': {'1. open': '295.0300',
   '2. high': '295.1100',
   '3. low': '294.6800',
   '4. close': '294.6800',
   '5. volume': '30177'},
  '2026-02-09 13:40:00': {'1. open': '294.5100',
   '2. high': '295.0200',
   '3. low': '294.2800',
   '4. close': '295.0000',
   '5. volume': '37941'},
  '2026-02-09 13:35:00': {'1. open': '294.6100',
   '2. high': '294.6899',
   '3. low': '294.4200',
   '4. close': '294.4750',
   '5. volume': '16500'},
  '2026-02-09 13:30:00': {'1. open': '294.1500',
   '2. high': '294.5900',
   '3. low': '294.0900',
   '4. close': '294.5900',
   '5. volume': '42024'},
  '2026-02-09 13:25:00': {'1. open': '293.9300',
   '2. high': '294.2900',
   '3. low': '293.8600',
   '4. close': '294.1600',
   '5. volume': '29760'},
  '2026-02-09 13:20:00': {'1. open': '293.7600',
   '2. high': '294.0600',
   '3. low': '293.3000',
   '4. close': '293.9300',
   '5. volume': '47663'},
  '2026-02-09 13:15:00': {'1. open': '294.2800',
   '2. high': '294.3300',
   '3. low': '293.5100',
   '4. close': '293.7075',
   '5. volume': '116778'},
  '2026-02-09 13:10:00': {'1. open': '294.3300',
   '2. high': '294.4000',
   '3. low': '294.0750',
   '4. close': '294.2200',
   '5. volume': '15912'},
  '2026-02-09 13:05:00': {'1. open': '293.4800',
   '2. high': '294.3800',
   '3. low': '293.3000',
   '4. close': '294.2600',
   '5. volume': '35817'},
  '2026-02-09 13:00:00': {'1. open': '293.5700',
   '2. high': '293.6200',
   '3. low': '293.2500',
   '4. close': '293.4600',
   '5. volume': '35708'},
  '2026-02-09 12:55:00': {'1. open': '293.7150',
   '2. high': '293.8199',
   '3. low': '293.5200',
   '4. close': '293.5400',
   '5. volume': '26016'},
  '2026-02-09 12:50:00': {'1. open': '294.0300',
   '2. high': '294.0350',
   '3. low': '293.6100',
   '4. close': '293.7250',
   '5. volume': '25613'},
  '2026-02-09 12:45:00': {'1. open': '293.7100',
   '2. high': '294.0300',
   '3. low': '293.5900',
   '4. close': '294.0300',
   '5. volume': '37694'},
  '2026-02-09 12:40:00': {'1. open': '293.5750',
   '2. high': '293.7750',
   '3. low': '293.4501',
   '4. close': '293.7600',
   '5. volume': '31428'},
  '2026-02-09 12:35:00': {'1. open': '294.2500',
   '2. high': '294.3800',
   '3. low': '293.5100',
   '4. close': '293.5750',
   '5. volume': '62149'},
  '2026-02-09 12:30:00': {'1. open': '294.3200',
   '2. high': '294.3450',
   '3. low': '293.9000',
   '4. close': '294.2500',
   '5. volume': '25524'},
  '2026-02-09 12:25:00': {'1. open': '294.4400',
   '2. high': '294.4899',
   '3. low': '294.0850',
   '4. close': '294.3250',
   '5. volume': '34868'},
  '2026-02-09 12:20:00': {'1. open': '294.4750',
   '2. high': '294.6500',
   '3. low': '294.2800',
   '4. close': '294.4050',
   '5. volume': '22785'},
  '2026-02-09 12:15:00': {'1. open': '294.5750',
   '2. high': '294.7800',
   '3. low': '294.3550',
   '4. close': '294.4750',
   '5. volume': '30493'},
  '2026-02-09 12:10:00': {'1. open': '294.5200',
   '2. high': '294.7154',
   '3. low': '294.4200',
   '4. close': '294.5300',
   '5. volume': '29345'},
  '2026-02-09 12:05:00': {'1. open': '294.3880',
   '2. high': '294.5900',
   '3. low': '294.2700',
   '4. close': '294.5300',
   '5. volume': '27059'},
  '2026-02-09 12:00:00': {'1. open': '294.3850',
   '2. high': '294.7099',
   '3. low': '294.3280',
   '4. close': '294.3750',
   '5. volume': '33297'},
  '2026-02-09 11:55:00': {'1. open': '293.8600',
   '2. high': '294.6600',
   '3. low': '293.7839',
   '4. close': '294.3150',
   '5. volume': '67469'},
  '2026-02-09 11:50:00': {'1. open': '293.9800',
   '2. high': '294.0000',
   '3. low': '293.7701',
   '4. close': '293.8600',
   '5. volume': '33729'},
  '2026-02-09 11:45:00': {'1. open': '293.4200',
   '2. high': '294.0200',
   '3. low': '293.4200',
   '4. close': '293.9700',
   '5. volume': '34428'},
  '2026-02-09 11:40:00': {'1. open': '292.8700',
   '2. high': '293.6500',
   '3. low': '292.8700',
   '4. close': '293.4800',
   '5. volume': '49376'},
  '2026-02-09 11:35:00': {'1. open': '293.3300',
   '2. high': '293.4600',
   '3. low': '292.8000',
   '4. close': '292.8700',
   '5. volume': '41140'}}}
data = r.json()
type(data)
dict
data.keys()
dict_keys(['Meta Data', 'Time Series (5min)'])
data['Meta Data']
{'1. Information': 'Intraday (5min) open, high, low, close prices and volume',
 '2. Symbol': 'IBM',
 '3. Last Refreshed': '2026-02-09 19:55:00',
 '4. Interval': '5min',
 '5. Output Size': 'Compact',
 '6. Time Zone': 'US/Eastern'}
type(data['Time Series (5min)'])
dict
data['Time Series (5min)'].keys()
dict_keys(['2026-02-09 19:55:00', '2026-02-09 19:50:00', '2026-02-09 19:45:00', '2026-02-09 19:40:00', '2026-02-09 19:30:00', '2026-02-09 19:25:00', '2026-02-09 19:20:00', '2026-02-09 19:15:00', '2026-02-09 19:10:00', '2026-02-09 19:05:00', '2026-02-09 19:00:00', '2026-02-09 18:55:00', '2026-02-09 18:50:00', '2026-02-09 18:45:00', '2026-02-09 18:40:00', '2026-02-09 18:35:00', '2026-02-09 18:30:00', '2026-02-09 18:25:00', '2026-02-09 18:20:00', '2026-02-09 18:15:00', '2026-02-09 18:10:00', '2026-02-09 18:05:00', '2026-02-09 18:00:00', '2026-02-09 17:55:00', '2026-02-09 17:50:00', '2026-02-09 17:45:00', '2026-02-09 17:40:00', '2026-02-09 17:35:00', '2026-02-09 17:30:00', '2026-02-09 17:25:00', '2026-02-09 17:20:00', '2026-02-09 17:15:00', '2026-02-09 17:10:00', '2026-02-09 17:05:00', '2026-02-09 17:00:00', '2026-02-09 16:55:00', '2026-02-09 16:50:00', '2026-02-09 16:45:00', '2026-02-09 16:40:00', '2026-02-09 16:35:00', '2026-02-09 16:30:00', '2026-02-09 16:25:00', '2026-02-09 16:20:00', '2026-02-09 16:15:00', '2026-02-09 16:10:00', '2026-02-09 16:05:00', '2026-02-09 16:00:00', '2026-02-09 15:55:00', '2026-02-09 15:50:00', '2026-02-09 15:45:00', '2026-02-09 15:40:00', '2026-02-09 15:35:00', '2026-02-09 15:30:00', '2026-02-09 15:25:00', '2026-02-09 15:20:00', '2026-02-09 15:15:00', '2026-02-09 15:10:00', '2026-02-09 15:05:00', '2026-02-09 15:00:00', '2026-02-09 14:55:00', '2026-02-09 14:50:00', '2026-02-09 14:45:00', '2026-02-09 14:40:00', '2026-02-09 14:35:00', '2026-02-09 14:30:00', '2026-02-09 14:25:00', '2026-02-09 14:20:00', '2026-02-09 14:15:00', '2026-02-09 14:10:00', '2026-02-09 14:05:00', '2026-02-09 14:00:00', '2026-02-09 13:55:00', '2026-02-09 13:50:00', '2026-02-09 13:45:00', '2026-02-09 13:40:00', '2026-02-09 13:35:00', '2026-02-09 13:30:00', '2026-02-09 13:25:00', '2026-02-09 13:20:00', '2026-02-09 13:15:00', '2026-02-09 13:10:00', '2026-02-09 13:05:00', '2026-02-09 13:00:00', '2026-02-09 12:55:00', '2026-02-09 12:50:00', '2026-02-09 12:45:00', '2026-02-09 12:40:00', '2026-02-09 12:35:00', '2026-02-09 12:30:00', '2026-02-09 12:25:00', '2026-02-09 12:20:00', '2026-02-09 12:15:00', '2026-02-09 12:10:00', '2026-02-09 12:05:00', '2026-02-09 12:00:00', '2026-02-09 11:55:00', '2026-02-09 11:50:00', '2026-02-09 11:45:00', '2026-02-09 11:40:00', '2026-02-09 11:35:00'])
import pandas as pd
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
Cell In[107], line 1
----> 1 import pandas as pd

ModuleNotFoundError: No module named 'pandas'
!pip install pandas
Collecting pandas

  Downloading pandas-3.0.0-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.metadata (79 kB)

Collecting numpy>=1.26.0 (from pandas)

  Using cached numpy-2.4.2-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.metadata (6.6 kB)

Requirement already satisfied: python-dateutil>=2.8.2 in /home/vikrant/usr/local/default/lib/python3.13/site-packages (from pandas) (2.9.0.post0)

Requirement already satisfied: six>=1.5 in /home/vikrant/usr/local/default/lib/python3.13/site-packages (from python-dateutil>=2.8.2->pandas) (1.17.0)

Downloading pandas-3.0.0-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (10.9 MB)

   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 10.9/10.9 MB 6.6 MB/s eta 0:00:00m eta 0:00:0136m0:00:01m

Using cached numpy-2.4.2-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (16.6 MB)

Installing collected packages: numpy, pandas

   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2/2 [pandas]━━━━ 1/2 [pandas]

Successfully installed numpy-2.4.2 pandas-3.0.0
import pandas as pd
pd.DataFrame(data['Time Series (5min)']).T
1. open 2. high 3. low 4. close 5. volume
2026-02-09 19:55:00 296.6000 296.6000 296.3604 296.3604 54
2026-02-09 19:50:00 296.6000 296.6000 296.5900 296.5900 21
2026-02-09 19:45:00 296.5300 296.6900 296.3400 296.3400 424
2026-02-09 19:40:00 296.3400 296.5300 296.3400 296.5300 46
2026-02-09 19:30:00 296.1800 296.2590 296.1800 296.2590 10
... ... ... ... ... ...
2026-02-09 11:55:00 293.8600 294.6600 293.7839 294.3150 67469
2026-02-09 11:50:00 293.9800 294.0000 293.7701 293.8600 33729
2026-02-09 11:45:00 293.4200 294.0200 293.4200 293.9700 34428
2026-02-09 11:40:00 292.8700 293.6500 292.8700 293.4800 49376
2026-02-09 11:35:00 293.3300 293.4600 292.8000 292.8700 41140

100 rows × 5 columns

Authentication

%%file passkey.txt
tyt%^^%@#
Writing passkey.txt
user = "vikrant"
with open("passkey.txt") as f:
    password = f.read()
url = "https://httpbin.org/get" 
r = requests.get(url, auth=(user, password))
r.status_code
200
r.json()
{'args': {},
 'headers': {'Accept': '*/*',
  'Accept-Encoding': 'gzip, deflate',
  'Authorization': 'Basic dmlrcmFudDp0eXQlXl4lQCMK',
  'Host': 'httpbin.org',
  'User-Agent': 'python-requests/2.32.5',
  'X-Amzn-Trace-Id': 'Root=1-698a9ed5-77f74bef566e41387a822408'},
 'origin': '103.215.167.18',
 'url': 'https://httpbin.org/get'}

homework

Write a function download_notes which will download all notes from our training website - It should create a folder first - then download notebook html for each day for each module in that folder - can you also create a index page through python function so that you can access the notes by opening index.html?

Observe the pattern of urls for example there is module number and day for each notebook.

  • https://vikrant.dev/python-foundation-professionals/module1-day1.html
  • https://vikrant.dev/python-foundation-professionals/module1-day2.html
  • https://vikrant.dev/python-foundation-professionals/module2-day1.html