Esempio n. 1
0
 def productDetails(self, email):
     self.a = email
     from db import DbConnection
     dbConn = DbConnection()
     lists = dbConn.getProductDetails(email=self.a)
     dictDetails = dict(lists)
     return dictDetails
Esempio n. 2
0
class SearchResultsVolume():
    def __init__(self, queries_tag, results_tag):
        self.queries_tag = queries_tag
        self.results_tag = results_tag
        self.db = DbConnection()

    def create_schema(self, clobber=False):
        if clobber:
            try:
                self.db.execute('DROP TABLE %s' % self.volume_name)
                self.db.execute('DROP TABLE %s' % self.volume_items_name)
            except:
                pass

        self.db.execute(
            "CREATE TABLE %s (id int, count int default 0, processed int default 0)"
            % self.volume_name)
        self.db.execute(
            "CREATE TABLE %s (id serial, result_id int, order_id int, item_id int, result text, UNIQUE (result_id, item_id))"
            % self.volume_items_name)
        self.db.execute(
            "INSERT INTO %s SELECT id, 0 as count, 0 as processed from %s" %
            (self.volume_name, self.queries_volume_name))

    @property
    def volume_name(self):
        return 'search_results_volume_%s' % self.results_tag

    @property
    def volume_items_name(self):
        return 'search_results_items_volume_%s' % self.results_tag

    @property
    def queries_volume_name(self):
        return 'search_queries_volume_%s' % self.queries_tag
Esempio n. 3
0
    def clicker(self):
        from userLogin import loginUser
        import hashlib
        from db import DbConnection
        dbConn = DbConnection()
        login = loginUser()
        tempEmail = self.email.get()
        tempPassword = self.password.get()
        # tempEmail = "*****@*****.**"
        # tempPassword = "******"
        lists = dbConn.userLogin(email=tempEmail)
        dictDetails = dict(lists)
        userEmail = ""
        userPassword = ""
        for key in dictDetails:
            userEmail = key
            userPassword = dictDetails.get(key)

        if (userEmail == 'admin' and userPassword == tempPassword):
            self.adminPage()
        elif (userEmail == tempEmail and userPassword == (hashlib.md5(
                tempPassword.encode()).hexdigest())):
            # self.userDashboard()
            self.Groceries()
        else:
            print("SO")
Esempio n. 4
0
 def __init__(self, queries_tag, results_a_tag, results_b_tag,
              search_items_csv_path, filename, sample, sample_size, diff):
     self.results_a_tag = results_a_tag
     self.results_b_tag = results_b_tag
     self.queries_tag = queries_tag
     self.search_items_csv_path = search_items_csv_path
     self.volumes = [self.results_a_tag, self.results_b_tag]
     self.db = DbConnection()
     self.load_search_items(self.search_items_csv_path)
     self.sample = self.get_sample_value(sample)
     self.sample_size = sample_size if sample_size else '300'
     self.all_results = not diff
Esempio n. 5
0
 def getInventory(self):
     self.inventoryPage = Toplevel()
     self.inventoryPage.geometry("800x800")
     self.label = Label(self.inventoryPage, text="ProductId")
     self.label.grid(row=0, column=0, padx=10)
     self.label1 = Label(self.inventoryPage, text="ProductName")
     self.label1.grid(row=0, column=1, padx=10)
     self.label2 = Label(self.inventoryPage, text="ProductQty")
     self.label2.grid(row=0, column=2, padx=10)
     self.update = Button(self.inventoryPage,
                          text="Update Inventory",
                          cursor="hand2",
                          command=self.updateInventory)
     self.update.grid(row=0, column=3, padx=10, ipadx=20, ipady=5)
     from db import DbConnection
     dbConn = DbConnection()
     from addtocart import getDetails
     productDet = getDetails()
     self.productDetail = productDet.getInventory()
     a = 0
     b = 1
     for i in self.productDetail:
         for j in i:
             self.fname = Label(self.inventoryPage, text=j)
             self.fname.grid(row=b, column=a, sticky=W, padx=10, pady=20)
             # for j in range(0, len(self.productDetail)):
             #     self.fname = Label(self.OrderListPage, text=i)
             #     self.fname.grid(row=b, column=a, sticky=W, padx=10)
             a += 1
         a = 0
         b += 1
Esempio n. 6
0
 def getOrderList(self):
     self.OrderListPage = Toplevel()
     self.OrderListPage.geometry("800x800")
     from db import DbConnection
     dbConn = DbConnection()
     from addtocart import getDetails
     productDet = getDetails()
     self.productDetail = productDet.getCartList()
     # for key in self.productDetails:
     self.label = Label(self.OrderListPage, text="UserEmail")
     self.label.grid(row=0, column=0, padx=10, sticky=W)
     self.label1 = Label(self.OrderListPage, text="ProductName")
     self.label1.grid(
         row=0,
         column=1,
     )
     self.label2 = Label(self.OrderListPage, text="ProductQty")
     self.label2.grid(row=0, column=2, padx=10, sticky=W)
     a = 0
     b = 1
     for i in self.productDetail:
         for j in i:
             self.fname = Label(self.OrderListPage, text=j)
             self.fname.grid(row=b, column=a, sticky=W, padx=10, pady=20)
             # for j in range(0, len(self.productDetail)):
             #     self.fname = Label(self.OrderListPage, text=i)
             #     self.fname.grid(row=b, column=a, sticky=W, padx=10)
             a += 1
         a = 0
         b += 1
def _save_db(address,
             contract_name,
             duration,
             result,
             found=True,
             failed=False):
    with DbConnection() as db:
        db.add_run(address, contract_name, duration,
                   filter_mythril_result(result) if found else '', found,
                   failed)
Esempio n. 8
0
class loginUser:
    from db import DbConnection
    dbConn = DbConnection()
    import hashlib
    tempEmail = ""
    tempPassword = ""
    lists = dbConn.userLogin(email=tempEmail)
    dictDetails = dict(lists)
    userEmail = ""
    userPassword = ""
    for key in dictDetails:
        userEmail = key
        userPassword = dictDetails.get(key)
Esempio n. 9
0
def run_controller(search_queries_tag, search_results_tag, sample, size):
    db = DbConnection()

    data = db.execute(
        "select id as ids from search_queries_volume_%s order by %s limit %s" %
        (search_queries_tag, get_sample_value(sample), size))
    ids = [str(item[0]) for item in data.fetchall()] if data else None
    batches = create_batches(ids)

    while len(batches) > 0:
        procs = []

        for allowed in range(1, 8):
            if len(batches) > 0:
                batch = batches.pop()
                p = subprocess.Popen([
                    "python", "worker.py", "--results_tag", search_results_tag,
                    "--queries_tag", search_queries_tag, "--ids"
                ] + batch)
                procs.append(p)

        for p in procs:
            p.wait()
Esempio n. 10
0
 def getTopData(self):
     namefirst = self.fnameEntry.get()
     nameLast = self.lnameEntry.get()
     addEmail = self.emailAddEntry.get()
     noPhone = self.phoneNoEntry.get()
     from userLogin import Userregister
     userLog = Userregister()
     a = userLog.generatePassword()
     from db import DbConnection
     db = DbConnection()
     db.registerUser(namefirst, nameLast, addEmail, noPhone, a)
     userLog.mailAddress = addEmail
     userLog.sendUserDetails()
     alertLabel = Label(
         self.top, text="Register SuccessFull Check Your Email To Login")
     alertLabel.grid(row=7, column=1, pady=10)
     backButton = Button(self.top,
                         text="Login",
                         command=self.quit,
                         cursor="hand2",
                         width=15,
                         height=1)
     backButton.grid(row=8, column=1)
def get_new_contracts(blocks):
    with DbConnection() as db:
        for index, block_no in blocks.items():
            eth = Etherscan(os.getenv('KEY'))
            logger.info(
                "Searching for contracts starting with block %s, index %s",
                block_no, index)
            prev_call = time.time()

            while db.get_amount(index) < int(
                    os.getenv('CONTRACTS_PER_TIMESTAMP')):
                time.sleep(time.time() -
                           (prev_call - 0.2))  # Max 5 api calls per second
                contracts, block_no = get_contracts_from_block_range(
                    eth, block_no)
                prev_call = time.time()
                logger.debug(
                    "For block_nos %s-%s (timestamp index %s), found %s contracts.",
                    block_no, block_no + 100, index, len(contracts))

                db.add_contracts(contracts, block_no, index)
Esempio n. 12
0
 def getRecords(self):
     self.detailPage = Toplevel()
     self.detailPage.geometry("600x500")
     from db import DbConnection
     dbConn = DbConnection()
     from addtocart import getDetails
     productDet = getDetails()
     self.productDetail = productDet.getDetail()
     # for key in self.productDetails:
     a = 0
     b = 1
     self.label = Label(self.detailPage, text="Fname")
     self.label.grid(row=0, column=0, padx=10)
     self.label1 = Label(self.detailPage, text="Lname")
     self.label1.grid(row=0, column=1, padx=10)
     self.label2 = Label(self.detailPage, text="email")
     self.label2.grid(row=0, column=2, padx=10, sticky=W)
     for i in self.productDetail:
         for j in range(0, len(self.productDetail) + 1):
             self.fname = Label(self.detailPage, text=i[j])
             self.fname.grid(row=b, column=a, sticky=W, padx=10)
             a += 1
         b += 1
         a = 0
Esempio n. 13
0
class SearchQueryVolume():
    def __init__(self, tag):
        self.tag = tag
        self.db = DbConnection()

    def create_schema(self, tag, clobber=False):
        if clobber:
            try:
                self.db.execute('DROP TABLE %s' % self.volume_name)
            except:
                pass
        self.db.execute("CREATE TABLE %s (id int, count int default 0, query varchar(255), q varchar(255))" % self.volume_name)

    def do_import(self, file, clobber):

        self.create_schema(self.tag, clobber)

        with open(file, 'rb') as csvfile:
            reader = csv.DictReader(csvfile)
            reader.next()
            id = 1
            for row in reader:
                self.db.execute(
                    "INSERT INTO %s (id, count, query, q) VALUES (:id, :count, :query, :q)" % self.volume_name,
                    {
                        'id': id,
                        'count': row['count'],
                        'query': row['query'],
                        'q': row['q']
                    }
                )
                id += 1

    @property
    def volume_name(self):
        return 'search_queries_volume_%s' % (self.tag,)
Esempio n. 14
0
 def getDetail(self):
     from db import DbConnection
     dbConn = DbConnection()
     lis = dbConn.getCustDetails()
     dictDetail = list(lis)
     return dictDetail
Esempio n. 15
0
from db import DbConnection
dbConn = DbConnection()


class addtoCart:
    def __init__(self, email, productname, productQty):
        self.productName = productname
        self.productQuantity = productQty
        self.emails = email
        dbConn.addToCart(self.emails, self.productName, self.productQuantity)


class getProduct:
    def productDetails(self, email):
        self.a = email
        from db import DbConnection
        dbConn = DbConnection()
        lists = dbConn.getProductDetails(email=self.a)
        dictDetails = dict(lists)
        return dictDetails


class getDetails:
    def getDetail(self):
        from db import DbConnection
        dbConn = DbConnection()
        lis = dbConn.getCustDetails()
        dictDetail = list(lis)
        return dictDetail

    def getCartList(self):
Esempio n. 16
0
 def updateBeans(self):
     self.riceQty = self.beansEntry.get()
     self.productId = "2"
     from db import DbConnection
     dbConn = DbConnection()
     dbConn.updateInventory(self.riceQty, self.productId)
Esempio n. 17
0
class SearchResultsReport():
    def __init__(self, queries_tag, results_a_tag, results_b_tag,
                 search_items_csv_path, filename, sample, sample_size, diff):
        self.results_a_tag = results_a_tag
        self.results_b_tag = results_b_tag
        self.queries_tag = queries_tag
        self.search_items_csv_path = search_items_csv_path
        self.volumes = [self.results_a_tag, self.results_b_tag]
        self.db = DbConnection()
        self.load_search_items(self.search_items_csv_path)
        self.sample = self.get_sample_value(sample)
        self.sample_size = sample_size if sample_size else '300'
        self.all_results = not diff

    def get_sample_value(self, sample_key):
        sample_types = {'top': 'count DESC', 'bottom': 'count ASC'}
        return sample_types.get(sample_key, 'count DESC')

    def load_search_items(self, search_items_csv_path):
        self.search_items = {}
        with open(search_items_csv_path) as p_fp:
            preader = csv.DictReader(p_fp, delimiter="\t")
            for row in preader:
                self.search_items[int(row['id'])] = row

    def create(self, filename):
        workbook = xlsxwriter.Workbook(filename)
        ws_search = workbook.add_worksheet('Search Results')

        ws_row = 0
        ws_search.write(0, 0, 'Term')
        ws_search.write(ws_row, 1, self.volumes[0])
        ws_search.write(ws_row, 2, self.volumes[1])

        ws_row += 2

        search_ids, all_results = self._get_search_results(
            self.queries_tag, self.volumes, self.sample, self.sample_size)
        base_results = all_results[0]
        comparison_results = all_results[1]

        for sid in search_ids:
            base_set = (filter(lambda b: b.search_id == sid, base_results))
            comparison_set = (filter(lambda c: c.search_id == sid,
                                     comparison_results))

            if all_results or base_set != comparison_set:
                if base_set:
                    ws_search.write(
                        ws_row, 0,
                        str(base_set[0].query) + ' (' +
                        str(base_set[0].count) + ')')
                base_count = len(base_set)
                comp_count = len(comparison_set)
                max_count = base_count if base_count >= comp_count else comp_count

                for i in range(0, max_count):
                    if base_count > 0:
                        base = base_set.pop(0)
                        base_item = self.search_items[
                            base.item_id] if self.search_items[
                                base.item_id] else ''
                        ws_search.write(
                            ws_row, 1,
                            '(' + str(base.order) + ') ' + base_item['name'] +
                            ' (' + base_item['description'] + ')' + ' (' +
                            str(base.item_id) + ')')
                        base_count = base_count - 1

                    if comp_count > 0:
                        comp = comparison_set.pop(0)
                        comp_item = self.search_items[
                            comp.item_id] if self.search_items[
                                comp.item_id] else ''
                        ws_search.write(
                            ws_row, 2,
                            '(' + str(comp.order) + ') ' + comp_item['name'] +
                            ' (' + comp_item['description'] + ')' + ' (' +
                            str(comp.item_id) + ')')
                        comp_count = comp_count - 1

                    ws_row += 1
                    max_count = 0
        workbook.close()

    def _get_search_results(self, queries_tag, volumes, sample, size):
        results = []
        searches = []
        for v, volume in enumerate(self.volumes):
            result_list = []
            SearchResult = namedtuple(
                'Result', ['search_id', 'query', 'count', 'item_id', 'order'])

            rows = self.db.execute(
                "select s.id as search_id, query, s.count, ri.item_id as item_id, ri.order_id \
            from search_queries_volume_{0} as s join search_results_volume_{1} as r on s.id = r.id \
            left join search_results_items_volume_{1} as ri on r.id = ri.result_id \
            where processed = 1 and s.id in (select ss.id from search_queries_volume_{0} ss order by {2} limit {3})\
            order by s.id desc, order_id;".format(queries_tag, volume, sample,
                                                  size)).fetchall()

            for row in map(SearchResult._make, rows):
                if row.search_id not in searches:
                    searches.append(row.search_id)
                result_list.append(row)
            results.append(result_list)
        return searches, results

    def _get_max_col_length(self, volumes, result_id, diff=False):
        max_size = 0

        for v, volume in enumerate(volumes):
            total = self.db.execute(
                "select count from search_results_volume_%s where id = %d" %
                (volume, result_id)).first()['count']

            if total > max_size:
                max_size = total

        return max_size
Esempio n. 18
0
 def updateCoffee(self):
     self.riceQty = self.coffeeEntry.get()
     self.productId = "3"
     from db import DbConnection
     dbConn = DbConnection()
     dbConn.updateInventory(self.riceQty, self.productId)
Esempio n. 19
0
 def __init__(self, queries_tag, results_tag):
     self.queries_tag = queries_tag
     self.results_tag = results_tag
     self.db = DbConnection()
Esempio n. 20
0
 def updateTea(self):
     self.riceQty = self.teaEntry.get()
     self.productId = "4"
     from db import DbConnection
     dbConn = DbConnection()
     dbConn.updateInventory(self.riceQty, self.productId)
Esempio n. 21
0
def run_worker(queries_tag, results_tag, ids):
    engine = os.getenv('EST_ENGINE')
    url = os.getenv('EST_ENGINE_PARAMS')
    module = importlib.import_module('engines.' + engine)
    api = getattr(module, 'SearchApi')(url)
    db = DbConnection()

    for id in ids:
        row = db.execute(
            "select q from search_queries_volume_%s where id = %d" %
            (queries_tag, id)).first()
        results = api.search(row['q'])
        if type(results) != list:
            results = api.search(row['q'])
            if type(results) != list:
                continue

        db.execute(
            "delete from search_results_items_volume_%s where result_id = %d" %
            (results_tag, id))
        db.execute(
            "update search_results_volume_%s set processed = 0 where id = %d" %
            (results_tag, id))

        order = 1
        for result in results:
            db.execute(
                "insert into search_results_items_volume_%s (result_id, order_id, item_id) values (%d, %d, %d)"
                % (results_tag, id, order, result))
            order += 1
        db.execute(
            "update search_results_volume_%s set processed = 1, count = %d where id = %d"
            % (results_tag, len(results), id))
Esempio n. 22
0
from gameserver import GameServer
from db import DbConnection


if __name__ == "__main__":
    DbConnection()
    GameServer().run()
Esempio n. 23
0
from db import DbConnection

db = DbConnection('bd_paq.txt')
db.mountA1()
db.mountA2()
db.mountA3()
db.mountA4()
db.mountA5()
db.mountA6()
db.mountA7()
db.mountA8()
def analyze_contracts():
    with DbConnection() as db:
        contracts = db.get_non_analyzed_contracts()

    logger.info('Using contracts: %s', contracts)
    analyze(contracts)
Esempio n. 25
0
 def getCartList(self):
     from db import DbConnection
     dbConn = DbConnection()
     proList = dbConn.getOrderList()
     dictDetails = list(proList)
     return dictDetails
Esempio n. 26
0
 def getInventory(self):
     from db import DbConnection
     dbConn = DbConnection()
     inventory = dbConn.getInventory()
     dictDetails = list(inventory)
     return dictDetails
Esempio n. 27
0
 def __init__(self, tag):
     self.tag = tag
     self.db = DbConnection()