def Volatility(directory_vol):
    try:
        if not os.listdir(directory_vol):
            os.rmkdir(directory_vol)
    except:
        if not os.path.exists(directory_vol):
            os.mkdir(directory_vol)  ###shifting through the days
            for day in range(1, 32):
                if day not in holidays:
                    if (day <= 9):
                        url = 'https://www.nseindia.com/archives/nsccl/volt/FOVOLT_0{}0{}2017.csv'
                        r = requests.get(url.format(day, month_in_num))
                        file_name = "fovolt_0{}0{}2017.csv"
                        modified_f_name = file_name.format(day, month_in_num)

                        ###os.path.join is used to merge the creating .zip files into the current /bhav_cpy dir
                        with open(os.path.join(directory_vol, modified_f_name),
                                  "wb") as code:
                            code.write(r.content)
                    else:
                        url = 'https://www.nseindia.com/archives/nsccl/volt/FOVOLT_{}0{}2017.csv'
                        r = requests.get(url.format(day, month_in_num))
                        file_name = "fovolt_{}0{}2017.csv"
                        modified_f_name = file_name.format(day, month_in_num)
                        with open(os.path.join(directory_vol, modified_f_name),
                                  "wb") as code:
                            code.write(r.content)
                else:
                    pass
def Monthly_bhav(directory_bhav):
    ###checks the desired dir exists else creates a new dir
    try:
        if not os.listdir(directory_bhav):
            os.rmkdir(directory_bhav)
    except:
        if not os.path.exists(directory_bhav):
            os.mkdir(directory_bhav)  ###shifting through the days
            for i in range(1, 32):
                if i not in holidays:
                    if (i <= 9):
                        url = 'http://www.nseindia.com/content/historical/DERIVATIVES/2017/{}/fo0{}{}2017bhav.csv.zip'
                        r = requests.get(url.format(month, i, month))
                        file_name = "fo0{}{}2017bhav.zip"
                        modified_f_name = file_name.format(i, month)

                        ###os.path.join is used to merge the creating .zip files into the current /bhav_cpy dir
                        with open(
                                os.path.join(directory_bhav, modified_f_name),
                                "wb") as code:
                            code.write(r.content)
                    else:
                        url = 'http://www.nseindia.com/content/historical/DERIVATIVES/2017/{}/fo{}{}2017bhav.csv.zip'
                        r = requests.get(url.format(month, i, month))
                        file_name = "fo{}{}2017bhav.zip"
                        modified_f_name = file_name.format(i, month)
                        with open(
                                os.path.join(directory_bhav, modified_f_name),
                                "wb") as code:
                            code.write(r.content)
                else:
                    pass
def Open_interest(directory_oi):
    try:
        if not os.listdir(directory_oi):
            os.rmkdir(directory_oi)
    except:
        if not os.path.exists(directory_oi):
            os.mkdir(directory_oi)  ###shifting through the days
            for i in range(1, 32):
                if i not in holidays:
                    if (i <= 9):
                        url = 'https://www.nseindia.com/archives/nsccl/mwpl/nseoi_0{}0{}2017.zip'
                        r = requests.get(url.format(i, month_in_num))
                        file_name = "nseoi_0{}0{}2017.zip"
                        modified_f_name = file_name.format(i, month_in_num)

                        ###os.path.join is used to merge the creating .zip files into the current /bhav_cpy dir
                        with open(os.path.join(directory_oi, modified_f_name),
                                  "wb") as code:
                            code.write(r.content)
                    else:
                        url = 'https://www.nseindia.com/archives/nsccl/mwpl/nseoi_{}0{}2017.zip'
                        r = requests.get(url.format(i, month_in_num))
                        file_name = "nseoi_{}0{}2017.zip"
                        modified_f_name = file_name.format(i, month_in_num)
                        with open(os.path.join(directory_oi, modified_f_name),
                                  "wb") as code:
                            code.write(r.content)
                else:
                    pass
Пример #4
0
    dir_fd (optional) : A file descriptor referring to a directory.
                        The default value of this parameter is None.
                        If the specified path is absolute then dir_fd is ignored.

    Note: The ‘*’ in parameter list indicates that all following parameters (Here in our case ‘dir_fd’)
          are keyword-only parameters and they can be provided using their name, not as positional parameter.

    Return Type: This method does not return any value.

import os
os.chdir(r"C:\Users\dell\Desktop")

os.mkdir('mon')    '''OR''' os.mkdir(r"C:\Users\dell\Desktop\mon") 
# create folder named mon on desktop

os.rmdir('mon')     '''OR''' os.rmkdir(r"C:\Users\dell\Desktop\mon") 
#delete folder named mon on desktop

    
##cannot delete folder inside a folder
os.makedirs(r'mon\non')
os.rmdir(r'mon')
##OSError: [WinError 145] The directory is not empty: 'mon'


                            '''8. os.removedirs():'''

    Syntax      : os.removedirs(path)
    Paramete    :
    path        : A path-like object representing a file path. A path-like object is either a string
                  or bytes object representing a path.
Пример #5
0
import os

print(os.name)

print(os.uname())

print(os.environ.get('PATH'))

print(os.path.abspath('.'))

print(os.path.join('/Users/tmd/Desktop/learn-python/IO', 'testdir'))

os.mkdir('/Users/tmd/Desktop/learn-python/IO/testdir')

os.rmkdir('/Users/tmd/Desktop/learn-python/IO/testdir')