tools.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. # -*- coding: utf-8 -*-
  2. """
  3. Created on 2024-02-02
  4. ---------
  5. @summary: 工具类
  6. ---------
  7. @author: Lzz
  8. """
  9. import datetime
  10. import re
  11. import time
  12. import bson
  13. import requests
  14. import setting
  15. from log import logger
  16. def clean_title(title):
  17. if title:
  18. rule_list = [
  19. '\(\d{1,20}\)',
  20. '\[[\u4e00-\u9fa5]{1,9}\]',
  21. '【[\u4e00-\u9fa5]{1,9}】',
  22. ]
  23. for rule in rule_list:
  24. title = re.sub(rule, '', title)
  25. return title
  26. def get_proxy():
  27. url = setting.PROXY_API
  28. headers = {"Authorization": setting.PROXY_TOKEN}
  29. proxy = requests.get(url, headers=headers, timeout=10).json().get("data")
  30. logger.info("切换代理:{}".format(proxy))
  31. return proxy
  32. def int2long(param: int):
  33. """int 转换成 long """
  34. return bson.int64.Int64(param)
  35. def get_current_date(date_format="%Y-%m-%d %H:%M:%S"):
  36. return datetime.datetime.now().strftime(date_format)
  37. def date_to_timestamp(date, fmt="%Y-%m-%d %H:%M:%S"):
  38. """
  39. @summary:
  40. ---------
  41. @param date:将"2011-09-28 10:00:00"时间格式转化为时间戳
  42. @param fmt:时间格式
  43. ---------
  44. @result: 返回时间戳
  45. """
  46. if ":" in date:
  47. timestamp = time.mktime(time.strptime(date, fmt))
  48. else:
  49. timestamp = time.mktime(time.strptime(date, "%Y-%m-%d"))
  50. return int(timestamp)
  51. def get_today_of_day(day_offset=0):
  52. return str(datetime.date.today() + datetime.timedelta(days=day_offset))