def runTasks(inputList):
    try:
        print "Start Script"
        for i in xrange(int(inputList[0])):
            startDate, endDate = getStartEndDate()
            userName, userId = getUser()
            tz = getTZ()
            obj = User(userId=userId, userName=userName, tz=tz)
            obj.save()
            obj.activityperiod_set.create(startTime=startDate, endTime=endDate)
    except Exception as E:
        print E
        logger.info(str(E))
Пример #2
0
 def post(self, request):
     status, response_data = UtilityMethods.get_default_response()
     u_fields = User.FieldNames
     required_fields = [u_fields.contact_number]
     try:
         received_data = UtilityMethods.get_required_data(
             required_fields, request.data)
         user = User.objects.filter(
             contact_number=received_data[u_fields.contact_number])
         if user.exists():
             data = {
                 UtilityMethods.SUCCESS_KEY: True,
                 'user_type': user[0].user_type,
                 'contact_number': user[0].contact_number,
                 'first_name': user[0].first_name,
                 'last_name': user[0].last_name,
                 'email': user[0].email
             }
         else:
             raise User.DoesNotExist()
     except User.DoesNotExist:
         data = {UtilityMethods.ERROR_KEY: 'Wrong Contact/Password'}
     except DataValidationError as e:
         data = {UtilityMethods.ERROR_KEY: e.args[1]}
     return Response(data=data, status=status)
Пример #3
0
 def post(self, request):
     status, response_data = UtilityMethods.get_default_response()
     u_fields = User.FieldNames
     required_fields = [
         u_fields.contact_number, u_fields.first_name, u_fields.last_name,
         u_fields.email
     ]
     try:
         received_data = UtilityMethods.get_required_data(
             required_fields, request.data)
         user = User.objects.filter(
             contact_number=received_data[u_fields.contact_number])
         if user.exists():
             cno = received_data[u_fields.contact_number]
             fname = received_data[u_fields.first_name]
             lname = received_data[u_fields.last_name]
             email1 = received_data[u_fields.email]
             user1 = User.objects.filter(contact_number=received_data[
                 u_fields.contact_number]).update(first_name=fname,
                                                  last_name=lname,
                                                  email=email1)
             data = {
                 UtilityMethods.SUCCESS_KEY: True,
             }
         else:
             raise User.DoesNotExist()
     except User.DoesNotExist:
         data = {UtilityMethods.ERROR_KEY: 'Wrong Contact/Password'}
     except DataValidationError as e:
         data = {UtilityMethods.ERROR_KEY: e.args[1]}
     return Response(data=data, status=status)
Пример #4
0
    def get(self):
        # all cases
        cases = Case.query.all()
        user_id = User.find_by_login(get_jwt_identity()).id

        return {
            'cases': [case.json_with_cooldown(user_id) for case in cases]
        }, 200
Пример #5
0
    def get(self, case_id):
        user_id = User.find_by_login(get_jwt_identity()).id

        case = Case.query.get(case_id)
        if case is None:
            return {"error": "Case doen't exists"}

        items = Item.query.filter_by(case_id=case_id)
        items = items_schema.dump(items).data

        return {'case': case.json_with_cooldown(user_id), 'items': items}, 200
Пример #6
0
    def patch(self, item_id):
        user_id = User.find_by_login(get_jwt_identity()).id
        item = Inventory.query.get(item_id)
        if not item or item.user_id != user_id:
            return {'message': 'No item inside inventory'}, 400

        if item.code is not None:
            return {'message': 'Item already activated'}, 400

        # create code and expiration for item
        response = item.activate()

        return response, 200
Пример #7
0
class CaseOpen(Resource):
    @jwt_required
    def post(self, case_id):
        # check case existence
        case = Case.query.get(case_id)
        if not case:
            return {'error': "Case doesn't exists"}, 400

        user_login = get_jwt_identity()
        user_id = User.find_by_login(login=user_login).id

        # check case cooldown
        case_cooldown = CaseCooldown.query.filter_by(case_id=case_id,
                                                     user_id=user_id).first()
        if case_cooldown is not None:
            if case_cooldown.is_cooled_down:
                db.session.delete(case_cooldown)
            else:
                return {'error': "Case isn't cooled down"}, 400

        items = Item.query.filter_by(case_id=case_id)
        items = [item for item in items]
        p_distr = [item.probability for item in items]

        reward = choices(population=items, weights=p_distr)[0]

        # create new item
        inv = Inventory(user_id=user_id, item_id=reward.id)
        db.session.add(inv)

        # case cool down after opening
        case_cooldown = CaseCooldown(user_id=user_id, case_id=case_id)
        db.session.add(case_cooldown)

        db.session.commit()

        reward = item_schema.dump(reward).data

        return {'id': inv.id, 'item': reward}, 201
Пример #8
0
    def get(self):
        user = User.find_by_login(get_jwt_identity())
        user_info = user_schema.dump(user).data

        return {'user_info': user_info}, 200