main.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. from fastapi.middleware.cors import CORSMiddleware
  10. db = dataset.connect('sqlite:///similar.db')
  11. app = FastAPI()
  12. origins = [
  13. "http://www.googo.org",
  14. "http://googo.org",
  15. "http://139.162.121.30"
  16. ]
  17. app.add_middleware(
  18. CORSMiddleware,
  19. allow_origins=origins,
  20. allow_credentials=True,
  21. allow_methods=["*"],
  22. allow_headers=["*"],
  23. )
  24. @app.get("/domain/{domain_name}")
  25. async def read_item(domain_name):
  26. cursor=db.query('select domain_name,json,dt from similar where domain_name="'+domain_name+'"')
  27. for c in cursor:
  28. print(c['json'])
  29. print(c['dt'])
  30. return c['json'][1:-1]
  31. print(domain_name)
  32. # conn = rpyc.connect("localhost",12345)
  33. conn = rpyc.connect("192.168.192.119",12345)
  34. #domain_name
  35. jsdata=conn.root.get_url('https://data.similarweb.com/api/v1/data?domain='+domain_name)
  36. print(jsdata)
  37. jsdict=str(jsdata)[1:-1]
  38. table=db['similar']
  39. table.insert({'domain_name':domain_name,'json':jsdict,'dt':datetime.datetime.now()})
  40. db.commit()
  41. return jsdata
  42. # print(jsdata)
  43. # return {"item_id": domain_name}