Beispiel #1
0
 def post(self, task_id):
     '''
     添加邮箱
     '''
     args = add_mail_parser.parse_args()
     Tasks.objects(id=task_id).update_one(push__mail_list=args['mail'])
     return {'msg': '添加成功'}
Beispiel #2
0
 def put(self, task_id):
     '''
     设置私信
     '''
     args = set_private_message_parser.parse_args()
     Tasks.objects(id=task_id).update(
         set__private_message=args['private_message'])
     return {'msg': '设置成功'}
Beispiel #3
0
 def post(self, task_id):
     '''
     添加爬取否定关键字
     '''
     args = spider_extra_keyword_parser.parse_args()
     Tasks.objects(id=task_id).update_one(
         push__spider_extra_keywords=args['extra_keyword'])
     return {'msg': '添加成功'}
Beispiel #4
0
 def post(self, task_id):
     '''
     添加爬取用户
     '''
     args = spider_user_parser.parse_args()
     Tasks.objects(id=task_id).update_one(
         push__spider_user_ids=args['user_id'])
     return {'msg': '添加成功'}
Beispiel #5
0
 def put(self, task_id):
     '''
     更新任务
     '''
     args = update_task_parser.parse_args()
     Tasks.objects(id=task_id).update_one(
         set__spider_interval=args['spider_interval'])
     Tasks.objects(id=task_id).update_one(
         set__switch_account_interval=args['switch_account_interval'])
     return {'msg': '更新成功'}
Beispiel #6
0
 def post(self, task_id):
     '''
     添加微博账号
     '''
     args = add_weibo_user_account_parser.parse_args()
     weibo_account = WeiboAccounts()
     weibo_account.account = args['account']
     weibo_account.password = args['password']
     Tasks.objects(id=task_id).update_one(
         push__weibo_accounts=weibo_account)
     return {'msg': '添加成功'}
Beispiel #7
0
    def get(self):
        '''
        获取用户列表
        '''
        users = Users.objects()
        users_list = []

        response_data = {}
        for user in users:
            user_json = {}
            user_json['user_id'] = str(user.id)
            user_json['phone'] = user.phone
            user_json['account'] = user.account
            user_json['create_at'] = user.create_at
            user_json['email'] = user.email
            user_json['device_code'] = user.device_code
            user_json['is_manager'] = user.is_manager
            user_json['task_id'] = user.task_id
            user_json['task'] = json.loads(
                Tasks.objects(id=user.task_id).first().to_json())
            if user.use_time == 0:
                user_json['use_time'] = ''
            else:
                user_json['use_time'] = time.strftime(
                    '%m/%d/%Y', time.localtime(user.use_time / 1000))
            users_list.append(user_json)
        response_data['draw'] = 1
        response_data['data'] = users_list
        return response_data
Beispiel #8
0
 def delete(self, task_id):
     '''
     删除邮箱
     '''
     args = add_mail_parser.parse_args()
     task = Tasks.objects(id=task_id).first()
     if task:
         task.mail_list.remove(args['mail'])
         task.update(set__mail_list=task.mail_list)
         return {'msg': '删除成功'}
     else:
         return {'error': '任务不存在'}, 400
Beispiel #9
0
 def delete(self, task_id):
     '''
     删除爬取否定关键字
     '''
     args = spider_extra_keyword_parser.parse_args()
     task = Tasks.objects(id=task_id).first()
     if task:
         task.spider_extra_keywords.remove(args['extra_keyword'])
         task.update(set__spider_extra_keywords=task.spider_extra_keywords)
         return {'msg': '删除成功'}
     else:
         return {'error': '任务不存在'}, 400
Beispiel #10
0
 def delete(self, task_id):
     '''
     删除微博账号
     '''
     args = delete_weibo_user_account_parser.parse_args()
     task = Tasks.objects(id=task_id).first()
     weibo_accounts = []
     if task:
         for account in task.weibo_accounts:
             if not account.account == args['account']:
                 weibo_accounts.append(account)
         task.update(set__weibo_accounts=weibo_accounts)
         return {'msg': '删除成功'}
     else:
         return {'error': '任务不存在'}, 400
Beispiel #11
0
 def get(self):
     '''
     获取任务
     '''
     args = get_task_parser.parse_args()
     task = Tasks.objects(belong_user_id=args['user_id']).first()
     if args['ignore_verify'] and args['ignore_verify'] == 1:
         return json.loads(task.to_json())
     else:
         if len(task.mail_list) == 0:
             return {'error': '至少填写一个邮箱'}, 400
         if len(task.spider_user_ids) == 0:
             return {'error': '至少填写一个爬取的微博用户id'}, 400
         if len(task.weibo_accounts) == 0:
             return {'error': '至少填写一个微博账号用于登录'}, 400
         return json.loads(task.to_json())
Beispiel #12
0
def make_default_task(user_id):
    task = Tasks()
    task.belong_user_id = user_id
    account = WeiboAccounts()
    account.account = '18855408432'
    account.password = '******'
    task.weibo_accounts = []
    task.weibo_accounts.append(account)
    task.spider_user_ids = ['5538536107', '1723931634']
    task.spider_keywords = ['无人', '自动无人']
    task.spider_extra_keywords = ['@', '还没', '网友']
    task.spider_interval = 13
    task.switch_account_interval = 7
    task.mail_list = ['*****@*****.**']
    task.private_message = '测试私信发送功能'
    task.save()
    Users.objects(id=task.belong_user_id).update_one(set__task_id=str(task.id))
    return task