コード例 #1
0
class Service:
    """Class to implement Service/Business feature"""
    def __init__(self):
        self.db = Connection()
        self.service_name = ''

    def register_service(self,
                         service_name,
                         service_type,
                         phone,
                         email,
                         balance=0.0):
        # Registers the service into the database
        self.service_name = service_name
        # Query to insert service into database
        qry = "INSERT INTO service_account VALUES (%s, %s, %s, %s, %s);"
        values = (self.service_name, service_type, phone, email, balance)
        self.db.iud(qry, values)
        return True

    def get_service_name(self):
        # Gathers the list of all services registered in the database
        qry = "SELECT servicename from service_account;"
        servicename = self.db.show(qry)
        return servicename
コード例 #2
0
class Login:
    """Class to implement Login feature."""
    def __init__(self):
        self.db = Connection()
        self.username = ''
        self.password = ''

    def login_user(self, username,
                   password):  # Logs the user into the application
        self.username = username
        qry = 'SELECT password FROM normal_user WHERE username = %s;'
        values = (self.username, )
        passwd = self.db.show_with_args(qry, values)
        if not passwd:  # Checks if username exists
            messagebox.showerror('Login', 'Username does not exist.')
            return False
        else:
            if password == passwd[0][0]:  # Checks if the password matches
                self.password = password
                return True
            else:
                messagebox.showerror('Login', 'Please enter correct password')
                return False

    def delete_user(self, username, password):  # Method to delete user
        self.username = username
        qry = 'SELECT password FROM normal_user WHERE username = %s;'
        values = (self.username, )
        passwd = self.db.show_with_args(qry, values)
        if not passwd:  # Checks if username exists
            messagebox.showerror('Delete User', 'Username does not exist.')
        else:
            if password == passwd[0][0]:  # Checks if the password matches
                # Gets the account_id for the given username
                qry1 = 'SELECT account_id FROM normal_account WHERE username = %s;'
                values1 = (self.username, )
                account_id = self.db.show_with_args(qry1, values1)
                # Retrieves the transaction history.
                qry_optional = 'SELECT account_id FROM transaction WHERE account_id = %s;'
                values_optional = (account_id[0][0], )
                optional_out = self.db.show_with_args(qry_optional,
                                                      values_optional)
                if optional_out:
                    # If the user has any transaction history, query deletes it.
                    qry2 = 'DELETE FROM transaction WHERE account_id = %s;'
                    values2 = (account_id[0][0], )
                    self.db.iud(qry2, values2)
                # Deletes the account.
                qry3 = 'DELETE FROM normal_account WHERE username = %s;'
                values3 = (self.username, )
                self.db.iud(qry3, values3)
                # Deletes the user information from the database
                qry4 = 'DELETE FROM normal_user WHERE username = %s;'
                values4 = (self.username, )
                if self.db.iud(qry4, values4):
                    return True
            else:
                messagebox.showerror('Delete User',
                                     'Please enter correct password')
                return False
コード例 #3
0
class Signup:
	"""Class to implement Signup feature."""
	def __init__(self):
		self.db = Connection()
		self.username = ''

	def signup_user(self, username, fullname, password, phone, email, balance=0.0):  # Registers the User in database
		self.username = username
		# Query to insert user information
		qry1 = "INSERT INTO normal_user VALUES (%s, %s, %s, %s, %s);"
		values1 = (self.username, fullname, password, phone, email)
		# Query to create e-wallet account
		qry2 = "INSERT INTO normal_account (username, balance) VALUES (%s, %s);"
		values2 = (self.username, balance)
		self.db.iud(qry1, values1)
		if self.db.iud(qry2, values2):
			return True
コード例 #4
0
    '''


if __name__ == '__main__':
    
    # Parse the command line arguments.
    parser = argparse.ArgumentParser(description="parse args")
    parser.add_argument('-data_dir', '--dir', default="./data/", type=str, help='The input data directory')
    args = parser.parse_args()

    # columns that should be read from the CSV file
    metadata = Metadata(input_file='glossary.pdf', output_file='columns.txt', data_dir=args.dir)
    columns = metadata.read_metadata()

    # connect to database
    con = Connection()
    engine = con.connect_to_database(return_as_string=False)
    table_name = os.getenv("tablename")

    @event.listens_for(engine, 'before_cursor_execute')
    def receive_before_cursor_execute(conn, cursor, statement, params, context, executemany):
        if executemany:
            cursor.fast_executemany = True

    # Get all the files that needs to be moved to DB
    csv_files = get_all_files(args.dir)

    # Process each file. -> This could be parallelized using multiprocessing module.
    for file in tqdm(csv_files):
        process_csv_file(args.dir+file, columns, engine, table_name, CHUNKSIZE)
    
コード例 #5
0
 def __init__(self):
     self.db = Connection()
     self.service_name = ''
コード例 #6
0
from helpers.pgwputils import get_installbase

defaults_file = os.path.join(get_installbase(),u"resources/configuration/pgwp.conf")
logfilename = u"/var/log/pgwp/pgwp.log"

logging.basicConfig(filename = logfilename, level=logging.WARN,
                    format=u'%(asctime)s[%(module)-5s:%(funcName)-5s] (%(processName)-5s) %(message)s',
                    )

if __name__ == u"__main__":

    valid_selection = False
    
    defaults = CommandDefaults(defaults_file)
    opts, args = options(defaults)
    monitorconnection = Connection(opts.monitorconnection)
    if not monitorconnection.valid:
            print(u"pgwp: Cannot process monitor connection info [{}] reason [{}]".format(opts.monitorconnection,monitorconnection.failurereason))
            sys.exit(1)
    else:
        if not monitorconnection.testQuery(u"SELECT query, calls, total_time FROM pg_stat_statements",limit=1):
            print(u"pgwp: Monitoring failure - No access to pg_stat_statements [{}]".format(opts.monitorconnection))
            monitorconnection.connection.close()
            sys.exit(1)
          
    dashboardconnection = Connection(opts.dashboardconnection)  
    if not dashboardconnection.valid:
            print(u"pgwp: Cannot process dashboard connection info [{}] reason [{}]".format(opts.dashboardconnection,dashboardconnection.failurereason))
            sys.exit(1)
    else:
        if not dashboardconnection.testQuery(u"SELECT * FROM pgwp.statements",limit=1):
コード例 #7
0
from modules.auth import is_authed, set_auth
from modules.local import create_repo
from classes.connection import Connection

# checks whether auth file with token is present
token = is_authed()

if not token:
    # saves the token to a file
    token = set_auth()

# create a github api connection
connection = Connection(token)

repo_name = input("Repo name: ")
repo_description = input("Repo description: ")

# create a github repo
if connection.create_repo(repo_name, repo_description):
    # create a local repo and add the github repos as remote
    create_repo(repo_name, connection.get_url())
コード例 #8
0
 def __init__(self):
     self.db = Connection()
コード例 #9
0
class Account:
    """Class to implement all the features available in the E-Wallet application."""
    def __init__(self):
        self.db = Connection()

    def get_balance(self, username):  # Returns the balance of the user account
        qry = 'SELECT balance FROM normal_account WHERE username = %s;'
        values = (username, )
        balance_db = self.db.show_with_args(qry, values)
        return balance_db[0][0]

    def add_transaction(self, username, detail,
                        amount):  # Adds the transaction details in in database
        # Retrieves the account id for the given username
        qry = 'SELECT account_id from normal_account WHERE username = %s'
        values = (username, )
        account_id = self.db.show_with_args(qry, values)
        # Inserts the transaction data in to the transaction table.
        qry2 = 'INSERT INTO transaction (account_id, detail, amount) VALUES (%s, %s, %s)'
        values2 = (account_id[0][0], detail, float(amount))
        self.db.iud(qry2, values2)
        return True

    def load_amount(self, username, bank, acc_no,
                    amount):  # Loads amount into the user account
        # Updates the balance to add loaded amount
        qry = 'UPDATE normal_account SET balance = balance + %s WHERE username = %s;'
        values = (amount, username)
        self.db.iud(qry, values)
        detail = f'Amount was loaded to wallet from {bank} Account No. {acc_no}.'
        self.add_transaction(
            username, detail,
            amount)  # adds the details of the transaction to the database
        return True

    def transfer_amount(self, username, receiver_username,
                        amount):  # Transfers amount to different user.
        # Updates the balance of sender to deduct the loaded amount
        qry = 'UPDATE normal_account SET balance = balance - %s WHERE username = %s;'
        values = (amount, username)
        self.db.iud(qry, values)
        detail = f'Transferred money to {receiver_username} through e-wallet.'
        self.add_transaction(
            username, detail, amount
        )  # adds the details of the transaction to the sender's database
        # Updates the balance of receiver to add received amount
        qry2 = 'UPDATE normal_account SET balance = balance + %s WHERE username = %s;'
        values2 = (amount, receiver_username)
        detail = f'Received money from {username} through e-wallet.'
        self.add_transaction(
            receiver_username, detail, amount
        )  # adds the details of the transaction to the receiver's database
        self.db.iud(qry2, values2)
        return True

    def pay_amount(self, username, servicename,
                   amount):  # Pays amount to business/service
        # Updates the balance to deduct paid amount
        qry = 'UPDATE normal_account SET balance = balance - %s WHERE username = %s;'
        values = (float(amount), username)
        self.db.iud(qry, values)
        detail = f'Paid money to {servicename} for their service through e-wallet.'
        self.add_transaction(username, detail, float(
            amount))  # adds the details of the transaction to the database
        # Updates the balance to add cashback amount
        qry2 = 'UPDATE normal_account SET balance = balance + %s WHERE username = %s;'
        values2 = (float(amount) * 2 / 100, username)
        detail = f'Received cashback from {servicename} through e-wallet.'
        self.add_transaction(username, detail,
                             float(amount) * 2 /
                             100)  # adds the details of the transaction
        self.db.iud(qry2, values2)
        return True

    def show_transaction(
            self, username):  # Shows the list of transactions done by the user
        # Query to retrieve the account_id for the username
        qry = 'SELECT account_id from normal_account WHERE username = %s'
        values = (username, )
        account_id = self.db.show_with_args(qry, values)
        # Query to retrieve the transaction history of the user
        qry2 = 'SELECT transaction_id, detail, amount FROM transaction WHERE account_id = %s;'
        values2 = (account_id[0][0], )
        data = self.db.show_with_args(qry2, values2)
        return data
コード例 #10
0
ファイル: index.py プロジェクト: maiconkkl/Sisdevin-G6
import re
from classes.pessoas import Pessoas
from classes.connection import Connection
from classes.generator import Generator
from classes.produto_servico import Produtos

db_con = Connection()
connection = db_con.get_connection()
pessoas = Pessoas(connection, 'DigisatServer')
emitente = pessoas.get_emitente()
generator = Generator()

responsavel_tecnico = ''
documento_tecnico = ''
tipo_empresa = ''
registro_mapa = ''

for x in emitente['CamposPersonalizado']:
    if x['TipoPersonalizado']['Descricao'].lower(
    ) == 'responsavel tecnico nome':
        responsavel_tecnico = x['Valor']

    if x['TipoPersonalizado']['Descricao'].lower(
    ) == 'responsavel tecnico documento':
        documento_tecnico = x['Valor']

    if x['TipoPersonalizado']['Descricao'].lower() == 'tipo empresa':
        tipo_empresa = x['Valor']

    if x['TipoPersonalizado']['Descricao'].lower() == 'registro mapa':
        registro_mapa = x['Valor']
コード例 #11
0
 def __init__(self):
     self.db = Connection()
     self.username = ''
     self.password = ''
コード例 #12
0
	def __init__(self):
		self.db = Connection()
		self.username = ''