def getCols(x): sql = 'select name from booksfull_fields where name like \'%' + x + '%\'' fields = sqlite.sql(db, sql) af = [] for f in fields: #print f af.append(f['name']) return af
def getCols(x): db = 'books2.sqlite' table = 'booksfull' '''selecciona las columnas ocn uncontenido x''' sql = 'select name from booksfull_fields where name like \'%' + x + '%\'' fields = sqlite.sql(db, sql) af = [] for f in fields: #print f af.append(f['name']) return af
for ll in l: m.append(len(ll)) mm = max(m) i = m.index(mm) return l[i] def gfd(d): m = [] for dd in d: print dd if dd['@language'] == 'en': return dd['@value'] books = sqlite.sql(db, 'select rowid, description as d from booksfull') authors = [] for b in books: row = b['rowid'] print row if b['d'][0:6] != '<html>': des = eval(b['d']) for d in des['@graph']: #print d if d.get('@type') == 'schema:Person': d['id'] = d.pop('@id') d['type'] = d.pop('@type') for dd in d: if type(d[dd]) is list: if type(d[dd][0]) is dict:
def __init__(self, model=None): self.baseModel = model self.relation = self.loadConf(model) self.baseRelation = self.loadConf() self.conn = sql().getConn() self.cur = self.conn.cursor()
import sqlite db = 'authors2.sqlite' table = 'authors' row = sqlite.sql(db, 'select * from authors') au = [] for r in row: if r['autor'] is not None: autors = r['autor'].split('|') for a in autors: a.strip(' ') a = 'http://' + a au.append({'autor': a, 'tipo': r['tipo'], 'name': None}) sqlite.dict2sqlite(db, 'autores_c', au) ''' --luego ejecutar esto para coger los valores unicos create table autores_c2 as SELECT distinct "autor", "tipo", "name" FROM autores_c ORDER BY ROWID --luego update autores_c2 set name = (select name from a.persons where persons.id like autores_c2.autor group by persons.name) limit 100 '''
sql += 'select %s as autor, \'%s\' as tipo from booksfull ' % (a, 'authors') sql += ' union ' for a in creators: sql += 'select %s, \'%s\' from booksfull ' % (a, 'creators') sql += ' union ' for a in contri: sql += 'select %s, \'%s\' from booksfull ' % (a, 'contri') sql += ' union ' for a in illus: sql += 'select %s, \'%s\' from booksfull ' % (a, 'illus') sql += ' union ' sql = sql[0:-6] print sql autores = sqlite.sql(db, sql) sqlite.dict2sqlite('authors2.sqlite', 'authors', autores) ## ahora toca navegar en cada link y buscar su viaf o su denominacion unica para encontrar a los unicos ''' select schema__Book_author, schema__CreativeWork_author, schema__Person_name from booksfull schema__book_creator schema__creativework_creator select rowid, schema__book_creator, schema__creativework_illustrator, schema__book_illustrator, schema__creativework_creator,
import utils import sqlite db = 'books2.sqlite' table = 'booksfull' ''' editor placeOfPublication publication publisher ''' cols = utils.getCols('publication') for c in cols: print c ed = sqlite.sql( db, "select schema__PublicationEvent_type from booksfull where auth like '%cervantes%'" ) for e in ed: print e
import sqlite db = 'books2.sqlite' table = 'booksfull' sql = 'select name from booksfull_fields where name like \'%schema%\'' fields = sqlite.sql(db, sql) af = [] for f in fields: af.append(f['name']) sql = 'select %s from booksfull' %(', '.join(af)) print sql