Example #1
0
 def get_archived_graph_data(lookup_id):
     '''get json repr of old graph'''
     query = "SELECT domain, node_depth, node_id, parent_node, url, found FROM Graph_Data WHERE lookup_id=?"
     conn = lite.connect(DbSessionFactory.get_db_file_path())
     df = pd.read_sql_query(query, conn, params=(lookup_id, ))
     conn.close()
     if len(df) > 1:
         graph = build_json_graph(df)
         return json.dumps(graph)
     # if graph only had one node, build with seed url
     else:
         graph = json.dumps(
             dict(url=df['url'].values[0], domain=df['domain'].values[0]))
         return graph
Example #2
0
 def get_history(user_id):
     ''' query the history to build search history view for returning users'''
     query = "SELECT auto_id, url, search_type, search_limit, keyword, created FROM History WHERE user_id=?"
     conn = lite.connect(DbSessionFactory.get_db_file_path())
     df = pd.read_sql_query(query, conn, params=(user_id, ))
     conn.close()
     history_dict_list = list()
     for i, r in df.iterrows():
         history_dict_list.append(
             dict(auto_id=r['auto_id'],
                  url=r['url'],
                  search_type=r['search_type'],
                  search_limit=r['search_limit'],
                  keyword=r['keyword'],
                  created=r['created']))
     return history_dict_list
Example #3
0
 def add_data(dataframe):
     '''add graph data to database for future query'''
     conn = lite.connect(DbSessionFactory.get_db_file_path())
     dataframe.to_sql('Graph_Data', conn, if_exists='append', index=False)
     conn.close()