Ejemplo n.º 1
0
 def display_account_summary(self):
     html_txt = self.login()
     parse_data = self.parse_response(html_txt)
     table_data = [(key, chalk.blue(value)) for key, value in parse_data]
     table_instance = AsciiTable(table_data)
     table_instance.inner_heading_row_border = False
     table_instance.inner_row_border = True
     print(chalk.blue("\nAccount Summary".upper()))
     print(table_instance.table)
Ejemplo n.º 2
0
def handle_payee(update, context):
    username = update.message.chat.username
    payee = update.message.text
    if payee == 'Back':
        payee = context.user_data['payee']
    try:
        response = UserHandler.find_user(payee)
        if payee == username:
            update.message.reply_text(
                'You cannot make transactions to yourself!')
            return handle_exit_to_main(update, context)

        elif response:
            update.message.reply_text(
                f'Payee\'s telegram username is {payee}. Please specify amount to pay in cents. For $1, input: 100',
                reply_markup=ReplyKeyboardMarkup(build_navigation_keyboard(),
                                                 one_time_keyboard=True))
            context.user_data['payee'] = payee
            return TRANSACTION_AMOUNT
        else:
            update.message.reply_text(
                f'Payee: {payee}. does not exist'.format(payee))
            return handle_exit_to_main(update, context)

    except Exception as e:
        print(chalk.blue("handle_payee"))
        print(e)
        update.message.reply_text("An error occur in handle_payee")
Ejemplo n.º 3
0
def handle_confirmation(update, context):
    action_by = update.message.chat.username
    action_type = context.user_data['fund_action']
    fund_manager = context.user_data['fund_manager']
    amount = context.user_data['amount']
    try:
        print(
            'fund transaction successful',
            chalk.blue(
                create_fund_transaction(fund_manager,
                                        amount,
                                        action_type,
                                        datetimeCreated=datetime.now(),
                                        action_by=action_by)))
    except Exception as e:
        print(
            chalk.red(
                "Error in fund handle_confirmation, cannot create fund_transaction"
            ))
        del context.user_data['fund_manager']
        del context.user_data['amount']
        del context.user_data['fund_action']
        return handle_fund_menu(update, context)
    try:
        if action_type == 'withdraw':
            TransactionHandler.createTransaction(fund_manager, 'fund', amount,
                                                 'fund withdrawal',
                                                 datetime.now())

        if action_type == 'deposit':
            TransactionHandler.createTransaction('fund', fund_manager,
                                                 amount, 'fund deposit',
                                                 datetime.now())
    except Exception as e:
        # clear context
        del context.user_data['fund_manager']
        del context.user_data['amount']
        del context.user_data['fund_action']
        message = f'Transaction fail! Error in updating fundDB.'
        update.message.reply_text(message)
        print(
            Chalk.red(
                'Error in fund handle_confirmation, cannot update transaction DB'
            ))
        return handle_fund_menu(update, context)

    try:
        balance = check_fund_balance()
        message = f'Transaction Successful! Current fund balance/amount in circulation: {balance}'
        # Respond success
        update.message.reply_text(message)
        return handle_exit_to_main(update, context)
    except Exception as e:
        message = f'Transaction fail! Error in reading balance.'
        update.message.reply_text(message)
        del context.user_data['fund_manager']
        del context.user_data['amount']
        del context.user_data['fund_action']
        print("Cannot read balance balance")
Ejemplo n.º 4
0
    def report(self, msg: str,
               options: MessageOptions = MessageOptions()) -> None:
        if not self.flags.silent:
            if options.title:
                msg = "\n" + chalk.green(msg)
            elif options.subtitle:
                msg = "\n" + chalk.blue(msg)
            elif options.block:
                msg = "\n" + msg
            elif self.flags.dry_run and options.action:
                msg = indent_lines(msg, "  (Dry run) ")
            else:
                msg = indent_lines(msg, "  ")

            if self.flags.verbosity < 2:
                msg = truncate_lines(msg, 100)

            print(msg)
Ejemplo n.º 5
0
def scrab_hn():
    titleMod = []
    for i, title in enumerate(titles):
        titleMod.append({
            'title':
            chalk.blue(title.get_text()),
            'score_sort':
            int(scores[i - 1].get_text().replace(' points', '')),
            'score':
            chalk.green('- ' + scores[i - 1].get_text()),
            'link':
            f"\n{chalk.yellowBright(title.get('href'))}"
        })

    # Loop through a sorted array by score value
    for i, title in enumerate(sorted(titleMod, key=lambda k: k['score_sort'])):
        print(f'\n{i + 1} -', title['title'], title['score'], title['link'],
              '\n\n')
    return ''
Ejemplo n.º 6
0
def standardDeviation():
    print(chalk.blue("<------------- Standard Deviation ------------->\n"))
    print(chalk.green("<------------- Giga IOPS ------------->\n"))
    for i in threadedIOPSResults:  # For all the thread numbers
        std = []
        for j in threadedIOPSResults[i]:
            try:
                std.append((j[0] / j[1]) / 1e9)
            except ZeroDivisionError:
                std.append(0)
        print(chalk.yellow(str(i) + " threads: " + str(np.std(std))))
    print(chalk.green("\n<------------- Giga IOPS ------------->\n"))
    for i in threadedFLOPSResults:  # For all the thread numbers
        std = []
        for j in threadedFLOPSResults[i]:
            try:
                std.append((j[0] / j[1]) / 1e9)
            except ZeroDivisionError:
                std.append(0)
        print(chalk.yellow(str(i) + " threads: " + str(np.std(std))))
Ejemplo n.º 7
0
                    "MainContentPlaceHolder_SearchResultsList_SearchResultControlLeft_0_TaxonHTMLName_0"
                })
            # print(plant_link['href'])
            plant_seach_link = plant_link['href']
            print(chalk.green.bold('plant found common name'), common_name)

        botanical_name_req = {'basic': botanical_name}
        time.sleep(1)
        r = requests.get(
            'http://www.missouribotanicalgarden.org/PlantFinder/PlantFinderProfileResults.aspx',
            params=botanical_name_req)
        # print(chalk.yellow.bold('botanical name search url'),r.url)
        soup = BeautifulSoup(r.text, 'html.parser')
        span = soup.find(id="dnn_ctr4158_SearchResults_lblNoResults")
        if span:
            print(chalk.blue(span.text))
            if span.text == "We're sorry, but no results were found matching your criteria.  Please revise your search criteria.":
                print(chalk.red.bold('plant not found with botanical name'),
                      botanical_name)
                botainical_not_found = 1
        else:
            # parse the stuff here
            botanical_found = 1
            results = soup.find('table', {'class': 'results'})
            # print(results)
            plant_link = soup.find(
                "a", {
                    "id":
                    "MainContentPlaceHolder_SearchResultsList_SearchResultControlLeft_0_TaxonHTMLName_0"
                })
            # print(plant_link['href'])
Ejemplo n.º 8
0
def main():

    # # Specify tests for various numbers of threads
    # testThreads = [i for i in range(1,200)]
    testThreads = [1, 2, 4, 8]

    # Specify tests for various numbers of operations
    # KEEP THE RANGE (1,2) FOR SINGLE VALUE
    # testInputs = [int(i * 1e4) for i in range(1,10)]
    testInputs = [int(i * 1e4) for i in range(1, 100)]

    totalOps = sum(testInputs) * 4

    # Compile all FLOPS and IOPS functions into list and associated descriptions list
    testFunctions = [
        intOpsAdd, intOpsSub, intOpsMul, intOpsDiv, fpOpsAdd, fpOpsSub,
        fpOpsMul, fpOpsDiv
    ]
    testFunctionDescriptions = [
        "IOPS Add", "IOPS Subtract", "IOPS Multiply", "IOPS Divide",
        "FLOPS Add", "FLOPS Subtract", "FLOPS Multiply", "FLOPS Divide"
    ]

    # RUN ALL TESTS
    unthreadedResults, threadedResults = runAllTests(testInputs, testThreads,
                                                     testFunctions)

    iopsUnthreadedAverage = 0
    flopsUnthreadedAverage = 0
    iopsThreadedAverage = {}
    for i in testThreads:
        iopsThreadedAverage[i] = 0
    flopsThreadedAverage = {}
    for i in testThreads:
        flopsThreadedAverage[i] = 0

    # Print unthreaded results to console
    print(chalk.blue.bold("Unthreaded Results:"))
    print(chalk.blue.bold("-------------------------------"))
    for i in range(len(testFunctions)):
        print(chalk.yellow.bold(testFunctionDescriptions[i] + " : "))
        for j in range(len(unthreadedResults[i])):
            if i < 4:
                iopsUnthreadedAverage += (testInputs[j] /
                                          unthreadedResults[i][j])
            else:
                flopsUnthreadedAverage += (testInputs[j] /
                                           unthreadedResults[i][j])
            print(
                chalk.yellow(
                    str(testInputs[j]) + " operations took " +
                    str(unthreadedResults[i][j]) + " seconds"))

        print(chalk.blue("-------------------------------"))

    print("\n\n")

    # Print threaded results to the console
    print(chalk.blue.bold("Threaded Results:"))
    print(chalk.blue.bold("-------------------------------"))
    for i in testThreads:
        print(chalk.green.bold(str(i) + " threads: "))
        for j in range(len(testFunctions)):
            print(chalk.yellow.bold(testFunctionDescriptions[j]) + " : ")
            for k in range(len(testInputs)):
                if j < 4:

                    iopsThreadedAverage[i] += sum(
                        threadedResults[i][j][testInputs[k]])
                else:
                    flopsThreadedAverage[i] += (sum(
                        threadedResults[i][j][testInputs[k]]))
                print(
                    chalk.yellow(
                        str(testInputs[k]) + " operations took " +
                        str(sum(threadedResults[i][j][testInputs[k]])) +
                        " seconds"))
            print()
        print(chalk.blue("-------------------------------"))

    for i in iopsThreadedAverage:
        iopsThreadedAverage[i] = totalOps / iopsThreadedAverage[i]
        flopsThreadedAverage[i] = totalOps / flopsThreadedAverage[i]

    print("\n\n")

    # Print summary of results
    print(chalk.blue.bold("Summary of Results:"))
    print(chalk.blue.bold("-------------------------------"))
    print(chalk.yellow.bold("Unthreaded IOPS: ") + str(iopsUnthreadedAverage))
    print(
        chalk.yellow.bold("Unthreaded FLOPS: ") + str(flopsUnthreadedAverage))
    print(
        chalk.yellow.bold("Unthreaded Giga IOPS: ") +
        str(iopsUnthreadedAverage / 1e9))
    print(
        chalk.yellow.bold("Unthreaded Giga FLOPS: ") +
        str(flopsUnthreadedAverage / 1e9))
    print(chalk.blue("-------------------------------"))

    print(chalk.yellow.bold("Threaded IOPS: "))
    for i in testThreads:
        print(chalk.green(str(i) + " threads: ") + str(iopsThreadedAverage[i]))

    print(chalk.yellow.bold("Threaded FLOPS: "))
    for i in testThreads:
        print(
            chalk.green(str(i) + " threads: ") + str(flopsThreadedAverage[i]))

    print(chalk.yellow.bold("Threaded Giga IOPS: "))
    for i in testThreads:
        print(
            chalk.green(str(i) + " threads: ") +
            str(iopsThreadedAverage[i] / 1e9))

    print(chalk.yellow.bold("Threaded Giga FLOPS: "))
    for i in testThreads:
        print(
            chalk.green(str(i) + " threads: ") +
            str(flopsThreadedAverage[i] / 1e9))

    print(chalk.blue("-------------------------------"))

    # Convert results to JSON for formatting
    f = open("threadedResults.py", "w")

    f.write("threadedResults = ")
    f.write(json.dumps(threadedResults, indent=4))

    f.write("\niops = ")
    f.write(json.dumps(iopsThreadedAverage, indent=4))

    f.write("\nflops = ")
    f.write(json.dumps(flopsThreadedAverage, indent=4))
    f.close()