12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- import rpyc
- import time
- from fastapi import FastAPI
- import sys
- import os
- import dataset
- import datetime
- import json
- from fastapi.middleware.cors import CORSMiddleware
- db = dataset.connect('sqlite:///similar.db')
- app = FastAPI()
- origins = [
- "http://www.googo.org",
- "http://googo.org",
- "http://139.162.121.30"
- ]
- app.add_middleware(
- CORSMiddleware,
- allow_origins=origins,
- allow_credentials=True,
- allow_methods=["*"],
- allow_headers=["*"],
- )
- @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'])
- return c['json'][1:-1]
- 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]
- table=db['similar']
- table.insert({'domain_name':domain_name,'json':jsdict,'dt':datetime.datetime.now()})
- db.commit()
- return jsdata
- # print(jsdata)
- # return {"item_id": domain_name}
|