gd_utils.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. # -*- coding: utf-8 -*-
  2. """
  3. Created on 2024-01-04
  4. ---------
  5. @summary: utils
  6. ---------
  7. @author: Lzz
  8. """
  9. from urllib import parse
  10. import execjs
  11. import requests
  12. from untils.tools import get_proxy
  13. def get_nodeId(params,proxies=False):
  14. proxy = proxies
  15. en_str = get_enstr(params)
  16. headers = {
  17. "Accept": "application/json, text/plain, */*",
  18. "Accept-Language": "zh-CN,zh;q=0.9",
  19. "Cache-Control": "no-cache",
  20. "Connection": "keep-alive",
  21. "Pragma": "no-cache",
  22. "Referer": "https://ygp.gdzwfw.gov.cn/ggzy-portal/",
  23. "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36",
  24. "X-Dgi-Req-App": en_str.get('X-Dgi-Req-App'),
  25. "X-Dgi-Req-Nonce": en_str.get('X-Dgi-Req-Nonce'),
  26. "X-Dgi-Req-Signature": en_str.get('X-Dgi-Req-Signature'),
  27. "X-Dgi-Req-Timestamp": en_str.get('X-Dgi-Req-Timestamp'),
  28. }
  29. url = "https://ygp.gdzwfw.gov.cn/ggzy-portal/center/apis/trading-notice/new/nodeList"
  30. retry = 0
  31. while retry < 3:
  32. try:
  33. res = requests.get(url, headers=headers, params=params, proxies=proxy, timeout=60, verify=False)
  34. nodeId_info = res.json().get('data')
  35. nodeId_dict = {}
  36. for nd in nodeId_info:
  37. dsList = nd.get('dsList')
  38. for i in dsList:
  39. for k, v in i.items():
  40. for child in v:
  41. nodeId_dict[child] = nd.get('nodeId')
  42. nodeId_dict[nd.get('noticeId')] = nd.get('nodeId')
  43. if nodeId_dict:
  44. break
  45. proxy = get_proxy()
  46. retry += 1
  47. except:
  48. retry += 1
  49. return nodeId_dict
  50. def get_enstr(data):
  51. p_list = []
  52. for key, value in data.items():
  53. if str(value) == "False":
  54. value = "false"
  55. p_list.append(f"{key}={value}")
  56. p_str = parse.quote("&".join(p_list), safe="&=")
  57. with open('./gdsggzyjypt_encrypt.js','r') as fr:
  58. ex_js = fr.read()
  59. ctx = execjs.compile(ex_js)
  60. pm = ctx.call('get_pm',p_str)
  61. return pm
  62. def create_href(data):
  63. with open('./gdsggzyjypt_encrypt.js','r') as fr:
  64. ex_js = fr.read()
  65. ctx = execjs.compile(ex_js)
  66. pm = ctx.call('create_href',data)
  67. return pm
  68. def deal_time(tm):
  69. if tm and len(tm) == 8:
  70. pbtime = tm[:4] + "-" + tm[4:6] + "-" + tm[6:8]
  71. elif tm and len(tm) == 14:
  72. pbtime = tm[:4] + "-" + tm[4:6] + "-" + tm[6:8] + " " + tm[8:10] + ":" + tm[10:12] + ":" + tm[12:]
  73. else:
  74. pbtime = tm
  75. return pbtime