request_cache.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #! /usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. # vim:fenc=utf-8
  4. """
  5. A simple tool to request remote to make cache
  6. """
  7. import json
  8. import time
  9. import requests
  10. from concurrent.futures.thread import ThreadPoolExecutor
  11. PLAN_ID = "20240813095121995118754"
  12. ACCOUNT_MAP = {
  13. "gh_6d205db62f04": "20231214075906052349516",
  14. "gh_0c89e11f8bf3": "20231214075715819462085"
  15. }
  16. SERVER_URL = "http://47.98.136.48:6060/score_list"
  17. def get_articles(plan_id, account_id):
  18. URL = 'http://aigc-api.cybertogether.net/aigc/publish/content/gzhWaitingPublishContent'
  19. headers={
  20. "Content-Type": "application/json;charset=UTF-8"
  21. }
  22. payload={
  23. "params": {
  24. "accountId": account_id,
  25. "planId": plan_id
  26. }
  27. }
  28. resp = requests.post(URL, headers=headers, json=payload)
  29. json_data = resp.json()
  30. content_titles = [x['title'].replace("'", "") for x in json_data['data']]
  31. return content_titles
  32. def score_list(server_url, titles, account_gh_id):
  33. account_id = ACCOUNT_MAP[account_gh_id]
  34. predefined_titles = [
  35. "在俄罗斯买好地了,却发现没有公路、码头、仓储、燃气管道……”",
  36. "被霸占15年后成功收回,岛礁资源超100万吨,曾遭到美菲联手抢夺",
  37. "感人!河南姐弟被父母遗弃,7岁弟弟带着姐姐看病:别怕,以后我养",
  38. "山东26岁女子产下罕见“4胞胎”,丈夫却突然消失,婆婆:养不起",
  39. "突然,中国资产大爆发!A50指数期货直线拉升超4.5%,港股大涨!人民币也涨了"
  40. ]
  41. t1 = time.time()
  42. body = {
  43. "gh_id_list": [account_gh_id],
  44. "text_list": titles,
  45. "max_time": None,
  46. "min_time": None,
  47. "interest_type": "avg",
  48. "sim_type": "avg",
  49. "rate": 0.1
  50. }
  51. response = requests.post(url=server_url, headers={}, json=body).json()
  52. t2 = time.time()
  53. print(json.dumps(response, ensure_ascii=False, indent=4))
  54. print(f"time: {t2 - t1:.4f}")
  55. return response
  56. if __name__ == '__main__':
  57. titles = get_articles(PLAN_ID, ACCOUNT_MAP['gh_6d205db62f04'])
  58. score_list(SERVER_URL, titles, 'gh_6d205db62f04')