コード例 #1
0
ファイル: routes.py プロジェクト: Rudrarka/Dashboard-Backend
def feeds():
    db_instance = Database()
    db = db_instance.mongodb_conn()
    feeds_collection = db['feeds']
    user_collection = db['users']
    feeds = feeds_collection.find().sort("_id", -1).limit(10)
    response = {}
    feed_list = []
    for feed in feeds:
        print(feed['userId'])
        user = user_collection.find_one({'userId': feed['userId']}, {
            '_id': 0,
            'displayName': 1,
            'profileImageUrl': 1
        })
        if user:
            response_item = {
                'id': str(feed['_id']),
                'displayName': user['displayName'],
                'avatar': user['profileImageUrl'],
                'feed': feed['feed']
            }
            feed_list.append(response_item)
    response = {'data': feed_list}
    print(response)
    return jsonify(response)
コード例 #2
0
def stats():
    db_instance = Database()
    db = db_instance.mongodb_conn()
    stats_collection = db['appStatistics']
    app_stats = stats_collection.find_one({'app':'organization'})
    if app_stats:
        response = {
            'data' : [
                {
                    'header' : 'New Visits',
                    'percent' : app_stats['nvPercent'],
                    'value' : app_stats['newVisits']
                },
                {
                    'header' : 'Purchases',
                    'percent' : app_stats['pPercent'],
                    'value' : app_stats['purchases']
                },
                {
                    'header' : 'Active Users',
                    'percent' : app_stats['auPercent'],
                    'value' : app_stats['activeUsers']
                },
                {
                    'header' : 'Returned',
                    'percent' : app_stats['ruPercent'],
                    'value' : app_stats['returnedUsers']
                }
            ]
        }
    
    return jsonify(response)
コード例 #3
0
def login(username, password):
    try:
        validator.valid_login(username, password)
        account = Database().find_one({'username': username})
        validator.valid_account(account)
        return security.checkpw(password, account['password'])
    finally:
        return False
コード例 #4
0
def post_languages_classification(classification):
    if "parent" not in classification:
        classification["parent"] = None
    if "children" not in classification:
        classification["children"] = []
    if "languages" not in classification:
        classification["languages"] = []
    Database().get_languages_classes().insert_one(classification)
コード例 #5
0
def setg():
    if config.debug:
        g.debug = "true"
    else:
        g.debug = "false"

    g.collections = Database().collection_names()
    g.rest = config.rest.root_bare

    g.username_length = config.username_length
    g.password_length_max = config.password_length_max
コード例 #6
0
ファイル: routes.py プロジェクト: Rudrarka/Dashboard-Backend
def country_data():
    db_instance = Database()
    db = db_instance.mongodb_conn()
    user_collection = db['users']
    count_object = user_collection.aggregate([{
        '$group': {
            '_id': '$region',
            'count': {
                '$sum': 1
            }
        }
    }])
    response = {}
    count_list = []
    count_list.append(['Country', 'Popularity'])
    for count in count_object:
        item = [count['_id'], count['count']]
        count_list.append(item)
    response = {'data': count_list}

    return jsonify(response)
コード例 #7
0
def disconnect(child_id, parent_id):
    database = Database().get_languages_classes()
    child = get_languages_classification_by_id(child_id)
    parent = get_languages_classification_by_id(parent_id)
    child["parent"] = None
    parent["children"].remove(child_id)
    database.replace_by_id(child)
    database.replace_by_id(parent)
コード例 #8
0
def super_app():
    db_instance = Database()
    db = db_instance.mongodb_conn()
    stats_collection = db['appStatistics']
    super_app_stats = stats_collection.find({'app': {'$ne' : 'organization'}}).sort([('totalVisits',-1)]).limit(1)
    print(super_app_stats)
    response_list = []
    for stats in super_app_stats:
        response_list = [
            stats['app'],
            stats['price'],
            {   
                'id':str(stats['_id']),
                'heading':'Total Visits',
                'value' : stats['totalVisits']
            },
            {
                'id':str(stats['_id']),
                'heading':'New Visits',
                'value' : stats['newVisits']
            },
            {
                'id':str(stats['_id']),
                'heading':'Sales',
                'value' : stats['purchases']
            },
            {
                'id':str(stats['_id']),
                'heading':'Active Users',
                'value' : stats['activeUsers']
            }
        ]
        
    response = {
        'data': response_list
        }
    print(response)    
    return jsonify(response)
コード例 #9
0
def connect(child_id, parent_id):
    database = Database().get_languages_classes()
    child = get_languages_classification_by_id(child_id)
    parent = get_languages_classification_by_id(parent_id)
    if child and parent:
        child["parent"] = parent["_id"]
        database.replace_by_id(child)
        if child_id not in parent["children"]:
            parent["children"].append(child_id)
        database.replace_by_id(parent)
コード例 #10
0
ファイル: processor.py プロジェクト: Zarimir/LanguageLearning
def process_request(request, _id):
    info = {}
    info['collection'] = process_collection(request)
    if info['collection'] == config.collections:
        return {config.collections: Database().collection_names()}
    info['method'] = request.method.lower()
    info['json'] = process_json(request)
    info['event'] = info['json'].pop('event', None)
    if info['event']:
        info['quantity'] = split_on_first_capital(info['event'])[2]
    elif _id:
        info['json'] = {'_id': _id}
        info['quantity'] = 'one'
    else:
        info['quantity'] = 'many'
    return execute(info)
コード例 #11
0
ファイル: main.py プロジェクト: jonatl4/CTC-Analytics
def main():
    """The controller of the entire program. It will handle initializing the facebook API connection, and call various modules in the program to perform tasks such as 
        grabbing the facebook ad accounts, storing values in the database, generating the html document and sending the html document to a list of clients"""
    FacebookConnection = FacebookAPI()  # Create the facebook api object
    FacebookAdAccounts = create_structure(
        FacebookConnection.get_accounts())  #dictionary of account name, id
    CTCDatabase = Database()
    db_account_ids = CTCDatabase.getListOfAccountIDs()
    curr_date = time.strftime("%Y-%m-%d")
    yesterday = (date.today() - timedelta(1)).strftime("%Y-%m-%d")

    for acc_name, acc_id in FacebookAdAccounts.items(
    ):  #iterate through all account names, ids
        acc_campaign_id = FacebookConnection.get_prospecting_campaign_id(
            acc_id)  #Grab the prospecting campaign id

        if acc_id not in db_account_ids:  #Case when we have a new account id being added to the database.
            campaign_stats = FacebookConnection.get_campaign_stats(
                acc_campaign_id
            )  #Get all the necessary data points required to calculate score
            CTCDatabase.insertCampaignData(campaign_stats, acc_id)
        else:  #Case where we only want to grab and insert to the db todays values
            campaign_stats = FacebookConnection.get_current_date_stats(
                acc_campaign_id, curr_date)
            CTCDatabase.insertCampaignData(campaign_stats, acc_id)

        #Grab all the historical values and todays values
        campaign_data_set = CTCDatabase.getCampaignData(acc_id, curr_date)
        curr_date_values = CTCDatabase.getCurrentDateValues(acc_id, curr_date)
        yesterday_values = CTCDatabase.getCurrentDateValues(acc_id, yesterday)
        ctc_score = calculate_ctc_score(campaign_data_set, curr_date_values)
        check_past = CTCDatabase.checkForPastScore(acc_id, yesterday)

        if check_past == True:  #This if statement is meant for brand new clients. We need to do a comparision from yesterdays date.
            yesterday_campaign_values = CTCDatabase.getCampaignData(
                acc_id, yesterday)
            yesterday_ctc_score = calculate_ctc_score(campaign_data_set,
                                                      curr_date_values)
            CTCDatabase.insertScores(yesterday_ctc_score,
                                     curr_date_values['account_name'],
                                     curr_date_values['account_id'], yesterday)

        percentage_change = calculate_percentage_change(
            curr_date_values, yesterday_values
        )  #calculate percentage change between todays and yesterdays values
        CTCDatabase.insertScores(ctc_score, curr_date_values['account_name'],
                                 curr_date_values['account_id'], curr_date)
        CTCDatabase.insertPerChange(percentage_change,
                                    curr_date_values['account_name'],
                                    curr_date_values['account_id'], curr_date)

        #The rest of the code will be dedicated to email creation
        print "Sending email for account: " + str(acc_name)
        email = Email(curr_date_values, ctc_score, percentage_change,
                      EMAIl_ADDRESS)
コード例 #12
0
def get_languages_classifications_tree():
    roots = Database().get_languages_classes().find({"parent": None})
    for i in range(len(roots)):
        roots[i] = languages_classification_children_explore(roots[i])
    return roots
コード例 #13
0
def delete_languages_classification_by_id(_id):
    Database().get_languages_classes().delete_by_id(_id)
コード例 #14
0
from modules.utils import *
from etc.config import *
spath = os.path.dirname(os.path.realpath(__file__))

# Listener for success attack
def success_attack(event):
    # print(event.retval)
    if len(event.retval) == 7:
        DB.saveAttack(event.retval)

if __name__ == '__main__':
    scheduler = BackgroundScheduler(jobstores=jobstores, executors=executors, job_defaults=job_defaults, timezone=utc)
    scheduler.remove_all_jobs()
    scheduler.add_listener(success_attack, EVENT_JOB_EXECUTED)
    # scheduler.add_listener(my_listener, EVENT_JOB_EXECUTED | EVENT_JOB_ERROR)
    DB = Database(connString)
    # DB = Database('pq://*****:*****@localhost:5432/ctf')
    teams = DB.getTeams(GAME['teams'])
    services = DB.getServices(GAME['services'])
    # loadExpolits(services)
    # scheduler.add_job(
    #     Zond.attack,
    #     args=(spath, 'check', '127.0.0.1', 'Test 1', 'test_flag'), # command for Zond
    #     max_instances=3, # how many instances (threads) open for this job
    #     trigger='interval', # job trigger type
    #     seconds=4, # repeat interval
    #     misfire_grace_time=int(3), # maximum waiting time
    #     executor='default' # executor (thread, process, custom)
    # ) #, executor='processpool')
    # scheduler.add_job(
    #     Zond.attack,
コード例 #15
0
def register(username, password):
    validator.valid_login(username, password)
    username_not_taken(username)
    hashed = security.hashpw(password)
    return Database().get_users().insert_one({'username': username, 'password': hashed})
コード例 #16
0
def get_language_by_id(arg):
    element = Database().get_languages().find_by_id(arg)
    element["classification"] = get_languages_classification_by_id(element["classification"])
    return element
コード例 #17
0
def username_not_taken(username):
    validator.valid_username(username)
    if Database().get_users().find_one({'username': username}):
        crash(config.username_taken)
コード例 #18
0
def get_languages_classification_by_id(classification_id):
    return Database().get_languages_classes().find_by_id(classification_id)
コード例 #19
0
def get_languages():
    Database().get_languages().find()
コード例 #20
0
def replace(account):
    _id = validator.has(account, '_id', ObjectId)
    validator.valid_account(account)
    return Database().get_users().replace_by_id(_id, account)
コード例 #21
0
def logs():
    db = Database()
    return render_template('logs.html', logs=db.get_access_log())
コード例 #22
0
 def __init__(self):
     if self.instance_n == 1:
         Database.__init__(self)
コード例 #23
0
ファイル: processor.py プロジェクト: Zarimir/LanguageLearning
def execute(info):
    res = Database(info['collection']).execute(info['method'], info['quantity'], info['json'])
    return jsonify(res)
コード例 #24
0
class Collection(Resource):
    def get(self, _id=None):
        return process_request(request, _id)

    def post(self, _id=None):
        return process_request(request, _id)

    def put(self, _id=None):
        return process_request(request, _id)

    def delete(self, _id=None):
        return process_request(request, _id)


addresses = [config.rest.root]
for name in Database().collection_names():
    address = config.rest.root + name
    addresses.append(address)
    addresses.append(address + '/<string:_id>')

api.add_resource(Collection, *addresses)


@app.before_request
def before_request():
    constants.setg()


@app.route('/')
def index():
    return render_template('index.html')
コード例 #25
0
def word(_id):
    element = Database().get_words().execute("get", "one", {"_id": _id})
    element['z'] = ["awoidjawoi", "OAWIdjoawid"]
    print(element)

    return render_template('word.html', element=element)
コード例 #26
0
def delete(_id):
    return Database().get_users().delete_by_id(_id)
コード例 #27
0
import shutil
import boto3
from time import gmtime, strftime
from os.path import join

from modules.db import Database

db = Database()


def index_faces_with_aws(images, collection, label):
    client = boto3.client('rekognition')
    try:
        client.create_collection(CollectionId=collection)
    except:
        print("Collection already exists!")

    for img in images:
        full_image_url = join("static/images/tmp", img)
        print(full_image_url)
        with open(full_image_url, 'rb') as image:
            response = client.index_faces(Image={'Bytes': image.read()},
                                          CollectionId=collection,
                                          ExternalImageId=label,
                                          DetectionAttributes=['ALL'])
            current = strftime("%Y-%m-%d %H:%M:%S", gmtime())
            db.insert_train_info(current, label, collection,
                                 response['FaceRecords'][0]['Face']['FaceId'],
                                 response['FaceRecords'][0]['Face']['ImageId'])

    # remove all tmp images after indexing them with AWS
コード例 #28
0
def get_language_by_name(language):
    return Database().get_languages().find_one({'language': language})