libs/status.py
def create_type_schema(cls, db):
        """
        Given a PostgreSQL connection, create enum type for response status and phrases.
        The intention is to save space by using enum type instead of strings directly in DB.
        :param db: A PostgresSQL DB connection instance.
        :return:
        """
        response_status_type_sql = "CREATE TYPE response_status AS ENUM ('responsive', 'unresponsive');"
        # A complete phrases include all HTTP status codes and four additional ones.
        phrases = [getattr(x, 'phrase').lower() for x in HTTPStatus] + ['domain not exist', 'ssl error',
                                                                        'connection timeout',
                                                                        'page content not expected']
        phrases = tuple(phrases)
        phrase_type_sql = f'CREATE TYPE phrase_status AS ENUM {phrases};'

        with db.cursor() as curs:
            for typename, sql in [('response_status', response_status_type_sql), ('phrase_status', phrase_type_sql)]:
                # Firstly check whether this type exits
                curs.execute(f"select 1 from pg_type where typname = '{typename}'")
                if curs.fetchone():  # Defined already, do nothing
                    continue
                curs.execute(sql)
        db.commit()

        Given a PostgreSQL connection, create enum type for response status and phrases.
        The intention is to save space by using enum type instead of strings directly in DB.
        :param db: A PostgresSQL DB connection instance.
        :return:
        
Given a PostgreSQL connection, create enum type for response status and phrases.
The intention is to save space by using enum type instead of strings directly in DB.
Given a PostgreSQL connection create enum type for response status and phrases . The intention is to save space by using enum type instead of strings directly in DB .
def create_type_schema(cls, db):
        response_status_type_sql = "CREATE TYPE response_status AS ENUM ('responsive', 'unresponsive');"
        phrases = [getattr(x, 'phrase').lower() for x in HTTPStatus] + ['domain not exist', 'ssl error',
                                                                        'connection timeout',
                                                                        'page content not expected']
        phrases = tuple(phrases)
        phrase_type_sql = f'CREATE TYPE phrase_status AS ENUM {phrases};'
        with db.cursor() as curs:
            for typename, sql in [('response_status', response_status_type_sql), ('phrase_status', phrase_type_sql)]:
                curs.execute(f"select 1 from pg_type where typname = '{typename}'")
                if curs.fetchone():  
                    continue
                curs.execute(sql)
        db.commit()
def create_type_schema ( cls , db ) : response_status_type_sql = "CREATE TYPE response_status AS ENUM ('responsive', 'unresponsive');" phrases = [ getattr ( x , 'phrase' ) . lower ( ) for x in HTTPStatus ] + [ 'domain not exist' , 'ssl error' , 'connection timeout' , 'page content not expected' ] phrases = tuple ( phrases ) phrase_type_sql = f'CREATE TYPE phrase_status AS ENUM {phrases};' with db . cursor ( ) as curs : for typename , sql in [ ( 'response_status' , response_status_type_sql ) , ( 'phrase_status' , phrase_type_sql ) ] : curs . execute ( f"select 1 from pg_type where typname = '{typename}'" ) if curs . fetchone ( ) : continue curs . execute ( sql ) db . commit ( )
Given a PostgreSQL connection, create enum type for response status and phrases.
Given a PostgreSQL connection create enum type for response status and phrases .
"""
        Given a PostgreSQL connection, create enum type for response status and phrases.
        The intention is to save space by using enum type instead of strings directly in DB.
        :param db: A PostgresSQL DB connection instance.
        :return:
        """ # A complete phrases include all HTTP status codes and four additional ones. # Firstly check whether this type exits # Defined already, do nothing
None
cls
db
A PostgresSQL DB connection instance.
A PostgresSQL DB connection instance .