main.py 927 B

1234567891011121314151617181920212223242526272829303132333435363738
  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. conn = rpyc.connect("192.168.192.119",12345)
  21. #domain_name
  22. jsdata=conn.root.get_url('https://data.similarweb.com/api/v1/data?domain='+domain_name)
  23. print(jsdata)
  24. jsdict=str(jsdata)[1:-1]
  25. table=db['similar']
  26. table.insert({'domain_name':domain_name,'json':jsdict,'dt':datetime.datetime.now()})
  27. db.commit()
  28. return jsdata
  29. # print(jsdata)
  30. # return {"item_id": domain_name}