Esempio n. 1
0
    def connect(configs=config()):
        """
        tz_aware - if True, datetime instances returned as values in a document by this MongoClient will
        be timezone aware (otherwise they will be naive).

        w: (integer or string) If this is a replica set, write operations will block until they have been
        replicated to the specified number or tagged set of servers. w=<int> always includes the replica
        set primary (e.g. w=3 means write to the primary and wait until replicated to two secondaries).

        j: If True block until write operations have been committed to the journal. Ignored if the server
        is running without journaling.
        """
        host = unicode(configs['mongo']['host'])
        port = configs['mongo']['port']
        user = unicode(configs['mongo']['user'])
        password = unicode(configs['mongo']['password'])
        database = unicode(configs['mongo']['database'])
        collection = unicode(configs['mongo']['collection'])

        if host not in ('localhost', '127.0.0.1'):
            connection_uri = "mongodb://" + user + ":" + password + "@" + host + ":" + str(
                port) + '/' + database
            db = MongoClient(host=connection_uri, tz_aware=True, w=1,
                             j=True)[database]
        else:
            db = MongoClient(host, port, tz_aware=True, w=1, j=True)[database]

        return db
Esempio n. 2
0
    def connect(configs=config()):
        """
        tz_aware - if True, datetime instances returned as values in a document by this MongoClient will
        be timezone aware (otherwise they will be naive).

        w: (integer or string) If this is a replica set, write operations will block until they have been
        replicated to the specified number or tagged set of servers. w=<int> always includes the replica
        set primary (e.g. w=3 means write to the primary and wait until replicated to two secondaries).

        j: If True block until write operations have been committed to the journal. Ignored if the server
        is running without journaling.
        """
        host = unicode(configs['mongo']['host'])
        port = configs['mongo']['port']
        user = unicode(configs['mongo']['user'])
        password = unicode(configs['mongo']['password'])
        database = unicode(configs['mongo']['database'])
        collection = unicode(configs['mongo']['collection'])

        if host not in ('localhost', '127.0.0.1'):
            connection_uri = "mongodb://" + user + ":" + password + "@" + host + ":" + str(port) + '/' + database
            db = MongoClient(host=connection_uri, tz_aware=True, w=1, j=True)[database]
        else:
            db = MongoClient(host, port, tz_aware=True, w=1, j=True)[database]

        return db
Esempio n. 3
0
# -*- coding: utf-8 -*-

from datetime import datetime
from pymongo.errors import AutoReconnect
from pymongo import DESCENDING

from connectors import MongoDBConnection

db = MongoDBConnection.connect()
from helpers import config

config = config()
collection = config['mongo']['collection']


class LogEntry:
    """Main class for new log entries.

    Keyword arguments:
    owner - person ot system, who create this entry (required)
    datetimestamp - date and time, when entry was created (required)
    level - attentiveness level (required):
        - critical – for errors that lead to termination
        - error – for errors that occur, but are handled
        - warning – for exceptional circumstances that might not be errors
        - notice – for non-error messages you usually want to see
        - info – for messages you usually don’t want to see
        - debug – for debug messages
    data - main message body (required)
    tags - tags list for extended search
Esempio n. 4
0
# -*- coding: utf-8 -*-

from bson import ObjectId

from flask import request

from helpers import config, jsonify
from models import LogEntry
from exceptions import InvalidAPIUsage
from pymongo.errors import AutoReconnect

VERSION = "0.2.1"

config = config()


def index():
    """Status page

    Generating status (main) page and returns it.

    """
    response = {
        'name': "simplelogs",
        'type': "API",
        'status': "available",
        'version': VERSION
    }
    return jsonify(response)

Esempio n. 5
0
def create_short_url():
    old_url = request.form.get('url_old')
    new_url = domain + config().generate_random_string()
    dbutils().update_new_url_in_db(old_url, new_url)
    return new_url