Skip to content

coderooz/My_simple_functions

Repository files navigation

Personal EveryDay Usage Functions

Project Author Details:

Contents:

  1. Project Info
  2. Project Files
  3. Files Description

This is just a personal project where I make classes and fuctions that will help me do certain task more effectiely rather that re-codig them again and again.

Project Files are:-

File Descriptions

The file AsyncHandler encases a class called AsyncHandler(). This class is used to do task asuncronuslly.

The file DataHandler encases a class called DataHandler(). This class is used to menial tasks that usually require rewriting of a lot of code.

This class is used for handleling data related tasks

Functions of the class:-

  • timestamp: Returns the date and time in the specified format.
data = timestamp(given_time, format= "%Y-%m-%d %H:%M:%S", time_zone=None, normalize:str='sec')
print(data)
#output:  

The file DbSqliteHandler encases a class called DbSqliteHandler. This class is used creating and managing SQLITE3 databases.

  • Initializaton of database: When initalizing the database, on emust provide the desired database name. If the database existes, the class will just connect it else if the the database doesnot exist, then the database will be created and connectionn will be established.

    import DbSqliteHandler
    dbConn = DbSqliteHandler('db_name.db')
    
  • create(): If the database is created newly, then the database will require a table to function properly, or else the db will just remain as file in the system. So to create a table we need to use the class method called createTb().

    • Parameter:
    • Usage:
    tb_name = 'table_1'
    columns = ['col1', 'col2']
    ## or you can specify the datatype like this.
    columns = ['col1 TEXT', 'col2 INT']
    dbConn.createTb(tb_name, columns)
    

    The method also comes with the feature of adding data along side creating the table raher than writing a special code for it and also comes with the feature to primary key while creating the table.

    col = ['col1', 'col2']
    data = ['data1', 'data2']
    dbConn.createTb(tbName, columns=col, insertData=data, addId=False, idKey='id')
    
  • insert:

    • Parameter:
    • Usage:
    
    
  • json_insert:

    • Parameter:
    • Usage:
    
    
  • fetch:

    • Parameter:
    • Usage:
    
    
  • getCount: This method counts the number of rows in the specified table. This method also allows or count with special queries like col1='tofu'.

    • Parameter:
      • table_name : Takes the name of table.
      • query : Takes the search query. Default is '' meaning, there is no search parameter and will count all the rows in the table.
    • Returns: int
    • Usage:
    query = "col1='tofu'"
    num = dbconn.getCount(table_name, query)
    print(num) ##prints out the number of row with col1 value as tofu.
    
  • update:

    • Parameter:
    • Usage:
    
    
  • delTb:

    • Parameter:
    • Usage:
    
    
  • renameTb:

    • Parameter:
    • Usage:
    
    
  • getTb:

    • Parameter:
    • Usage:
    
    
  • getTbData:

    • Parameter:
    • Usage:
    
    
  • execute:

    • Parameter:
    • Usage:
    
    
  • alterTb:

    • Parameter:
    • Usage:
    
    
  • getColumnNames:

    • Parameter:
    • Usage:
    
    
  • get_table_info:

    • Parameter:
    • Usage:
    
    
  • modifyColumns:

    • Parameter:
    • Usage:
    
    
  • checkIndex:

    • Parameter:
    • Usage:
    
    
  • getIndexes:

    • Parameter:
    • Usage:
    
    
  • addIndex:

    • Parameter:
    • Usage:
    
    
  • delIndex:

    • Parameter:
    • Usage:
    
    
  • cleanTb:

    • Parameter:
    • Usage:
    
    
  • addColumn:

    • Parameter:
    • Usage:
    
    
  • renameColumn:

    • Parameter:
    • Usage:
    
    
  • removeColumn: Removes a column from the specified table.

    • Parameter:
    • Usage:
    
    
  • close_connection:This method for to close all the connections made to the db and also end the session.

The file Filehandler encases a class called Filehandler. This class is used for writing & reading file related tasks.

  • Initialization: The initiallization is a simple process. To use it , just add FileHandler.func_name() and it will work. Examples are below.
  • Class methods: The class method are as follows:
    • getFiles(): Gets the list for files and folder in the specified folder.
      • Parameter:
        • file_path: Takes the path of the folder that needs to be looked into.
        • catg : This parameter takes either 1 or 2, where 1 means to only look for files whereas 2 means to lik for directories. Default is 0. Which means both.
      • Return: list
      • Usage:
      folder_path = './test_folder' #folder present in the current directory.
      fi = getFiles(folder_path) # for both files and folder.
      print(fi) #output: [file1.txt, dir1, ....] 
      
    • get_only_filename():
    • getFileCatg():
    • splitFileName():
    • getExtention():
    • read():
    • write(): This function is to write files and add contents to it.
      • Parameter:
        • file_name : The name of the file.
        • data: The data to be written to the file.
        • separator: Optional separator to append after the data.
      • Usage:
          data = 'This is Hello World File.' #file contents
          fileName = 'test.txt' # the file name
          FileHandler.write()
      
    • write_over():
      • Parameter:
        • file_name : The name of the file.
        • data: The data to be written to the file.
        • separator: Optional separator to append after the data.
      • Usage:
          data = 'This is Hello World File.' #file contents
          fileName = 'test.txt' # the file name
          FileHandler.write()
      
    • read_csv():
      • Parameter:
        • file_name : The name of the file.
        • data: The data to be written to the file.
        • separator: Optional separator to append after the data.
      • Usage:
          data = 'This is Hello World File.' #file contents
          fileName = 'test.txt' # the file name
          FileHandler.write()
      
    • write_csv():
      • Parameter:
        • file_name : The name of the file.
        • data: The data to be written to the file.
        • separator: Optional separator to append after the data.
      • Usage:
          data = 'This is Hello World File.' #file contents
          fileName = 'test.txt' # the file name
          FileHandler.write()
      
    • read_excel():
      • Parameter:
        • file_name : The name of the file.
        • data: The data to be written to the file.
        • separator: Optional separator to append after the data.
      • Usage:
          data = 'This is Hello World File.' #file contents
          fileName = 'test.txt' # the file name
          FileHandler.write()
      
    • write_excel():
      • Parameter:
        • file_name : The name of the file.
        • data: The data to be written to the file.
        • separator: Optional separator to append after the data.
      • Usage:
          data = 'This is Hello World File.' #file contents
          fileName = 'test.txt' # the file name
          FileHandler.write()
      
    • read_pdf(): This function reads and returns the text values of the pdf. - Parameter: - file_name : The name of the file. - Usage: fileName = 'test.pdf' # the file name FileHandler.read_pdf()

The file HtmlScraper encases a class called HtmlScraper. This class is used to scraping HTML webpages with the help of Requester class along with beautifulSoup.

The file Requester encases a class called Requester. This class is used to request related tasks.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages