Exemplo n.º 1
0
 def get(self, name):
     """returns a specified donkey query"""
     try:
         query = self.rd_conn.hmget("library:%s" % name, ["params", "description", "saved", "query"])
         params = eval(query[0] or "[]")
         description = query[1]
         date_saved = str(datetime.fromtimestamp(float(query[2])))
         qry = grabber.comp(query[3], un=True)
         query = {
             "name": name,
             "description": description,
             "required parameters": params,
             "query": qry,
             "saved at": date_saved,
         }
         return query
     except Exception as e:
         print e
         raise e
Exemplo n.º 2
0
 def search(self, name=None):
     """searches the query library for a given term"""
     if name:
         keys = filter(lambda x: name in x.replace("library:", ""), self.rd_conn.keys("library:*"))
     else:
         keys = self.rd_conn.keys("library:*")
     results = []
     for i in keys:
         query = self.rd_conn.hmget(i, ["params", "description", "saved", "query"])
         params = eval(query[0])
         description = query[1]
         date_saved = str(datetime.fromtimestamp(float(query[2])))
         qry = grabber.comp(query[3], un=True)
         res = {
             "name": i.replace("library:", ""),
             "description": description,
             "required parameters": params,
             "query": qry,
             "saved at": date_saved,
         }
         results.append(res)
     return results
Exemplo n.º 3
0
 def save(self, query, parameters, name, description):
     """saves the query to th library"""
     to_save = {"params": parameters, "description": description, "saved": time.time(), "query": grabber.comp(query)}
     self.rd_conn.hmset("library:%s" % name, to_save)
     return "query saved successfully"