Esempio n. 1
0
def migration(request):
    """
    REMINDER : pkg install databases/py-sqlite3 && pkg install sqlite3
    get the file uploaded to generate a slite3 connector
    calls main method processing to spawn each field of vulture database with the connector
    """
    form = MigrationForm(request.POST or None)
    if request.method == 'POST':
        try:
            # store the sqlite3 db file to a temp path
            default_storage.DEFAULT_FILE_STORAGE = '/tmp/'
            logger.info("Starting import process")
            f = request.FILES['file']
            f.content_type = "application/x-sqlite3"
            path = default_storage.save('tmp/migration-temp.db', ContentFile(f.read()))
            conn = sqlite3_connect('/home/vlt-gui/vulture/static/'+path)
            # start a subprocess for processing datas
            m = Process(name='script', target=processing, args=[conn, ])
            m.start()
            return HttpResponseRedirect('/migration/')
        except:
            raise



    else:
        return render_to_response('migration_vulture.html', {'form': form}, context_instance=RequestContext(request))
Esempio n. 2
0
def db_connect(config):
    db = None
    if config['DEBUG']:
        db = sqlite3_connect(config['DB_NAME'] + '.db')
    else:
        db = pymysql_connect(host=config['MYSQL_DB_HOST'], user=config['MYSQL_DB_USER'],
                             password=config['MYSQL_DB_PASSWORD'], database=config['DB_NAME'], charset='utf8')
    return db
Esempio n. 3
0
 def __init__(self):
     conn = sqlite3_connect(":memory:")
     writer = SQLiteAdjustmentWriter(conn)
     empty = DataFrame(
         {"sid": array([], dtype=uint32), "effective_date": array([], dtype=uint32), "ratio": array([], dtype=float)}
     )
     writer.write(splits=empty, mergers=empty, dividends=empty)
     super(NullAdjustmentReader, self).__init__(conn)
Esempio n. 4
0
def dbcon():
    """ opens sqlite database connection from config """
    parser = RawConfigParser()
    basedir = dirname(__file__)
    configdir = path_join(basedir, 'config.ini')
    parser.read(configdir)
    dbpath = parser.get('database', 'path')
    con = sqlite3_connect(dbpath)
    return (con)
Esempio n. 5
0
 def open(self,filename = DATABASE_FILENAME, replace = False):
  if self.connection and replace: self.close()
  if not self.connection:
   self.connection = sqlite3_connect(filename,isolation_level = 'DEFERRED')
   self.connection.text_factory = str
   self.connection.row_factory = sqlite3_row
   self._cursor = self.connection.cursor() 
  else:
   print 'Connection already open'
Esempio n. 6
0
 def __init__(self):
     conn = sqlite3_connect(':memory:')
     writer = SQLiteAdjustmentWriter(conn)
     empty = DataFrame({
         'sid': array([], dtype=uint32),
         'effective_date': array([], dtype=uint32),
         'ratio': array([], dtype=float),
     })
     writer.write(splits=empty, mergers=empty, dividends=empty)
     super(NullAdjustmentReader, self).__init__(conn)
Esempio n. 7
0
 def __init__(self):
     conn = sqlite3_connect(':memory:')
     writer = SQLiteAdjustmentWriter(conn)
     empty = DataFrame({
         'sid': array([], dtype=uint32),
         'effective_date': array([], dtype=uint32),
         'ratio': array([], dtype=float),
     })
     writer.write(splits=empty, mergers=empty, dividends=empty)
     super(NullAdjustmentReader, self).__init__(conn)
Esempio n. 8
0
    def __init__(self):
        self.conn = sqlite3_connect(":memory:")
        self.sqldir = Path(root()).joinpath("storage", "sql_queries", "sqlite")

        create_tables = [
            "create_table_users",
            "create_table_games"]
        for table in create_tables:
            with self.sqldir.joinpath("%s.sql" % table).open() as sqlfile:
                self.conn.cursor().execute(sqlfile.read())
Esempio n. 9
0
def is_enabled(addon, home):

    db = sqlite3_connect("%s/userdata/Database/Addons27.db" % (home))
    cursor = db.cursor()

    id = cursor.execute(
        "SELECT 1 FROM installed WHERE addonID = '%s' AND enabled"
        % (addon)
    ).fetchone()
    db.close()

    return True if id else False
    def create_connection(self):
        """create_connection(str) -> return sqlite connection

           Creates a database connection to the SQLite database

           :return
                Returns either a connection object or None
        """

        try:
            self._conn = sqlite3_connect(self._db_file_name)
            self._conn.row_factory = Row  # returns the data as a dictionary instead of tuples
        except Error as e:
            raise e
Esempio n. 11
0
def remove_addon(addon, home):
    changed = False
    if exists("%s/addons/%s" % (home, addon)):
        rm_rf("%s/addons/%s" % (home, addon))
        changed = True
    db = sqlite3_connect("%s/userdata/Database/Addons27.db" % (home))
    cursor = db.cursor()
    id = cursor.execute(
        "SELECT id FROM installed WHERE addonID = '%s'"
        % (addon)
    ).fetchone()
    if id:
        cursor.execute("DELETE FROM installed WHERE idAddon = '%s'" % (addon))
        changed = True
        db.commit()
    db.close()
    return changed
Esempio n. 12
0
 def __init__(self):
     conn = sqlite3_connect(":memory:")
     writer = SQLiteAdjustmentWriter(conn, None, None)
     empty = DataFrame(
         {"sid": array([], dtype=uint32), "effective_date": array([], dtype=uint32), "ratio": array([], dtype=float)}
     )
     empty_dividends = DataFrame(
         {
             "sid": array([], dtype=uint32),
             "amount": array([], dtype=float64),
             "record_date": array([], dtype="datetime64[ns]"),
             "ex_date": array([], dtype="datetime64[ns]"),
             "declared_date": array([], dtype="datetime64[ns]"),
             "pay_date": array([], dtype="datetime64[ns]"),
         }
     )
     writer.write(splits=empty, mergers=empty, dividends=empty_dividends)
     super(NullAdjustmentReader, self).__init__(conn)
Esempio n. 13
0
 def __init__(self):
     conn = sqlite3_connect(':memory:')
     writer = SQLiteAdjustmentWriter(conn, None, None)
     empty = DataFrame({
         'sid': array([], dtype=uint32),
         'effective_date': array([], dtype=uint32),
         'ratio': array([], dtype=float),
     })
     empty_dividends = DataFrame({
         'sid': array([], dtype=uint32),
         'amount': array([], dtype=float64),
         'record_date': array([], dtype='datetime64[ns]'),
         'ex_date': array([], dtype='datetime64[ns]'),
         'declared_date': array([], dtype='datetime64[ns]'),
         'pay_date': array([], dtype='datetime64[ns]'),
     })
     writer.write(splits=empty, mergers=empty, dividends=empty_dividends)
     super(NullAdjustmentReader, self).__init__(conn)
Esempio n. 14
0
 def __init__(self):
     conn = sqlite3_connect(':memory:')
     writer = SQLiteAdjustmentWriter(conn, None, None)
     empty = DataFrame({
         'sid': array([], dtype=uint32),
         'effective_date': array([], dtype=uint32),
         'ratio': array([], dtype=float),
     })
     empty_dividends = DataFrame({
         'sid': array([], dtype=uint32),
         'amount': array([], dtype=float64),
         'record_date': array([], dtype='datetime64[ns]'),
         'ex_date': array([], dtype='datetime64[ns]'),
         'declared_date': array([], dtype='datetime64[ns]'),
         'pay_date': array([], dtype='datetime64[ns]'),
     })
     writer.write(splits=empty, mergers=empty, dividends=empty_dividends)
     super(NullAdjustmentReader, self).__init__(conn)
Esempio n. 15
0
 def __init__(self):
     conn = sqlite3_connect(":memory:")
     writer = SQLiteAdjustmentWriter(conn, None, None)
     empty = DataFrame({
         "sid": array([], dtype=uint32),
         "effective_date": array([], dtype=uint32),
         "ratio": array([], dtype=float),
     })
     empty_dividends = DataFrame({
         "sid":
         array([], dtype=uint32),
         "amount":
         array([], dtype=float64),
         "record_date":
         array([], dtype="datetime64[ns]"),
         "ex_date":
         array([], dtype="datetime64[ns]"),
         "declared_date":
         array([], dtype="datetime64[ns]"),
         "pay_date":
         array([], dtype="datetime64[ns]"),
     })
     writer.write(splits=empty, mergers=empty, dividends=empty_dividends)
     super(NullAdjustmentReader, self).__init__(conn)
Esempio n. 16
0
def update_db(addon, home, enabled):

    # Check if the addon is in the db already and set the enable flag
    its_there = is_in_db(addon, home)
    en = 1 if enabled else 0

    # Open the addon database
    db = sqlite3_connect("%s/userdata/Database/Addons27.db" % (home))
    cursor = db.cursor()

    # Add the addon to the database if necessary, enabling it if requested
    if its_there:
        cursor.execute(
            "UPDATE installed SET enabled = %s WHERE addonID = '%s'"
            % (en, addon)
        )
    else:
        cursor.execute(
            "INSERT INTO installed select (MAX(id)+1),'%s',1,datetime(),NULL,NULL,'' FROM installed;"
            % (addon)
        )

    db.commit()
    db.close()
Esempio n. 17
0
#!/usr/bin/python
from flask import Blueprint, jsonify, request
from json import loads as json_decode
from functools import wraps
from hashlib import sha1
from sqlite3 import connect as sqlite3_connect
from re import match

hash = lambda x: sha1(x.encode('utf-8') + b'salt_is_salty').hexdigest()[10:30]
dbconn = lambda: sqlite3_connect('blog.db')

BlogService = Blueprint('blogservice', __name__)


def only_accept_json(f):
    @wraps(f)
    def decorated_function(*args, **kwargs):
        if request.accept_mimetypes.best_match(['application/json'
                                                ]) != 'application/json':
            return '', 406
        return f(*args, **kwargs)

    return decorated_function


def check_id_exists(f):
    @wraps(f)
    def decorated_function(*args, **kwargs):
        if '_id' not in kwargs or not kwargs['_id'].isdigit():
            return jsonify({'error': 1, 'message': 'invalid id'}), 400
        _id = int(kwargs['_id'])
Esempio n. 18
0
 def __init__(self, database_path):
     self._database_path = database_path
     self.lock = Lock()
     self.connection = sqlite3_connect(self._database_path,
                                       check_same_thread=False)
     self.init_table()
Esempio n. 19
0
    def __init__(self, appname):
        self.conn = sqlite3_connect("%s.db" % appname)
        self.cursor = self.conn.cursor()

        self.create_tables()
Esempio n. 20
0
    if os.path.isfile('folhapessoal.db') is True:
        break

print(
    "________________________________________________________________________________"
)
print(
    "Olá! \nA Pesquisa a pesquisa pode ser feita por Ente, CPF(sem pontuação) e nome. \nAbra o arquivo leia-me.txt para entender como funciona a consulta.  "
)
print(
    "________________________________________________________________________________\n"
)

while True:
    while True:
        db = sqlite3_connect('folhapessoal.db')  #abre base de dados
        cursor = db.cursor()
        criterio_pesquisa = input('Pesquisa: ')
        pergunta = criterio_pesquisa.replace(".", "").replace("-", "")
        pergunta = pergunta.strip()
        try:
            pergunta = str(int(pergunta))
            pass
        except:
            pass
        if len(pergunta) == 0: continue

        start_time = time_time()
        print()
        print("Pesquisando.... BASE MUNICIPAL E ESTADUAL")
        print()
Esempio n. 21
0
	def __init__(self, appname):
		self.conn = sqlite3_connect("%s.db" % appname)
		self.cursor = self.conn.cursor()

		self.create_tables()