def getCreatedSameDay(index, editor, nid): stamp = utility.misc.get_milisec_stamp() index.output.latest = stamp index.lastSearch = (nid, None, "createdSameDay") try: nidMinusOneDay = nid - (24 * 60 * 60 * 1000) nidPlusOneDay = nid + (24 * 60 * 60 * 1000) res = mw.col.db.execute( "select distinct notes.id, flds, tags, did, mid from notes left join cards on notes.id = cards.nid where nid > %s and nid < %s order by nid desc" % (nidMinusOneDay, nidPlusOneDay)).fetchall() dayOfNote = int(time.strftime("%d", time.localtime(nid / 1000))) rList = [] c = 0 for r in res: dayCreated = int( time.strftime("%d", time.localtime(int(r[0]) / 1000))) if dayCreated != dayOfNote: continue if not str(r[0]) in index.pinned: rList.append((r[1], r[2], r[3], r[0], 1, r[4], "")) c += 1 if c >= index.limit: break if check_index(): if len(rList) > 0: index.output.print_search_results(rList, stamp, editor) else: index.output.empty_result("No results found.") except: if check_index(): index.output.empty_result("Error in calculation.")
def getLastModifiedNotes(index, editor, decks, limit): stamp = utility.misc.get_milisec_stamp() index.output.latest = stamp index.lastSearch = (None, decks, "lastModified") if not "-1" in decks and len(decks) > 0: deckQ = "(%s)" % ",".join(decks) else: deckQ = "" if len(deckQ) > 0: res = mw.col.db.execute( "select distinct notes.id, flds, tags, did, notes.mid, notes.mod from notes left join cards on notes.id = cards.nid where did in %s order by notes.mod desc limit %s" % (deckQ, limit)).fetchall() else: res = mw.col.db.execute( "select distinct notes.id, flds, tags, did, notes.mid, notes.mod from notes left join cards on notes.id = cards.nid order by notes.mod desc limit %s" % (limit)).fetchall() rList = [] for r in res: if not str(r[0]) in index.pinned: rList.append((r[1], r[2], r[3], r[0], 1, r[4], "")) if check_index(): if len(rList) > 0: index.output.print_search_results(rList, stamp, editor) else: index.output.empty_result("No results found.")
def getCreatedNotesOrderedByDate(index, editor, decks, limit, sortOrder): stamp = utility.misc.get_milisec_stamp() index.output.latest = stamp if sortOrder == "desc": index.lastSearch = (None, decks, "lastCreated", limit) else: index.lastSearch = (None, decks, "firstCreated", limit) if not "-1" in decks and len(decks) > 0: deckQ = "(%s)" % ",".join(decks) else: deckQ = "" if len(deckQ) > 0: res = mw.col.db.execute( "select distinct notes.id, flds, tags, did, mid from notes left join cards on notes.id = cards.nid where did in %s order by nid %s limit %s" % (deckQ, sortOrder, limit)).fetchall() else: res = mw.col.db.execute( "select distinct notes.id, flds, tags, did, mid from notes left join cards on notes.id = cards.nid order by nid %s limit %s" % (sortOrder, limit)).fetchall() rList = [] for r in res: #pinned items should not appear in the results if not str(r[0]) in index.pinned: #todo get refs rList.append((r[1], r[2], r[3], r[0], 1, r[4], "")) if check_index(): if len(rList) > 0: index.output.print_search_results(rList, stamp, editor) else: index.output.empty_result("No results found.")