main.py 706 B

1234567891011121314151617181920212223242526272829303132
  1. from fastapi import FastAPI
  2. import sys
  3. import os
  4. import dataset
  5. import requests
  6. db = dataset.connect('sqlite:////tmp/hhh.db')
  7. app = FastAPI()
  8. def check_db(domain_name):
  9. global db
  10. table=db['q_cache']
  11. table.insert({'domain_name':domain_name})
  12. # table.upsert({'query':domain_name},keys=['query'])
  13. db.commit()
  14. # db.query('select')
  15. @app.get("/domain/{domain_name}")
  16. async def test_domain(domain_name):
  17. check_db(domain_name)
  18. r = requests.get('https://data.similarweb.com/api/v1/data?domain='+domain_name)
  19. js=r.json()
  20. #https://data.similarweb.com/api/v1/data?domain=hhh.com.tw
  21. return {"item_id": js}
  22. @app.get("/")
  23. async def root():
  24. return {"message": "test"}