def update(self, features, make_backup=True, **kwargs): """ Update database with features. features : str, iterable, FeatureDB instance If FeatureDB, all features will be used. If string, assume it's a filename of a GFF or GTF file. Otherwise, assume it's an iterable of Feature objects. The classes in gffutils.iterators may be helpful in this case. make_backup : bool If True, and the database you're about to update is a file on disk, makes a copy of the existing database and saves it with a .bak extension. Remaining kwargs are passed to create_db. """ if make_backup: if isinstance(self.dbfn, basestring): shutil.copy2(self.dbfn, self.dbfn + '.bak') # No matter what `features` came in as, convert to gffutils.Feature # instances. Since the tricky part -- attribute strings -- have been # parsed into dicts in a Feature, we no longer have to worry about # that. This also allows GTF features to be used to update a GFF # database, or vice versa. if isinstance(features, basestring): indb = create.create_db(features, intermediate, **kwargs) features = indb.all_features() if isinstance(features, FeatureDB): features = features.all_features() if self.dialect['fmt'] == 'gtf': if 'id_spec' not in kwargs: kwargs['id_spec'] = { 'gene': 'gene_id', 'transcript': 'transcript_id'} db = create._GTFDBCreator( data=features, dbfn=self.dbfn, dialect=self.dialect, **kwargs) elif self.dialect['fmt'] == 'gff3': if 'id_spec' not in kwargs: kwargs['id_spec'] = 'ID' db = create._GFFDBCreator( data=features, dbfn=self.dbfn, dialect=self.dialect, **kwargs) else: raise ValueError db._populate_from_lines(features) db._update_relations() db._finalize()
from logic import do_GET from create import create_db hostName = "localhost" hostPort = 9000 pgConn = None #pgConn = psycopg2.connect("dbname='simplestore' user='******' host='swan.v7f.eu' password='******'") class ThreadedHTTPServer(ThreadingMixIn, HTTPServer): """Handle requests in a separate thread.""" create_db(pgConn) class MyServer(BaseHTTPRequestHandler): def log_message(self, format, *args): return def do_GET(self): return do_GET(self, pgConn) myServer = ThreadedHTTPServer((hostName, hostPort), MyServer) print(time.asctime(), "Server Starts - %s:%s" % (hostName, hostPort)) try: myServer.serve_forever()
import sys import sqlite3 import psycopg2 from logic import do_GET from create import create_db hostName = "0.0.0.0" hostPort = 9000 conConfig = "dbname='simplestore' user='******' host='localhost' password='******'" pgConn = psycopg2.connect(conConfig) create_db(pgConn) class ThreadedHTTPServer(ThreadingMixIn, HTTPServer): """Handle requests in a separate thread.""" class MyServer(BaseHTTPRequestHandler): def log_message(self, format, *args): return def do_GET(self): global pgConn try: pgConn.isolation_level except psycopg2.OperationalError: pgConn = psycopg2.connect(conConfig) return do_GET(self, pgConn)
# install with python3 -m pip install PyMySQL from connection import connection from create import create_db from insert import insert_jovem, insert_carteira, insert_inep, insert_enem create_db(connection) insert_jovem(connection, "10097142441", "Otacilio Saraiva Maia Neto", "14/12/1996") insert_carteira(connection, "10097142441", "Dona Faker", "Seu Sumido", "Cesinha School", "*****@*****.**") insert_inep(connection, "10097142441", "1218721872128", "2017") # CPF MASCULINO Br Pub Single Rico 20 urbana 1tv 3pcs no_car 1 2 net tv po emprega banh trablh insert_enem(connection, "10097142441", "1218721872128", "2017", "M", 1, 1, 0, "Q", 20, "B", "A", "C", "D", "A", "B", "A", "A", "D", "C", "B", "A") # Guardar dados em memoria pra inserir de vez connection.close()