Esempio n. 1
0
def get_results_csv():  # todo: need to fix time format
    """
    get host's logs through the API in JSON type

    Returns:
        an array with JSON events
    """
    api_key_is_valid(app, flask_request)
    session = create_connection()
    result_id = get_value(flask_request, "id")
    if not result_id:
        return jsonify(
            structure(status="error", msg=messages("invalid_scan_id"))), 400
    scan_details = session.query(Report).filter(Report.id == result_id).first()
    data = get_logs_by_scan_unique_id(scan_details.scan_unique_id)
    keys = data[0].keys()
    filename = ".".join(
        scan_details.report_path_filename.split('.')[:-1])[1:] + '.csv'
    with open(filename, "w") as report_path_filename:
        dict_writer = csv.DictWriter(report_path_filename,
                                     fieldnames=keys,
                                     quoting=csv.QUOTE_ALL)
        dict_writer.writeheader()
        for event in data:
            dict_writer.writerow(
                {key: value
                 for key, value in event.items() if key in keys})
    with open(filename, 'r') as report_path_filename:
        reader = report_path_filename.read()
    return Response(
        reader,
        mimetype='text/csv',
        headers={'Content-Disposition': 'attachment;filename=' + filename})
Esempio n. 2
0
def get_results_json():
    """
    get host's logs through the API in JSON type

    Returns:
        an array with JSON events
    """
    api_key_is_valid(app, flask_request)
    session = create_connection()
    result_id = get_value(flask_request, "id")
    if not result_id:
        return jsonify(
            structure(
                status="error",
                msg=messages("invalid_scan_id")
            )
        ), 400
    scan_details = session.query(Report).filter(Report.id == result_id).first()
    json_object = json.dumps(
        get_logs_by_scan_unique_id(
            scan_details.scan_unique_id
        )
    )
    filename = ".".join(scan_details.report_path_filename.split('.')[:-1])[1:] + '.json'
    return Response(
        json_object,
        mimetype='application/json',
        headers={
            'Content-Disposition': 'attachment;filename=' + filename
        }
    )
Esempio n. 3
0
def __get_results_json():
    """
    get host's logs through the API in JSON type

    Returns:
        an array with JSON events
    """
    session = create_connection(__language())
    __api_key_check(app, flask_request, __language())
    try:
        _id = int(__get_value(flask_request, "id"))
        scan_id_temp = session.query(Report).filter(Report.id == _id).all()
    except Exception as _:
        _id = ""
    if(scan_id_temp):
        result_id = session.query(Report).join(HostsLog, Report.scan_id == HostsLog.scan_id).filter(Report.scan_id == scan_id_temp[0].scan_id).all()
    else:
        result_id = []
    json_object = {}
    if(result_id):
        scan_id = result_id[0].scan_id
        data = __logs_by_scan_id(scan_id, __language())
        json_object = json.dumps(data)
    date_from_db = scan_id_temp[0].date
    date_format = datetime.strptime(date_from_db, "%Y-%m-%d %H:%M:%S")
    date_format = str(date_format).replace("-", "_").replace(":", "_").replace(" ", "_")
    filename = "report-" + date_format +"".join(random.choice(string.ascii_lowercase) for x in range(10))
    return Response(json_object, mimetype='application/json', headers={'Content-Disposition':'attachment;filename='+filename+'.json'})
Esempio n. 4
0
def __get_results_csv():
    """
    get host's logs through the API in JSON type

    Returns:
        an array with JSON events
    """
    session = create_connection(__language())
    __api_key_check(app, flask_request, __language())
    try:
        _id = int(__get_value(flask_request, "id"))
        scan_id_temp = session.query(Report).filter(Report.id == _id).all()
    except Exception as _:
        _id = ""
    if (scan_id_temp):
        result_id = session.query(Report).join(
            HostsLog, Report.scan_id == HostsLog.scan_id).filter(
                Report.scan_id == scan_id_temp[0].scan_id).all()
    else:
        result_id = []
    date_from_db = scan_id_temp[0].date
    date_format = datetime.strptime(date_from_db, "%Y-%m-%d %H:%M:%S")
    date_format = str(date_format).replace("-",
                                           "_").replace(":",
                                                        "_").replace(" ", "_")
    filename = "report-" + date_format + "".join(
        random.choice(string.ascii_lowercase) for x in range(10))
    _reader = ''
    if (result_id):
        scan_id = result_id[0].scan_id
        data = __logs_by_scan_id(scan_id, __language())
        keys = data[0].keys()
        with open(filename, "w") as output_file:
            dict_writer = csv.DictWriter(output_file,
                                         fieldnames=keys,
                                         quoting=csv.QUOTE_ALL)
            dict_writer.writeheader()
            for i in data:
                dictdata = {
                    key: value
                    for key, value in i.items() if key in keys
                }
                dict_writer.writerow(dictdata)
        print_data = []
        with open(filename, 'r') as output_file:
            _reader = output_file.read()
    return Response(_reader,
                    mimetype='text/csv',
                    headers={
                        'Content-Disposition':
                        'attachment;filename=' + filename + '.csv'
                    })
Esempio n. 5
0
import cv2
import numpy as np
from keras.models import model_from_json
from keras.preprocessing import image
from database import db

database = r"C:\Users\Orkhan ALIYEV\Desktop\Django\hackathon\db.sqlite3"
# create a database connection
conn = db.create_connection(database)

#load model
model = model_from_json(open("fer_json.json", "r").read())
#load weights
model.load_weights('fer.h5')

face_haar_cascade = cv2.CascadeClassifier(
    'haarcascade_frontalface_default.xml')

cap = cv2.VideoCapture(0)

while True:
    ret, test_img = cap.read(
    )  # captures frame and returns boolean value and captured image
    if not ret:
        continue
    gray_img = cv2.cvtColor(test_img, cv2.COLOR_BGR2GRAY)

    faces_detected = face_haar_cascade.detectMultiScale(gray_img, 1.32, 5)

    for (x, y, w, h) in faces_detected:
        cv2.rectangle(test_img, (x, y), (x + w, y + h), (255, 0, 0),
Esempio n. 6
0
def handle(msg):
    chat_id = msg['chat']['id']
    chat_username = msg['chat']['username']
    command = msg['text']
    subscribe = "اشترك في التذكير للامتحانات"
    Suggestion = "اقتراح"

    print('Got command: %s' % command)
    if command == "/start":
        a = " أهلا"
        c = " السلام عليكم ورحمة الله وبركاتة أتمنى أن تكون بأفضل حال "
        v = " يسعدني ويشرفني خدمتك \n أنا البوت الخاص ببنك الطالب"
        h = " ملاحظة: في حالة لم يلبي البوت غرضك فضلا قم بالتواصل معنى على الايميل الخاص بالدعم الفني [email protected]"
        b = "فضلا قم بإختيار زر الاشتراك للاشتراك في خدمة التذكير بمواعيد الامتحانات"
        start = "{}\t{}\n{}\n{}\n{}\n\n\n\n{}".format(a, chat_username, c, v, b, h)
        bot.sendMessage(chat_id, start, reply_markup=json_keyboard)

    elif command == "السلام" or command == "السلام عليكم" or command == "السلام عليكم ورحمة الله ويركاته":
        a = "وعليكم السلام ورحمة الله وبركاته \nأهلا بك تفضل انا أنا البوت الخاص ببنك الطالب\nكيف اقدر أخدمك"
        bot.sendMessage(chat_id, a, reply_markup=json_keyboard)
        conn = db.create_connection(database)
        with conn:
            db.insert_date(conn, 'bot', "send, mass, type, user,id,time", "'{}','{}','{}', '{}','{}','{}'".
                           format(command, a, command, chat_username, chat_id, tim))

    elif command == subscribe:
        a = "شكرا لاشتراكك في خدمة ذكرني\n فضلاً اكتب رقم المادة المراد الاشتراك فيها من القائمة أدناه"
        bot.sendMessage(chat_id, a, reply_markup=json_keyboard)
        conn = db.create_connection(database)
        with conn:
            db.insert_date(conn, 'bot', "send, mass, type,user,id, time", "'{}','{}','{}','{}', '{}','{}'"
                           .format(subscribe, a, subscribe, chat_username, chat_id, tim))

    elif command == "من أنت":
        a = "أنا البوت الخاص ببنك الطالب لقد قام ببرمجتني الطالبة نورة الوابل كيف ممكن اخدمك "
        bot.sendMessage(chat_id, a, reply_markup=json_keyboard)
        conn = db.create_connection(database)
        with conn:
            db.insert_date(conn, 'bot', "send, mass, type,user,id,time",
                           "'{}','{}','{}','{}', '{}','{}'".format(Suggestion, a, Suggestion, chat_username, chat_id,
                                                                   tim))
    elif command == "وش بنك الطالب هذا" or command == "وش هذا بنك الطالب" or command == "وش هذا البوت" or command == "ماهذا البوت":
        a = "بنك الطالب هو مشروع صغير يخزن المصادر المهمة لبعض المواد الدراسية "\
            "حالياً لدينا المصادر الخاصة بمادتي تقنيات المصادر المفتوحة 542، وهندسة البرمجيات 323"\
            ""\
            "كذلك بنك الطالب يقدم خدمة ذكرني، للتذكير بمواعيد الامتحانات الخاصة بالمود المتاحة للاشتراك"\
        bot.sendMessage(chat_id, a, reply_markup=json_keyboard)
        conn = db.create_connection(database)
        with conn:
            db.insert_date(conn, 'bot', "send, mass, type,user,id,time",
                           "'{}','{}','{}','{}', '{}','{}'".format(Suggestion, a, Suggestion, chat_username, chat_id,
                                                                   tim))
    elif command == "نورة":
        a = "اهلا انا لست نورة انا البوت الخاص ببنك الطالب"
        bot.sendMessage(chat_id, a, reply_markup=json_keyboard)
        conn = db.create_connection(database)
        with conn:
            db.insert_date(conn, 'bot', "send, mass, type,user,id,time",
                           "'{}','{}','{}','{}', '{}','{}'".format(Suggestion, a, Suggestion, chat_username, chat_id,
                                                                   tim))
    elif command == "مادة" or command == "كورس":
        a = "ماهو اسم المادة"
        bot.sendMessage(chat_id, a, reply_markup=json_keyboard)
        conn = db.create_connection(database)
        with conn:
            db.insert_date(conn, 'bot', "send, mass, type,user,id,time",
                           "'{}','{}','{}','{}', '{}','{}'".format(Suggestion, a, Suggestion, chat_username, chat_id,
                                                                   tim))
    elif command == "وش المواد المتاحة مصادرها" or command == "وش المواد الموجودة" or command == "وش الكورسات المتوفرة" or command == "أسماء الكورسات المتاحة":
        a = "حالياً لدينا المصادر الخاصة بمادتي تقنيات المصادر المفتوحة 542، وهندسة البرمجيات 323"
        bot.sendMessage(chat_id, a, reply_markup=json_keyboard)
        conn = db.create_connection(database)
        with conn:
            db.insert_date(conn, 'bot', "send, mass, type,user,id,time",
                           "'{}','{}','{}','{}', '{}','{}'".format(Suggestion, a, Suggestion, chat_username,
                                                                   chat_id,
                                                                   tim))
    elif command == "وش تقصد بالمصادر" or command == "ماذا تعني بالمصادر" or command == "ماهي المصادر اللتي قد أحصل عليها" or command == "زودني بالمصادر":
        a = "المصادر اللتي نملكها: الكتاب الخاصة بالمادة، توصيف المقرر، الشرائح الخاصة بالدكتور"
        bot.sendMessage(chat_id, a, reply_markup=json_keyboard)
        conn = db.create_connection(database)
        with conn:
            db.insert_date(conn, 'bot', "send, mass, type,user,id,time",
                           "'{}','{}','{}','{}', '{}','{}'".format(Suggestion, a, Suggestion, chat_username, chat_id,
                                                                   tim))
    elif command == "وجهني":
        a = "اكتب اسم المقرر الذي تحتاج مصادره"\
            "تقنيات المصادر المفتوحة"\
            "هندسة البرمجيات"
        bot.sendMessage(chat_id, a, reply_markup=json_keyboard)
        conn = db.create_connection(database)
        with conn:
            db.insert_date(conn, 'bot', "send, mass, type,user,id,time",
                           "'{}','{}','{}','{}', '{}','{}'".format(Suggestion, a, Suggestion, chat_username, chat_id,
                                                                   tim))
    elif command == "Open Source" or command == "اوبن سورس" or command == "المصادر المفتوحة" or command == "تقنيات المصادر المفتوحة" or command == "547" or command == "IT 547" or command == "Open Source Technology" :
        a = "حدد المصدر الذي تريده"\
            "توصيف المصادر المفتوحة"\
            "المرجع الخاص بالمصادر المفتوحة"\
            "الشرائح الخاصة بالمصادر المفتوحة"
        bot.sendMessage(chat_id, a, reply_markup=json_keyboard)
        conn = db.create_connection(database)
        with conn:
            db.insert_date(conn, 'bot', "send, mass, type,user,id,time",
                           "'{}','{}','{}','{}', '{}','{}'".format(Suggestion, a, Suggestion, chat_username, chat_id,
                                                                   tim))

    elif command == "توصيف المصادر المفتوحة" or command == "توصيف اوبن سورس" or command == "توصيف مقرر المصادر المفتوحة":
        a = "توصيف المقرر: يهدف المقرر إلى تعريف الطالبة بتاريخ المصادر المفتوحه والنظام الإيكولوجي (ecosystem)، " \
            "وتزويدها بالمفاهيم المتعلقة بتراخيص البرمجيات الحرة والمصادر المفتوحه، وتكييف برمجيات المصادر المفتوحة " \
            "،وكذلك أساليب إنتاج برمجيات المصادر المفتوحة، بالإضافة إلى أدوات وتقنيات المصادر المفتوحة والتوجه " \
            "المستقبلي لتطورها. "\
            ""\
            ""\
            ""\
            ""
        bot.sendMessage(chat_id, a, reply_markup=json_keyboard)
        conn = db.create_connection(database)
        with conn:
            db.insert_date(conn, 'bot', "send, mass, type,user,id,time",
                           "'{}','{}','{}','{}', '{}','{}'".format(Suggestion, a, Suggestion, chat_username, chat_id,
                                                                   tim))
            
    elif command == "المرجع الخاص بالمصادر المفتوحة" or command == "كتاب الاوبن سورس" or command == "كتاب مقرر المصادر المفتوحة":
        a = "تفضل رابط التحميل" \
            "http://www.mediafire.com/file/e8rmk9go5enyhfb/Books%20Open%20Source.zip"\
            ""
        bot.sendMessage(chat_id, a, reply_markup=json_keyboard)
        conn = db.create_connection(database)
        with conn:
            db.insert_date(conn, 'bot', "send, mass, type,user,id,time",
                           "'{}','{}','{}','{}', '{}','{}'".format(Suggestion, a, Suggestion, chat_username, chat_id,
                                                                   tim))
    
    elif command == "الشرائح الخاصة بالمصادر المفتوحة" or command == "الفصول الخاصة بالاوبن سورس" or command == "اوبن سورس تشابترز":
        a = "تفضل رابط التحميل" \
            "http://www.mediafire.com/file/l62soykp2dsg890/Chapters%20Open%20source.zip"\
            ""
        bot.sendMessage(chat_id, a, reply_markup=json_keyboard)
        conn = db.create_connection(database)
        with conn:
            db.insert_date(conn, 'bot', "send, mass, type,user,id,time",
                           "'{}','{}','{}','{}', '{}','{}'".format(Suggestion, a, Suggestion, chat_username, chat_id,
                                                                   tim))
    
    elif command == "software engineer" or command == "سوفتوير" or command == "هندسة" or command == "هندسة البرمجيات" or command == "323" or command == "IT 323" or command == "Software Engineer" :
        a = "حدد المصدر الذي تريده"\
            "توصيف هندسة البرمجيات"\
            "المرجع الخاص بهندسة البرمجيات"\
            "الشرائح الخاصة بهندسة البرمجيات"
        bot.sendMessage(chat_id, a, reply_markup=json_keyboard)
        conn = db.create_connection(database)
        with conn:
            db.insert_date(conn, 'bot', "send, mass, type,user,id,time",
                           "'{}','{}','{}','{}', '{}','{}'".format(Suggestion, a, Suggestion, chat_username, chat_id,
                                                                   tim))
            
    elif command == "توصيف هندسة البرمجيات" or command == "توصيف سوفتوير" or command == "توصيف مقرر هندسة البرمجيات":
        a = "يتبع المقرر مقرر هندسة البرامج-1 حيث أنه يستمر في دراسة دورة حياة تطوير البرامج"\ 
            "ستتمكن الطالبات من معاينة والتمكن من المراحل المتبقية من دورة حياة تطوير البرامج. "\
            "بدءا من لمحة مفصلة عن علميات البرمجة ومراجعة ما قد تم تعلمه في المقرر السابق ، "\
            "ستتعرض الطالبات لتغطية متعمقةلمفاهيم التصميم والتي لم يتم تقديمها في هندسة البرامج I،"\
            "بما في ذلك التصميم المعماري ومباديء تصميم الواجهة. بعد ذلك سيتعرض المقرر لطرق مختلفة لتطوير البرامج،"\
            "بما في ذلك التطوير السريع للبرامج، البرمجة المفرطة، وهندسة البرامج المعتمدة على العناصر."\
            "كما يقدم المقرر بعد ذلك فاعلية البرامج والتحقق منها بما في ذلك عمليات التفتيش ومختلف تقنيات الاختبار الديناميكي."\
            "بعد وضع النظم في الاستخدام لابد من تغييرها إذا كان عليها البقاء صالحة."\
            "يعرض المقرر للطالبات عملية تطوير البرنامج و صيانة البرمجيات. تعتبر "\
            "إدارة الكود وعملية التوثيق للنظام المطور من أهم العناصر في أي تطوير برمجي، يقدم المقرر للطالبات مبادئ إدارة التغيير."\ 
            "وفي التهاية يعطي القرر لمحة موجزة عن إدارة جودة البرمجيات بما فيها مقاييس وقياسات البرامج" 
        bot.sendMessage(chat_id, a, reply_markup=json_keyboard)
        conn = db.create_connection(database)
        with conn:
            db.insert_date(conn, 'bot', "send, mass, type,user,id,time",
                           "'{}','{}','{}','{}', '{}','{}'".format(Suggestion, a, Suggestion, chat_username, chat_id,
                                                                   tim))
    elif command == "المرجع الخاص بهندسة البرمجيات" or command == "كتاب السوفتوير" or command == "كتاب مقرر هندسة البرمجيات":
        a = "تفضل رابط التحميل" \
            "http://www.mediafire.com/file/fqk3cbtbg9ah3sx/Book.pdf"\
            ""
        bot.sendMessage(chat_id, a, reply_markup=json_keyboard)
        conn = db.create_connection(database)
        with conn:
            db.insert_date(conn, 'bot', "send, mass, type,user,id,time",
                           "'{}','{}','{}','{}', '{}','{}'".format(Suggestion, a, Suggestion, chat_username, chat_id,
                                                                   tim))
    
    elif command == "الشرائح الخاصة بهندسة البرمجيات" or command == "الفصول الخاصة بهندسة البرمجيات" or command == "سوفتوير تشابترز":
        a = "تفضل رابط التحميل" \
            "http://www.mediafire.com/file/5v7l3l5vjsyujzj/Chapters%20Software%20Engineer.zip"\
            ""
        bot.sendMessage(chat_id, a, reply_markup=json_keyboard)
        conn = db.create_connection(database)
        with conn:
            db.insert_date(conn, 'bot', "send, mass, type,user,id,time",
                           "'{}','{}','{}','{}', '{}','{}'".format(Suggestion, a, Suggestion, chat_username, chat_id,
                                                                   tim))
    else:
        bot.sendMessage(chat_id, ' لم اعرف ماذا تريد، أكتب "وجهني" أو "ماهذا البوت" حتى أستطيع مساعدتك', reply_markup=json_keyboard)
Esempio n. 7
0
import os
from database.db import create_connection

path = os.getcwd()

split_path = path.split('/')

while split_path[-1] != 'Recommender-System':
    print(split_path)
    path = "/".join(split_path[:-1])
    print(path)
    split_path = path.split('/')

path += "/recommender-db.db"

print(path)

db = create_connection(path)