users.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. # -*- coding: utf-8 -*-
  2. # @Author: wangkun
  3. # @Time: 2023/2/2
  4. """
  5. 创建虚拟站内 UID
  6. https://w42nne6hzg.feishu.cn/docx/PhbhdXScYo9CxpxTT3gcOle4nIs
  7. """
  8. import os
  9. import sys
  10. import requests
  11. sys.path.append(os.getcwd())
  12. from common.common import Common
  13. class Users:
  14. @classmethod
  15. def create_user(cls, log_type, crawler, user_dict, env):
  16. """
  17. 创建站内虚拟 UID
  18. :param log_type: 日志
  19. :param crawler: 哪款爬虫
  20. :param user_dict: 字典{'nickName': 用户名, 'avatarUrl': 头像, 'tagName': 站内用户标签}
  21. :param env: 环境
  22. :return: 站内 UID
  23. """
  24. try:
  25. if env == 'dev':
  26. # 外网
  27. url = 'http://videotest.yishihui.com/longvideoapi/user/virtual/crawler/registerVirtualUser'
  28. # 内网
  29. # url = 'http://videotest-internal.yishihui.com/longvideoapi/user/virtual/crawler/registerVirtualUser'
  30. elif env == 'prod':
  31. # 外网
  32. url = 'http://longvideoapi.piaoquantv.com/longvideoapi/user/virtual/crawler/registerVirtualUser'
  33. # 内网
  34. # url = 'http://longvideoapi-internal.piaoquantv.com/longvideoapi/user/virtual/crawler/registerVirtualUser'
  35. else:
  36. # 外网
  37. url = 'http://longvideoapi.piaoquantv.com/longvideoapi/user/virtual/crawler/registerVirtualUser'
  38. # 内网
  39. # url = 'http://longvideoapi-internal.piaoquantv.com/longvideoapi/user/virtual/crawler/registerVirtualUser'
  40. params = {
  41. # 'count': 1, # (必须)账号个数:传1
  42. # 'accountType': 4, # (必须)账号类型 :传 4 app虚拟账号
  43. 'pwd': '', # 密码 默认 12346
  44. 'nickName': user_dict['nickName'], # 昵称 默认 vuser......
  45. 'avatarUrl': user_dict['avatarUrl'], # 头像Url 默认 http://weapppiccdn.yishihui.com/resources/images/pic_normal.png
  46. 'tagName': user_dict['tagName'], # 多条数据用英文逗号分割
  47. }
  48. response = requests.post(url=url, params=params)
  49. # print(response.text)
  50. user_id = response.json()['data']
  51. return user_id
  52. except Exception as e:
  53. Common.logger(log_type, crawler).error(f"create_user异常:{e}\n")
  54. if __name__ == "__main__":
  55. uid = Users.create_user('log', 'kanyikan', 'youtube爬虫,定向爬虫策略', 'dev')
  56. print(uid)