示例#1
0
from flask import Flask, request, jsonify
import dblib
import logger_module
import libencryption
import sys

logger = logger_module.setup_logger("secret")

if libencryption.check_key():
    print("Starting my super App")
    logger.debug('Starting my super App')
else:
    print('Cannot Find Server as file key.txt is not found')
    logger.debug('Cannot Find Server as file key.txt is not found')
    sys.exit("File key.txt is not found ")

app = Flask(__name__)
app.config['JSON_SORT_KEYS'] = False
app.config['APPLICATION_ROOT'] = '/api'
print("\n\n\n")


@app.route('/')
def index():
    logger.debug("Request for testing connection invoked")
    return 'Cool API is online :)'


@app.route('/ping')
def ping():
    logger.debug("Request for ping")
示例#2
0
import uuid
import mysql.connector
import datetime
import time
import logger_module
import config

logger = logger_module.setup_logger("dblib")


def open_db():
    try:
        logger.debug('open_db function invoked')
        mydb = mysql.connector.connect(
            host=config.dbconnection["host"],
            user=config.dbconnection["user"],
            passwd=config.dbconnection["passwd"],
            database=config.dbconnection["database"])
        logger.debug('open_db finished')
        return mydb
    except mysql.connector.Error as error:
        logger.error('There is no DB connection: {}'.format(error))


def close_db(mydb):
    try:
        logger.debug("close_db function invoked")
        mydb.close()
        logger.debug("close_db finished")

    except mysql.connector.Error:
示例#3
0
from flask import Flask, request, jsonify
import json
import lib
import logger_module
import json

logger = logger_module.setup_logger("todo")
logger.debug('Start my super App')
app = Flask(__name__)
app.config['JSON_SORT_KEYS'] = False
print("\n\n\n")


@app.route('/')
def index():
    return 'Flow Runner :)'


# get data through todo (not forget to transfer obtained tupple to the string)


@app.route('/todo')
def get_todo():
    logger.debug('run invoked')
    all_data = lib.get_all()
    # rs = json.dumps(all_data)
    respond = json.loads(all_data)
    logger.debug("get information from all ids: " + str(respond))
    print(respond)
    return jsonify(all_collected_data=respond)
示例#4
0
import mysql.connector
import logger_module
import logger_module
logger = logger_module.setup_logger("todo2-lib")

mydb = mysql.connector.connect(host="db4free.net",
                               user="******",
                               passwd="coolspammail-pass",
                               database="coolspammail")


def get_all():
    """get flowdata from db."""
    logger.debug("get_all invoked")
    myresult = ''
    try:
        mycursor = mydb.cursor()
        sql = "SELECT * FROM `todo`"
        mycursor.execute(sql)
        myresult = mycursor.fetchall()
    except:
        print("Something went wrong in get_all")
    logger.debug("get_all myresult" + str(myresult))
    return myresult


def get_todo_by_id(id):
    # myresult = ''
    try:
        mycursor = mydb.cursor()
        sql = "SELECT * FROM todo WHERE id = %s;"
示例#5
0
from flask import Flask, request, jsonify
import datetime
import lib
import logger_module
logger = logger_module.setup_logger("flowsapp")
logger.debug('Start my super App')


app = Flask(__name__)
app.config['JSON_SORT_KEYS'] = False

print("\n\n\n\n\n\n\n\n\n\n")


@app.route('/')
def index():
    logger.debug("Request for testing connection invoked")
    return 'Flow Runner :)'


@app.route('/run/<string:username>/<string:flow>')
def run(username, flow):
    logger.debug('Run invoked')
    data = lib.get_flowdata(username, flow)
    print(data)
    # data = [(u'weather:Brooklyn, NY',), (u'news:3',), (u'norris:3',), (u'news:2',), (u'thecocktail:random',), (u'thecocktail:random',)]
    logger.debug("Data from DB(actionline):" + str(data))
    if not data:  # len(data) == 0:
        return jsonify(
            error="no data for this user and flow",
            username=username,
示例#6
0
from cryptography.fernet import Fernet
import logger_module
import os.path
import config

logger = logger_module.setup_logger("libencryption")


def get_cryptor():
    try:
        logger.debug("Start to read a key")
        key = config.key
        # logger.debug("Get a key: " + key)
        cryptography = Fernet(key)
    except IOError:
        logger.error('An error occured trying to read the file.')
    except Exception as error:
        logger.error(error)
    return cryptography


def encrypt(msg):
    try:
        logger.debug("Start encryption with a key")
        encryption = get_cryptor()
        msgn = bytes(msg)
        encrypted_msg = encryption.encrypt(msgn)
        logger.debug("Encrypted message: " + encrypted_msg)
    except IOError:
        logger.error('An error occured trying to read the file.')
    except ValueError:
示例#7
0
import logger_module
import os

logger = logger_module.setup_logger("utils")


def check_config():
    try:
        logger.debug("Check key")
        if os.path.isfile('./config.py'):
            return True
        else:
            return False
    except IOError:
        logger.error('An error occured trying to read the key.')
    except Exception as error:
        logger.error(error)
示例#8
0
import uuid
import mysql.connector
import datetime
import time
import logger_module
import json
from cryptography.fernet import Fernet

logger = logger_module.setup_logger("secret-2lib")


def open_db():
    mydb = mysql.connector.connect(host="db4free.net",
                                   user="******",
                                   passwd="coolspammail-pass",
                                   database="coolspammail")
    return mydb


def close_db(mydb):
    mydb.close()


def is_not_expired(created, exp):
    try:
        logger.debug(
            "Time function to control expiration time of the msg invoked")
        my_time = created + datetime.timedelta(0, exp)
        logger.debug("Time before expiration: " + str(my_time))
        current_time = datetime.datetime.utcnow()
        logger.debug("Current time: " + str(current_time))
示例#9
0
import json
import mysql.connector
import telebot
import logger_module
logger = logger_module.setup_logger("lib2")


def open_db():
    mydb = mysql.connector.connect(host="db4free.net",
                                   user="******",
                                   passwd="coolspammail-pass",
                                   database="coolspammail")
    return mydb


def close_db(mydb):
    mydb.close()


def get_all():
    """get flowdata from db."""
    mydb = open_db()
    mycursor = mydb.cursor()
    sql = "SELECT * FROM `todo`"
    mycursor.execute(sql)
    # this will extract row headers
    rv = mycursor.fetchall()
    row_headers = [x[0] for x in mycursor.description]
    json_data = []
    for result in rv:
        json_data.append(dict(zip(row_headers, result)))
示例#10
0
import mysql.connector
import logger_module

logger = logger_module.setup_logger("open_dblib")


def open_db():
    try:
        logger.debug('open_db function invoked')
        mydb = mysql.connector.connect(
            host="db4free.net",
            user="******",
            passwd="coolspammail-pass",
            database="coolspammail"
        )
        logger.debug('open_db finished')
        return mydb
    except mysql.connector.Error as error:
        logger.error('There is no DB connection: {}'.format(error))