123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- # -*- coding: utf-8 -*-
- # @Author: wangkun
- # @Time: 2023/2/2
- """
- 创建虚拟站内 UID
- https://w42nne6hzg.feishu.cn/docx/PhbhdXScYo9CxpxTT3gcOle4nIs
- """
- import os
- import sys
- import requests
- sys.path.append(os.getcwd())
- from common.common import Common
- class Users:
- @classmethod
- def create_user(cls, log_type, crawler, user_dict, env):
- """
- 创建站内虚拟 UID
- :param log_type: 日志
- :param crawler: 哪款爬虫
- :param user_dict: 字典{'nickName': 用户名, 'avatarUrl': 头像, 'tagName': 站内用户标签}
- :param env: 环境
- :return: 站内 UID
- """
- try:
- if env == 'dev':
- # 外网
- url = 'http://videotest.yishihui.com/longvideoapi/user/virtual/crawler/registerVirtualUser'
- # 内网
- # url = 'http://videotest-internal.yishihui.com/longvideoapi/user/virtual/crawler/registerVirtualUser'
- elif env == 'prod':
- # 外网
- url = 'http://longvideoapi.piaoquantv.com/longvideoapi/user/virtual/crawler/registerVirtualUser'
- # 内网
- # url = 'http://longvideoapi-internal.piaoquantv.com/longvideoapi/user/virtual/crawler/registerVirtualUser'
- else:
- # 外网
- url = 'http://longvideoapi.piaoquantv.com/longvideoapi/user/virtual/crawler/registerVirtualUser'
- # 内网
- # url = 'http://longvideoapi-internal.piaoquantv.com/longvideoapi/user/virtual/crawler/registerVirtualUser'
- params = {
- # 'count': 1, # (必须)账号个数:传1
- # 'accountType': 4, # (必须)账号类型 :传 4 app虚拟账号
- 'pwd': '', # 密码 默认 12346
- 'nickName': user_dict['nickName'], # 昵称 默认 vuser......
- 'avatarUrl': user_dict['avatarUrl'], # 头像Url 默认 http://weapppiccdn.yishihui.com/resources/images/pic_normal.png
- 'tagName': user_dict['tagName'], # 多条数据用英文逗号分割
- }
- response = requests.post(url=url, params=params)
- # print(response.text)
- user_id = response.json()['data']
- return user_id
- except Exception as e:
- Common.logger(log_type, crawler).error(f"create_user异常:{e}\n")
- if __name__ == "__main__":
- uid = Users.create_user('log', 'kanyikan', 'youtube爬虫,定向爬虫策略', 'dev')
- print(uid)
|