def get(ident,tags,limit=8+1): category = hash(tags) % 0x7FFFFFFF arg = argbuilder() category = arg(category) stmt = Select(withtags.tagsWhat,InnerJoin( 'randomSeen',InnerJoin('media','things',EQ('things.id','media.id')), EQ('randomSeen.media','media.id')), AND( "seen", AND(EQ('randomSeen.category',category), "randomSeen.id <= "+arg(ident)))) stmt = Order(stmt,'randomSeen.id DESC') stmt = Limit(stmt,limit=limit) rows = db.execute(stmt.sql(),arg.args) #print('\n'.join(r[0] for r in rows)) #raise SystemExit return rows
def main(): recalculate() setup() note.magenta('got em yay') from orm import Select,With,AS,Limit,OuterJoin stmt = Select('id,hasTags,uniquelyIdentifies,(select path from filesources where id = thingy.id),(select uri from urisources where id=thingy.id) from thingy') #stmt = Limit(stmt,limit=10) stmt = With( stmt, thingy=((), Select('sources.id,hasTags,uniquelyIdentifies', OuterJoin( OuterJoin('sources', 'goodsources', 'sources.id = goodsources.id'), 'sourceProblems', 'sources.id = sourceProblems.id'), 'goodsources.id IS NULL AND sourceProblems.id IS NULL'))) stmt = stmt.sql() note.blue(stmt) def problem(ident,s): note.alarm('+++',ident,s) if ident is None: return db.execute('INSERT INTO sourceProblems (id,problem) VALUES ($1,$2)', (ident,s)) for id,hasTags,uniquelyIdentifies,path,uri in db.execute(stmt): print('---------------') note.blue(id) note.blue(path,uri) time.sleep(1)#input() if path and os.path.exists(path): note.green('found path',path) impmort(path,{'laptop','special:recovery'}) elif uri: if uri.startswith('file://'): path = uri[len('file://'):] note.green('uri path',path) if os.path.exists(path): impmort(path,{'laptop','special:recovery'}) else: id = problem(id,'bad file: uri') else: note.green('uri',uri) try: norm = normalize(uri) if uri != norm: id = problem(id,'denormalized uri: {}'.format(norm)) newid = db.execute('SELECT id FROM urisources where uri = $1',(norm,)) if newid: id = newid[0][0] else: id = None if hasTags and uniquelyIdentifies: parse(norm) elif not uniquelyIdentifies: id = problem(id,'not a unique source') else: id = problem(id,'no tags at this one') #recalculate() except ParseError as e: id = problem(id,str(e)) except urllib.error.HTTPError as e: id = problem(id,str(e)) except http.client.RemoteDisconnected as e: id = problem(id,str(e)) except NoGood as e: id = problem(id,str(e)) elif path: id = problem(id,'bad path') else: id = problem(id,'no path, and a bad uri')