import rpyc import time from fastapi import FastAPI import sys import os import dataset import datetime import json import ast from fastapi.responses import JSONResponse from fastapi.middleware.cors import CORSMiddleware db = dataset.connect('sqlite:///similar.db') app = FastAPI() origins = [ "http://www.googo.org", "http://www.googo.org:8080", "http://googo.org:8080", "http://googo.org", "http://139.162.121.30" ] app.add_middleware( CORSMiddleware, allow_origins=origins, allow_credentials=True, allow_methods=["*"], allow_headers=["*"], ) @app.get("/query/{qq}") async def query(qq): print(qq) return JSONResponse(content={'query':qq}) @app.get("/domain/{domain_name}") async def read_item(domain_name): cursor=db.query('select domain_name,json,dt from similar where domain_name="'+domain_name+'"') for c in cursor: print(c['json']) print(c['dt']) # jsdict=ast.literal_eval(c['json']) jsdict=json.loads(c['json']) return JSONResponse(content=jsdict) print(domain_name) # conn = rpyc.connect("localhost",12345) conn = rpyc.connect("192.168.192.119",12345) #domain_name jsdata=conn.root.get_url('https://data.similarweb.com/api/v1/data?domain='+domain_name) print(jsdata) # jsdict=str(jsdata)[1:-1] # jsdict=json.loads(str(jsdata)) jsdict=ast.literal_eval(str(jsdata)) # jsdict=str(jsdata) table=db['similar'] jstr=json.dumps(jsdict) table.insert({'domain_name':domain_name,'json':jstr,'dt':datetime.datetime.now()}) db.commit() return JSONResponse(content=jsdict) # print(jsdata) # return {"item_id": domain_name}