main.py 876 B

123456789101112131415161718192021222324252627282930313233343536
  1. import rpyc
  2. import time
  3. from fastapi import FastAPI
  4. import sys
  5. import os
  6. import dataset
  7. import datetime
  8. import json
  9. db = dataset.connect('sqlite:///similar.db')
  10. app = FastAPI()
  11. @app.get("/domain/{domain_name}")
  12. async def read_item(domain_name):
  13. cursor=db.query('select domain_name,json,dt from similar where domain_name="'+domain_name+'"')
  14. for c in cursor:
  15. print(c['json'])
  16. print(c['dt'])
  17. return c['json'][1:-1]
  18. print(domain_name)
  19. conn = rpyc.connect("localhost",12345)
  20. #domain_name
  21. jsdata=conn.root.get_url('https://data.similarweb.com/api/v1/data?domain='+domain_name)
  22. print(jsdata)
  23. jsdict=str(jsdata)[1:-1]
  24. table=db['similar']
  25. table.insert({'domain_name':domain_name,'json':jsdict,'dt':datetime.datetime.now()})
  26. db.commit()
  27. return jsdata
  28. # print(jsdata)
  29. # return {"item_id": domain_name}