def build_db(conn,TABLES): ''' Calls functions from create_db and populate_db to create ncdoc db, only if the file doesnt already exist ''' if conn: # Loop through tables for table_name in TABLES: print("Working on table...", table_name) # Make sure all the CSV files are in the data folder! # Default dtype will be string - need to convert later print("\tReading in table data as pandas DataFrame") table_data = pd.read_csv(config.data_folder + table_name + ".csv", dtype=str) columns = table_data.columns columns = ', '.join(columns) columns = clean_column_names(columns) print("\tCreating table in database...") create_table(conn, table_name, columns) records = extract_data(table_data) print("\tInserting records into table...") insert_records(conn, table_name, columns, records) # Close connection conn.commit()
def login_page(error): if error == "error": printError = "<h2>Login page. Enter please</h2><br /><br /><b style='color: red'>Somthing wrong :( I'm sad about this, but try again!</b><br /><br />" else: printError = "<h2>Login page. Enter please</h2><br /><br />" if create_db.check_db(): if create_db.create_table(): print('<div class="alert alert-success">DB was created<br />') create_db.update_all() print('<br />Now you can login, default: admin/admin</div>') ref = form.getvalue('ref') if ref is None: ref = "/index.html" print('<center><form name="auth" action="login.py" class="form-horizontal" method="get">') print(printError) print('<label for="login">Login: </label> <input type="text" name="login" required class="form-control"><br /><br />') print('<label for="pass">Pass: </label> <input type="password" name="pass" required class="form-control"><br /><br />') print('<input type="hidden" value="%s" name="ref">' % ref) print('<button type="submit" name="Login" value="Enter">Sign Up</button>') print('</form></center>')
#!/usr/bin/env python3 # -*- coding: utf-8 -*- import funct import sql import create_db import os from jinja2 import Environment, FileSystemLoader env = Environment(loader=FileSystemLoader('templates/'), autoescape=True) template = env.get_template('ovw.html') print('Content-type: text/html\n') if create_db.check_db(): if create_db.create_table(): create_db.update_all() create_db.update_all_silent() funct.check_login() try: user, user_id, role, token, servers = funct.get_users_params() groups = sql.select_groups() user_group = funct.get_user_group(id=1) if (role == 2 or role == 3) and int(user_group) != 1: users = sql.select_users(group=user_group) servers_for_grep = '' i = 0 servers_len = len(servers) for s in servers: i += 1 if i != servers_len:
def add_to_db(self): create_db.create_database() create_db.create_table() create_db.insert(self.name, self.url, self.email, self.password)
#!/usr/bin/env python3 # -*- coding: utf-8 -*-" import create_db from configparser import ConfigParser, ExtendedInterpolation path_config = "haproxy-webintarface.config" config = ConfigParser(interpolation=ExtendedInterpolation()) config.read(path_config) mysql_enable = config.get('mysql', 'enable') if mysql_enable == '1': from mysql.connector import errorcode import mysql.connector as sqltool else: db = "haproxy-wi.db" import sqlite3 as sqltool create_db.create_table() create_db.update_all()
import sqlite3 from sqlite3 import Error import pandas as pd from create_db import create_connection, create_table, clean_column_names from populate_db import extract_data, insert_records import config table_name = "OFNT3CE1" conn = create_connection(config.database_name) print("\tReading in table data as pandas DataFrame") table_data = pd.read_csv(config.data_folder + table_name + ".csv", dtype=str) columns = table_data.columns columns = ', '.join(columns) columns = clean_column_names(columns) print("\tCreating table in database...") print(columns) create_table(conn, table_name, columns) print("\tExtract records") records = extract_data(table_data) print("\tInserting records into table...") insert_records(conn, table_name, columns, records)
def dialog(message): if message.chat.type == 'private': table_name = '{0}_{1.id}'.format(month, message.from_user) if message.text == 'Стандартик': markup = types.InlineKeyboardMarkup(row_width=2) item1 = types.InlineKeyboardButton('500', callback_data='500') item2 = types.InlineKeyboardButton('1000', callback_data='1000') markup.add(item1, item2) bot.send_message(message.chat.id, 'Сколько запишем?', reply_markup=markup) elif message.text == 'Чо по бабкам?': try: summa = i_got(table_name) bot.send_message(message.chat.id, 'Эм... \n' + str(summa) + ' братка') except Exception as e: logger.error('Ошибка вывода общей суммы: ' + repr(e)) bot.send_message( message.chat.id, 'Новый месяц ещё не заведен в базе :(\nЖмакай' ' на кнопку "Новый месяц"') elif message.text == 'Новый месяц': try: create_table(table_name) bot.send_message( message.chat.id, 'Готово!\nНовый месяц "' + str(table_name) + '" дабавлен ;)') except Exception as e: logger.error('Ошибка создания таблицы: ' + repr(e)) bot.send_message(message.chat.id, 'Этот месяц "' + table_name + '" уже создан') elif message.text == 'Глянуть в прошлое': all_month_before = [] items_to_markup = [] now_month = date.strftime('%m') this_year = date.strftime('%Y') markup = types.InlineKeyboardMarkup(row_width=2) for i in range(1, int(now_month)): all_month_before.append('{0}_{1}_{2.id}'.format( MONTHS[i], this_year, message.from_user)) items_to_markup.append(f'item{i}') items_to_markup[i - 1] = types.InlineKeyboardButton( f'{TRANSLATE[MONTHS[i]]}', callback_data=f'{TRANSLATE[MONTHS[i]]}') markup.add(items_to_markup[i - 1]) bot.send_message(message.chat.id, 'Вебери месяц:', reply_markup=markup) elif message.text == 'Все движения': markup = types.InlineKeyboardMarkup(row_width=2) item1 = types.InlineKeyboardButton('Cколько движений', callback_data='count') item2 = types.InlineKeyboardButton('Посмотреть всё', callback_data='all') markup.add(item1, item2) bot.send_message(message.chat.id, 'Сейчас всё расскажу..', reply_markup=markup) else: if message.text: try: if int(message.text) < 500: add_summ(message.text, table_name) bot.send_message( message.chat.id, 'Мало!\nну сколько заработал {0}'.format( u"\U0001F595")) elif (int(message.text) >= 500) and (int(message.text) < 1000): add_summ(message.text, table_name) bot.send_message( message.chat.id, message.text + ' номально вышло, но нужно подтянуть' ' до кЭсика') elif int(message.text) >= 1000: add_summ(message.text, table_name) bot.send_message( message.chat.id, message.text + ' - вот номально вышло, умеешь же {0}'.format( u"\U0001F4AA")) except Exception as e: # print('Ошибка ввода сообщения: ' + repr(e)) logger.error('Ошибка ввода сообщения: ' + repr(e)) bot.send_message( message.chat.id, 'Нужно цыфры воодить! \nА если не создал ' 'новый месяц, то скорее жмакай на' ' одноименную кнопку') else: bot.send_message(message.chat.id, 'Не знаю что ответить :( ')