make_curl.py 668 B

1234567891011121314151617181920212223242526272829
  1. """
  2. Make a curl script for testing performance
  3. """
  4. import os
  5. from itertools import islice
  6. from urllib.parse import quote
  7. from paths import DATA_DIR
  8. from wiki import get_wiki_titles_and_urls
  9. URL_TEMPLATE = "http://localhost:8000/complete?q={}"
  10. CURL_FILE = os.path.join(DATA_DIR, "urls.curl")
  11. def get_urls():
  12. titles_and_urls = get_wiki_titles_and_urls()
  13. for title, url in islice(titles_and_urls, 100):
  14. query = quote(title.lower())
  15. yield URL_TEMPLATE.format(query)
  16. def run():
  17. with open(CURL_FILE, 'wt') as output_file:
  18. for url in get_urls():
  19. output_file.write(f'url="{url}"\n')
  20. if __name__ == '__main__':
  21. run()