def index(self): from UHE.user.models import User, UserData import datetime now = datetime.datetime.now() data = {} data['active_user'] = User.objects(activated=True).count() data['login_last_ten'] = User.objects( last_login__gte=now - datetime.timedelta(minutes=10)).count() data['active_user_daily'] = User.objects( last_login__gte=datetime.datetime(now.year, now.month, now.day)).count() data['pending'] = UserData.objects(status='pending').count() data['success'] = UserData.objects(status='success').count() data['failed'] = UserData.objects(status='failed').count() return self.render('analytics_index.html', data=data)
def get_data(card_id, password): user_data = UserData.objects(user=card_id, identifier=__plugin__).first() user_data.status = 'pending' user_data.save() try: client = Fin(card_id, password) client.login() client.get_data() except Exception as e: user_data.status = 'failed' user_data.save() print('error') raise e user_data.data = client.to_json() user_data.status = 'success' user_data.last_modified = datetime.datetime.now() user_data.lock_save(password)
def get_course(card_id, password): user_data = UserData.objects(user=card_id, identifier=__plugin__).first() user_data.status = 'pending' user_data.save() try: client = XK(card_id, password) client.captcha = captcha_solver.create(client.captcha_img, site='XK')['Result'] client.login() client.get_data() except Exception as e: user_data.status = 'failed' user_data.save() print('error') raise e user_data.data = client.to_json() user_data.status = 'success' user_data.last_modified = datetime.datetime.now() user_data.lock_save(password)
def index(): if request.method == 'GET': data = UserData.objects(user=current_user.id, identifier=__plugin__).get_or_404() return jsonify(data) else: post_data = request.get_json() user_data = UserData.objects(user=current_user.id, identifier=__plugin__).first() if user_data is None: user_data = UserData(identifier=__plugin__, user=current_user.id, status='none') user_data.save() task = get_course.delay(post_data['card_id'], post_data['password']) return jsonify(success=task.id)
def sync_index(): if request.method == 'GET': data = UserData.objects(user=current_user.id, identifier=__plugin__).get_or_404() return jsonify(data) else: post_data = request.get_json() user_data = UserData.objects(user=current_user.id, identifier=__plugin__).first() if user_data is None: user_data = UserData(identifier=__plugin__, user=current_user.id, status='none') user_data.save() else: if user_data.status == 'pending': return jsonify(status='pending') task = get_course(current_user.id, post_data['password']) return jsonify(success='ok')
def status(): data = UserData.objects(user=current_user.id, identifier=__plugin__).get_or_404() return jsonify(status=data.status)