Exemple #1
0
def get_pins_channel(guild_id: int, cur: MySQLCursor = None):
    cur.execute(
        '''
        SELECT pins_channel FROM config
        WHERE guild_id = %s
    ''', (guild_id, ))
    result = cur.fetchone()
    return result[0] if result else None
def ReadBusinessUnit(db_cursor: MySQLCursor, business_code: int):
    db_cursor.execute(
        "SELECT title, business_code, summary  FROM business_units WHERE business_code="
        + str(business_code))
    myresult = db_cursor.fetchone()
    my_bu = BusinessUnit(title=myresult[0],
                         specific_code=myresult[1],
                         summary=myresult[2])
    return my_bu
Exemple #3
0
def ReadDocumentType(db_cursor: MySQLCursor, document_code: int):
    db_cursor.execute(
        "SELECT document_code, title, summary  FROM document_types WHERE document_code="
        + str(document_code))
    myresult = db_cursor.fetchone()

    my_document = DocumentType(document_code=myresult[0],
                               title=myresult[1],
                               summary=myresult[2])
    return my_document
Exemple #4
0
def ReadRecord(db_cursor: MySQLCursor, serial_number:int):
    db_cursor.execute("SELECT business_code, document_code, full_serial_number, status, title, custodian, revision, link, sow_no, issue_date, effective_date, \
                      reaffirmation_date, protection_lvl, ec_technical_data, permit, ecl, eccn, usml, cg, us_exemption, ca_exemption, exp_date, summary  FROM \
                      records WHERE full_serial_number=" + str(serial_number))
    myresult = db_cursor.fetchone()
    
    my_record = Record(business_code = myresult[0], document_code = myresult[1], full_serial_number = myresult[2], status = myresult[3], title = myresult[4], custodian = myresult[5], \
                       revision = myresult[6], link = myresult[7], sow_no = myresult[8], issue_date = myresult[9], effective_date = myresult[10], reaffirmation_date = myresult[11], \
                       protection_lvl = myresult[12], ec_technical_data = myresult[13], permit = myresult[14], ecl = myresult[15], eccn = myresult[16], usml = myresult[17], \
                       cg = myresult[18], us_exemption = myresult[19], ca_exemption = myresult[20], exp_date = myresult[21], summary = myresult[22])
    return my_record
Exemple #5
0
def get_channel_download_blacklist(guild_id: int,
                                   cur: MySQLCursor = None
                                   ) -> Optional[List[int]]:
    cur.execute(
        '''
        SELECT channel_download_blacklist FROM config
        WHERE guild_id = %s
    ''', (guild_id, ))
    result = cur.fetchone()
    if result:
        return _split_channel_download_blacklist(result[0])
    return []
Exemple #6
0
def ReadRecord(db_cursor: MySQLCursor, serial_number: int):
    db_cursor.execute(
        "SELECT full_serial_number, title, business_code, document_code, summary  FROM records WHERE full_serial_number="
        + str(serial_number))
    myresult = db_cursor.fetchone()

    my_record = Record(full_serial_number=myresult[0],
                       title=myresult[1],
                       business_code=myresult[2],
                       document_code=myresult[3],
                       summary=myresult[4])
    return my_record
Exemple #7
0
def _get_most_recent_update(guild_id: int, channel_id: int,
                            cur: MySQLCursor) -> Optional[dt.datetime]:
    typecheck(guild_id, int, 'guild_id')

    cur.execute(f'''
        SELECT MAX(timestamp) FROM g{guild_id}_messages as msgs
        INNER JOIN channels ON (channels.key_id = msgs.channel)
        WHERE channels.id = %s
        GROUP BY channel;
    ''', (channel_id,))
    timestamp = cur.fetchone()

    return timestamp[0] if timestamp else None
Exemple #8
0
def get_pin_msg_id(guild_id: int,
                   original_msg_id: int,
                   cur: MySQLCursor = None) -> Optional[int]:
    """
    Get the id of the associated pin message Hawkbot sent in a guild's
    designated pins channel

    :param guild_id: guild id
    :param original_msg_id: the id of the original message that was pinned
    :return: the id of the pin message Hawkbot sent linking to the original, or
        None if the original message was not found
    """
    typecheck(guild_id, int, 'guild_id')
    cur.execute(
        f'''
        SELECT pin FROM g{guild_id}_pins WHERE original = %s
    ''', (original_msg_id, ))
    pin_msg_id = cur.fetchone()
    return pin_msg_id[0] if pin_msg_id else None
Exemple #9
0
    def get_account(cursor: MySQLCursor, account_name: str):
        account_table_name = AccountTable.ACCOUNT_LIST.value

        try:
            get_account_query = 'SELECT name, salt, verifier FROM ' + account_table_name + ' WHERE name = %s'
            get_account_data = (account_name.upper(),)
            cursor.execute(get_account_query, get_account_data)
            values = cursor.fetchone()

            if values is None:
                result = None
            else:
                # need for save data by field name
                field_name = [field[0] for field in cursor.description]
                result = dict(zip(field_name, values))

        except ProgrammingError as e:
            Logger.error('[Account Manager]: (get_account) programming error {}'.format(e))

        else:
            if result is not None:
                return Account(name=result['name'], salt=result['salt'], verifier=result['verifier'])
Exemple #10
0
def user_name_from_id(id_: int, cur: MySQLCursor):
    cur.execute(
        'SELECT name FROM users WHERE id=%s', (id_,)
    )
    result = cur.fetchone()
    return result[0] if result else None
Exemple #11
0
def is_archived(cursor: MySQLCursor, conc_id):
    cursor.execute(
        'SELECT id FROM kontext_conc_persistence WHERE id = %s LIMIT 1',
        (conc_id,)
    )
    return cursor.fetchone() is not None