def filter_csv():
    if request.method == 'POST':
        mycheckbox = request.form.get('mycheckbox')
        file = request.files['file']
        if not file:
            flash('No files chosen')
            return redirect(request.url)
        filename = secure_filename(file.filename)
        with open(filename, 'wb') as input_file:
            input_file.write(file.stream.read())
        stream = open(filename, 'rb')
        content = io.StringIO(stream.read().decode("UTF8"), newline=None)
        csv_input = csv.reader(content)
        Valid_List = [
            "Test case", "No", "Source IP", "Destination IP", "Protocol",
            "Message Info", "Message Contents", "Path Mgmt Check",
            "Transmit Timer", "Periodic Timer"
        ]
        Valid_List = [x.lower() for x in Valid_List]
        try:
            FColumn = next(csv_input)
        except StopIteration:
            flash('No data')
            stream.close()
            context = {'row': read_data()}
            return render_template('filter_csv.html',
                                   context=context,
                                   activate_download=False)
        FColumn = [x.lower() for x in FColumn]
        status = all(x in FColumn for x in Valid_List)
        content.close()
        stream.close()
        if (len(FColumn) != len(Valid_List)) or (True != status):
            flash('Choose Appropriate File Format', 'error')
            context = {'row': read_data()}
            return render_template('filter_csv.html',
                                   context=context,
                                   activate_download=False)
        else:
            content = {'row': read_specific_data(mycheckbox)}
            key = (content['row'][0][0])
            num = request.form.get('num')
            perform(key, num, filename)
            os.remove(filename)
            context = {'row': read_data()}
            return render_template('filter_csv.html',
                                   context=context,
                                   activate_download=True)
    context = {'row': read_data()}
    return render_template('filter_csv.html',
                           context=context,
                           activate_download=False)
Beispiel #2
0
def measure(bot, update):
    logger.info("Sending measurements")

    raw = database.read_data()
    data = humino.raw_to_hum(raw)
    status = humino.status_message(data)

    update.message.reply_text(status)
Beispiel #3
0
def index():

    if request.method == 'POST':
        data = get_data()
    else:
        data = db.read_data().values()

    return render_template('master_index.html',
                           data=data,
                           services=config.SERVICES)
    def test_read_data(self):
        """Tests if csv input files will be formatted correctly to list of dictionaries."""

        csv_file = 'data/customer_data.csv'
        new_data = database.read_data(csv_file)

        expected = [{'user_id': '37431', 'name': 'Bill Gates', 'address': '500 5th Ave, Seattle, WA',
                     'phone_number': '206-709-3100', 'email': '*****@*****.**'},
                    {'user_id': '18720', 'name': 'Steve Ballmer', 'address': '123 Bel Air Road Los Angeles, CA',
                     'phone_number': '425-882-8080', 'email': '*****@*****.**'},
                    {'user_id': '700459', 'name': 'Elliot Alderson', 'address': '135 East 57th Street, New York, NY',
                     'phone_number': '212-867-5309', 'email': '*****@*****.**'}
                    ]
        self.assertEqual(new_data, expected)
Beispiel #5
0
def notify_about_dry_plants(bot, job):
    logging.info('Running notifications job')
    raw = database.read_data(days=1)
    data = humino.raw_to_hum(raw)

    for plant_id in data.columns:
        if len(
                data[plant_id]
        ) < 2 or data[plant_id][-1] is None or data[plant_id][-2] is None:
            logging.warning('Not enough or missing data for {}'.format(
                config.PLANTS[plant_id][0]))
        else:
            dry_now = data[plant_id][-1] < config.PLANTS[plant_id][1]
            dry_before = data[plant_id][-2] < config.PLANTS[plant_id][1]

            if dry_now and not dry_before:
                text = "💧 {} is thirsty now ({}%).".format(
                    config.PLANTS[plant_id][0], int(data[plant_id][-1]))
                bot.send_message(chat_id=job.context, text=text)
                logging.info("{} is dry".format(config.PLANTS[plant_id][0]))
Beispiel #6
0
# from datetime import datetime
import database as db
import newgui as gui

# import payments as p
# from decimal import *  # decimal numbers
# getcontext().prec = 10  # setting the decimals to two numbers, as in payments

# paymentDay = 24  # do skasowania
# PAYDAY = 24
#
# today = datetime.now()
# payment = today.replace(day=paymentDay)

db.read_data()
# # print("gui tutaj", gui.PaymentsGUI.get_sw())
# # gui.Label(gui.get_status_window(), text="Całkowity przychód: £" + str(db.calculate_total("income")))
# print("Wydatki przez direct debits: £" + str(db.calculate_total("directDebit")))
# print("Wydatki przez standing orders: £" + str(db.calculate_total("standingOrder")))
# print("Płatności kartą: £" + str(db.calculate_total("cardPayment")))
#
# full_outcome = db.calculate_total("directDebit") + db.calculate_total("standingOrder") \
#                + db.calculate_total("cardPayment")
#
# print("Wydatki całkowite: £" + str(full_outcome))
# print("Przychód - wydatki: £" + str(db.calculate_total("income") - full_outcome))

# ------ Starting the GUI adn the main loop
root = gui.Tk()
myapp = gui.PaymentsGUI(root)
root.mainloop()
Beispiel #7
0
        threshold = config.PLANTS[int(plant)][1]
        current_value = data[plant][-1]
        status = "🍂" if progress <= 0 else "🍃" if progress <= 10 else "🌱"
        rv += "{status} {progress:2d}% {name}\n".format(
            status=status,
            progress=progress if progress >= 0 else 0,
            name=config.PLANTS[int(plant)][0]
        )

    return rv


if __name__ == "__main__":
    # For reading from csv:
    # raw = database.read_data_csv("data/HUMINO.CSV")
    raw = database.read_data()

    data = raw_to_hum(raw)
    status = status_message(data)
    with open(os.path.join(config.OUT_FOLDER, "status.txt"), "w") as f:
        f.write(status)

    logging.info(status)

    try:
        make_plot(data)
    except ValueError as e:
        logging.error("Error making plot: {}".format(e))
    else:
        plt.savefig(os.path.join(config.OUT_FOLDER, 'plot.png'))