1
0

main.py 1.4 KB

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