コード例 #1
0
 def test_build_username_list(self):
     expected = ['Adam', 'Bernard', 'Charles']
     logs = [
         Log(username='******'),
         Log(username='******'),
         Log(username='******')
     ]
     actual = build_username_list(logs)
     self.assertEqual(actual, expected)
コード例 #2
0
    def post(self):
        json_data = request.get_json(force=True)
        if not json_data:
            return {'message': 'No input data provided'}, 400
        # Validate and deserialize input
        data, errors = category_schema.load(json_data)
        if errors:
            return errors, 422

        category = Category.query.filter_by(Name=json_data['Name']).first()
        if category is not None:
            return {'message': 'Category already exists'}, 409

        else:
            category = Category(Name=json_data['Name'])

            try:
                db.session.add(category)

                log = Log(ActionName=request.path,
                          Message=category.Name + " Category has been Added")
                db.session.add(log)
                db.session.commit()
                return {
                    'message':
                    'Category {} was created'.format(json_data['Name']),
                }
            except:
                return {'message': 'Something went wrong'}, 500
コード例 #3
0
ファイル: __init__.py プロジェクト: JensenQi/blog
 def open_connect():
     g.session = DBSession()
     g.session.add(
         Log(ip=request.remote_addr,
             url=request.url,
             create_time=datetime.now()))
     g.session.commit()
コード例 #4
0
def monitor_logs():
    """
    监听 kafka 区块数据,出现新数据时,从 web3 获取日志
    :return:
    """
    if not config.get('kafka', 'block_topic', fallback=None):
        logger_err.error('config.ini 中没有 block_topic 参数,退出 monitor_logs 任务')
        return
    elif not config.get('kafka', 'log_topic', fallback=None):
        logger_err.error('config.ini 中没有 log_topic 参数,退出 monitor_logs 任务')
        return
    consumer = kafka_consumer(config.get('kafka', 'block_topic'),
                              group_id='monitor_logs')
    for msg in consumer:
        block = msg.value
        logs = w3.eth.filter({
            'fromBlock': block['number'],
            'toBlock': block['number']
        }).get_all_entries()
        # 按交易聚合
        group = defaultdict(list)
        for log in logs:
            group[log.transactionHash].append(log)
        logger.info(
            f'区块高度 {block["number"]} 下共获得日志 {len(logs)} 条,按交易聚合得到日志 {len(group)} 组'
        )
        for g in group.values():
            Log(data=g).save()
コード例 #5
0
        def get_result():
            headers = request.getAllHeaders()
            content = cgi.FieldStorage(fp=request.content,
                                       headers=headers,
                                       environ={
                                           'REQUEST_METHOD': 'POST',
                                           'CONTENT_TYPE':
                                           headers['content-type'],
                                       })

            repo_uri = content['reponame'].value
            repo_base = config['cache']['repos']
            repo_json = os.path.join(repo_base, repo_uri, '%s.json' % repo_uri)
            if os.path.exists(repo_json):
                raise OSError("repo has already created.")

            if not os.path.exists(os.path.join(repo_base, repo_uri)):
                os.makedirs(os.path.join(repo_base, repo_uri))

            with open(repo_json, 'w') as fp:
                fp.write(content['config'].value)

            env = os.environ.copy()
            env['REPOPATH'] = repo_base
            env['NAME'] = repo_uri
            command = "../tools/repo.py create"
            status, _message = functions.getstatusoutput(command, env=env)
            if status == 0:
                message = "repo %s create succeed." % repo_uri
                Log(section='repository', message=message)
            else:
                message = "repo create failed. %s " % _message

            return {'status': status, 'message': message}
コード例 #6
0
ファイル: server.py プロジェクト: artfawl/Project_Bot
    def user_log(user_id, text):
        row = Log(user_id=user_id, text=text.strip(

        ), date=datetime.datetime.now().strftime("%Y-%m-%d "
                                                 "%H:%M:%S"))
        session.add(row)
        session.commit()
コード例 #7
0
    def post(self):
        form = RegisterUserForm()
        print 'enter registerview'
        if not form.validate_on_submit():
            return form.errors,422
        pwd = base64.decodestring(form.password.data)
        user = User(email = form.email.data, password = pwd,firstName = form.firstName.data, lastName = form.lastName.data, phone= form.phone.data,association = form.association.data)
        logentry = Log(datetime.datetime.utcnow(), 'Test door', user.firstName + ' ' + user.lastName, user.email, 'User registered ' + user.firstName + ' ' + user.lastName + ' ' + user.email , 'User registered', 'L1', 1, 'Web based')

        try:
            db.session.add(logentry)
            db.session.commit()
            db.session.add(user)
            db.session.commit()
        except IntegrityError:
            return make_response(jsonify({'error': 'eMail already registered'}), 400)

        # if activted send email
        if form.sendWelcomeMail.data != None:
            print 'sendWelcomeMail is ' + str(form.sendWelcomeMail.data)
            if form.sendWelcomeMail.data == 1:
                print 'try to send welcome mail'
                try:
                    send_email("Welcome to %s. You successfully registered" % 'RoseGuarden',
                                MAIL_USERNAME,
                                [user.email],
                                render_template("welcome_mail.txt",
                                user=user),
                                render_template("welcome_mail.html",
                                user=user))
                except:
                    print 'unable to send mail'
                    return '',201
        return '', 201
コード例 #8
0
    def post(self):
        form = DoorRegistrationForm()
        print 'Door registration request received'
        if not form.validate_on_submit():
            return form.errors,422

        if (g.user.role & 1) == 0:
            return make_response(jsonify({'error': 'Not authorized'}), 403)

        print 'Request door info from ' + 'http://' + form.address.data + ':5000' + '/request/doorinfo'
        try:
            response = requests.get('http://' + form.address.data + ':5000' + '/request/doorinfo', timeout=2)
        except:
            print "requested door unreachable"
            return 'requested door unreachable', 400

        print "create new door"
        response_data = json.loads(response.content)
        newDoor = Door(name = form.name.data, keyMask=response_data["keyMask"], address='http://' + form.address.data, local=0)
        logentry = Log(datetime.datetime.utcnow(), 'Test door', g.user.firstName + ' ' + g.user.lastName, g.user.email, 'Door ' + newDoor.name + ' on ' + newDoor.address + ' checked and registered', 'Door registered', 'L1', 1, 'Web based')
        try:
            db.session.add(logentry)
            db.session.commit()
            db.session.add(newDoor)
            db.session.commit()
            print "Added door to database"
        except IntegrityError:
            print "Problems to add door to database"
            return make_response(jsonify({'error': 'eMail already registered'}), 400)

        print "return new door data for request"
        return DoorSerializer(newDoor).data
コード例 #9
0
 def request(self, flow):
     self.l = Log()
     self.l.request_body = flow.request.get_text()
     self.l.method = flow.request.method
     self.l.url = flow.request.url
     self.l.request_headers = json.dumps(dict(flow.request.headers))
     self.l.save()
コード例 #10
0
def make_someone_sunday_absent():
    if not current_user.isSuperUser:
        abort(401)

    email = request.json['email']
    numberOfWeeks = int(request.json['numberOfWeeks'])

    if numberOfWeeks <= 0:
        abort(400)

    user = User.query.get(email)

    if not user:
        abort(404)

    """Insert a log"""
    description = 'User, ' + user.firstname + ' ' + user.lastname + ' (' + user.email + ') has been marked absent on Sundays by Admin for ' + str(numberOfWeeks) + ' weeks'
    log = Log(current_user.email, description)
    db.session.add(log)
    db.session.commit()

    user.futureSundayAbsentWeeks = 0
    user.isSundayAbsent = True
    user.sundayAbsentWeeks = numberOfWeeks
    db.session.commit()

    return "Success"
コード例 #11
0
def solve_order(request):
    rNumber = request.GET["rNumber"]
    ID = rNumber
    orderlist = Order.objects.filter(Receiver=rNumber, State="0")
    if "yes" in request.POST:
        post = request.POST
        sNumber = post["yes"]
        ord = Order.objects.filter(Sender=sNumber, Receiver=rNumber, State="0")
        for order in ord:
            order.State = "1"
            order.save()
            new_event = Log(
                Number=ID,
                Time=order.Time,
                Event=order.Event,
            )
            new_event.save()
            return HttpResponseRedirect("/search_event/?id=" + ID)
            break
    if "no" in request.POST:
        post = request.POST
        sNumber = post["no"]
        ord = Order.objects.filter(Sender=sNumber, Receiver=rNumber, State="0")
        for order in ord:
            order.State = "2"
            order.save()
            break
    return render_to_response(
        "solve_order.html",
        RequestContext(request, {
            "ID": ID,
            "orderlist": orderlist,
        }))
コード例 #12
0
def remove_sunday_absentee():
    if not current_user.isAdmin:
        abort(401)

    email = request.args.get('email')
    user = User.query.get(email)
    if not user:
        abort(404)

    user.isSundayAbsent = False
    user.sundayAbsentWeeks = 0
    user.futureSundayAbsentWeeks = 0
    db.session.commit()

    """Insert a log"""
    description = 'Deleted Sunday absentee - ' + user.firstname + ' ' + user.lastname
    log = Log(current_user.email, description)
    db.session.add(log)
    db.session.commit()

    super_user = User.query.filter_by(isSuperUser=True).first()

    """Send an email"""
    subject = 'Badminton: You are playing again on Sunday!!!'
    message = 'Hi,\r\n\nYou are removed from Sunday absents list by ' + current_user.firstname + ' ' + \
              current_user.lastname + '. From this point onwards you are assumed to be playing on Sundays ' + \
              'and you are charged for Sunday games. If you can\'t play in future please ' + \
              'register your absense using the badminton app.\r\n\n' + 'If you have any issues please contact ' + \
              super_user.firstname + ' ' + super_user.lastname + ' at: ' + super_user.email + \
              '\r\n\nThanks\r\nSydney Badminton Group'
    SendGrid.send_email(user.email, "*****@*****.**", subject, message)

    return "Success"
コード例 #13
0
def change_super_user():
    if not current_user.isSuperUser:
        abort(401)

    email = request.args.get('email')
    user = User.query.get(email)
    if not user:
        abort(404)

    """Make the current user not a super user"""
    current_user.isSuperUser = False

    """Make the selected user as new super user"""
    user.isGroupOwner = True
    user.isAdmin = True
    user.isSuperUser = True
    db.session.commit()

    """Insert a log"""
    description = 'Super user is changed to: ' + user.firstname + ' ' + user.lastname
    log = Log(current_user.email, description)
    db.session.add(log)
    db.session.commit()

    return "Success"
コード例 #14
0
ファイル: Item.py プロジェクト: YaserAlqasem/favorite-things
    def post(self):
        json_data = request.get_json(force=True)
        if not json_data:
            return {'message': 'No input data provided'}, 400
        # Validate and deserialize input
        data, errors = item_schema.load(json_data)
        if errors:
            return errors, 422

        item = Item.query.filter_by(Title=json_data['Title']).first()
        if item is not None:
            return {'message': 'Item already exists'}, 409

        else:
            item = Item(Title=json_data['Title'],
                        Description=json_data['Description'],
                        Ranking=json_data['Ranking'],
                        Category_id=json_data['Category_id'])

            try:
                db.session.add(item)

                log = Log(ActionName=request.path,
                          Message=item.Title + " Item has been Added")
                db.session.add(log)
                db.session.commit()
                return {
                    'message':
                    'Item {} was created'.format(json_data['Title']),
                }
            except:
                return {'message': 'Something went wrong'}, 500
コード例 #15
0
def want_to_play_on_sundays(email):
    user = User.query.get(email)

    if not user:
        abort(404)

    if user.group is not current_user.group:
        abort(404)

    if user.email is not email and not current_user.isGroupOwner:
        abort(401)

    user.isSundayAbsent = False
    user.sundayAbsentWeeks = 0
    user.futureSundayAbsentWeeks = 0
    db.session.commit()

    """"Insert a log"""
    description = 'Successfully registered wantToPlayOnSundays for user - ' + user.firstname + ' ' + user.lastname
    log = Log(current_user.email, description)
    db.session.add(log)
    db.session.commit()

    schema = UserSchema()
    json_result = schema.dumps(user)
    return json_result.data
コード例 #16
0
def cant_play_on_saturdays():
    email = request.json['email']
    weeks = int(request.json['weeks'])
    future = bool(request.json['future'])

    if weeks <= 0 or weeks > 520:
        abort(400)

    user = User.query.get(email)
    if not user:
        abort(404)

    if user.group is not current_user.group:
        abort(404)

    if user.email is not email and not current_user.isGroupOwner:
        abort(401)

    if future:
        user.futureSaturdayAbsentWeeks = weeks
    else:
        user.isSaturdayAbsent = True
        user.saturdayAbsentWeeks = weeks
    db.session.commit()

    """"Insert a log"""
    description = 'Successfully registered Saturday absence for - ' + str(weeks) + ' weeks' + \
        ' for user - ' + user.firstname + ' ' + user.lastname
    log = Log(current_user.email, description)
    db.session.add(log)
    db.session.commit()

    schema = UserSchema()
    json_result = schema.dumps(user)
    return json_result.data
コード例 #17
0
        def get_result():
            headers = request.getAllHeaders()
            content = cgi.FieldStorage(fp=request.content,
                                       headers=headers,
                                       environ={
                                           'REQUEST_METHOD': 'POST',
                                           'CONTENT_TYPE':
                                           headers['content-type'],
                                       })
            repo_base = config['cache']['repos']
            reponame = content['reponame'].value

            try:
                update_config = json.loads(eval(content['config'].value))
                repo_json = os.path.join(repo_base, reponame, '.update.json')
                with open(repo_json, 'w') as fp:
                    fp.write(json.dumps(update_config, indent=4))
                os.rename(repo_json,
                          os.path.join(repo_base, reponame, 'update.json'))
                Log(section='repository',
                    message='update %s json config' % reponame)
                return {'status': 0, 'message': 'update done'}

            except:
                return {'status': 1, 'message': 'update failed'}
コード例 #18
0
def adhoc_charge():
    if not current_user.isSuperUser:
        abort(401)

    amount = request.json['amount']
    subject = request.json['subject']
    message = request.json['message']

    users = User.query.order_by(User.firstname.asc()).all()
    cost_per_player = float("{0:.2f}".format(float(amount) / float(len(users))))

    """Add expense entry"""
    expense_entry = Expense(amount, cost_per_player, "Deduction_AdHoc", len(users))
    db.session.add(expense_entry)
    db.session.commit()

    email_ids = []
    for user in users:
        email_ids.append(user.email)
        user.balance = float("{0:.2f}".format(user.balance - cost_per_player))

        transaction = Transaction(user.email, cost_per_player, user.balance, "Deduct_AdHoc")
        db.session.add(transaction)
        db.session.commit()

    SendGrid.send_email(email_ids, "*****@*****.**", subject, message)

    """Insert a log"""
    description = 'An AdHoc amount of $' + str(amount) + ' is charged for reason: ' + subject
    log = Log(current_user.email, description)
    db.session.add(log)
    db.session.commit()
    return "Success"
コード例 #19
0
        def get_result():
            content = json.loads(request.content.read())
            repo_uri = content['reponame']
            division_name = content['division']
            base_repo = content['baserepo']

            repo_base = config['cache']['repos']
            repo_json = os.path.join(repo_base, repo_uri, '%s.json' % repo_uri)

            if not os.path.exists(repo_json):
                raise OSError("repo is not created.")
            repo_config = json.loads(open(repo_json, 'r').read())
            if not repo_config.get(base_repo):
                raise OSError("division repo is not supported.")

            env = os.environ.copy()
            env['REPOPATH'] = repo_base
            env['NAME'] = repo_uri

            command = "../tools/repo.py division --base %(base)s --division %(division)s" % {
                "base": base_repo,
                "division": division_name
            }
            Log(section='repository',
                message='create division reponame %s/%s' %
                (repo_uri, division_name))
            return dict(
                zip(['status', 'message'],
                    functions.getstatusoutput(command, env=env)))
コード例 #20
0
def api_task_new(*,
                 userid,
                 taskname,
                 taskcontent,
                 fileid=None,
                 deadline,
                 parentid=None):
    'new task and record in log'
    if not userid:
        raise APIValueError('userid')
    if not taskname or not taskname.strip():
        raise APIValueError('taskname')
    if not taskcontent or not taskcontent.strip():
        raise APIValueError('taskcontent')
    id = next_id()
    task = Task(id=id,
                userid=userid,
                taskname=taskname,
                taskcontent=taskcontent,
                deadline=deadline,
                fileid=fileid,
                parentid=parentid)
    affected = yield from task.save()
    id2 = next_id()
    logstr = '创建了任务(%s)' % taskname
    log = Log(id=id2, userid=userid, taskid=id, logcontent=logstr)
    affected2 = yield from log.save()
    id3 = next_id()
    member = Member(id=id3,
                    taskid=id,
                    memberid=userid,
                    userid=userid,
                    ismaster=True)
    affected3 = yield from member.save()
    if parentid:
        id4 = next_id()
        childlogstr = '创建了子任务(%s)' % taskname
        log = Log(id=id4,
                  userid=userid,
                  taskid=parentid,
                  logcontent=childlogstr)
        yield from log.save()
    return {
        'affected': affected,
        'logaffected': affected2,
        'memaffected': affected3
    }
コード例 #21
0
ファイル: test_log.py プロジェクト: connorwarnock/logbox
 def test_ingest(self):
     log_file_path = 'test/fixtures/example-1.log'
     log = Log(source='test_source', path=log_file_path)
     log.save()
     assert log.ingested == False
     log.ingest()
     assert log.ingested == True
     assert len(log.log_events) == 5
コード例 #22
0
def add_event(request):
    ID = request.GET["id"]
    if request.POST:
        post = request.POST
        new_event = Log(Number=ID, Time=post["time"], Event=post["event"])
        new_event.save()
        return HttpResponseRedirect("/search_event/?id=" + ID)
    return render_to_response("add_event.html")
コード例 #23
0
def log_message(d):
    # Takes input dictionary d and writes it to the Log table
    # Hint: use json.dumps or str() to get it in a nice string form
    time = datetime.now()
    log = Log(logtime=time, message=d)
    g.session.add(log)
    g.session.commit()
    pass
コード例 #24
0
def log_message(d):
    # Takes input dictionary d and writes it to the Log table
    order =  json.dumps(d)
    #log_obj = Log(sender_pk=order['sender_pk'],receiver_pk=order['receiver_pk'], \
    #          buy_currency=order['buy_currency'], sell_currency=order['sell_currency'], \
    #          buy_amount=order['buy_amount'], sell_amount=order['sell_amount'] )
    g.session.add(Log(message=order))
    g.session.commit()
  
    pass
コード例 #25
0
def api_log_new(*, userid, taskid, logcontent):
    'new log'
    if not userid:
        raise APIValueError('userid')
    if not taskid:
        raise APIValueError('taskid')
    id = next_id()
    log = Log(id=id, userid=userid, taskid=taskid, logcontent=logcontent)
    affected = yield from log.save()
    return {'affected': affected}
コード例 #26
0
 def post(self):
     # init models object
     custom_index_log = Log()
     custom_index_log.ip_address = self.request.remote_addr
     custom_index_log.alarm_id = self.request.get("SENSOR_ID")
     custom_index_log.alarm_status = self.request.get("SENSOR_STATUS")
     custom_index_log.alarm_count = self.request.get("SENSOR_COUNT")
     custom_index_log.put()
     self.response.headers['Content-Type'] = 'text/plain'
     self.response.write('return successful')
コード例 #27
0
 def parse_log_file(self, log_file):
     log = open(log_file, "r")
     next(log)
     logs = self.parse_log(log)
     pilots_logs = self.process_log(logs)
     pilots_data = map(lambda x: self.pilot_log_to_model(x),
                       pilots_logs.itervalues())
     pilots_data = self.compute_each_pilot_position(pilots_data)
     race_ended = self.check_if_any_pilot_completed_the_race(pilots_data)
     return Log(logs, pilots_data, race_ended)
コード例 #28
0
ファイル: index.py プロジェクト: Cl0udG0d/testAWD
def saveLog(username, password, ischeck):
    '''
    存储登录日志函数
    :param username:
    :param ischeck:
    :return:
    '''
    log = Log(username=username, password=password, ischeck=ischeck)
    db.session.add(log)
    db.session.commit()
コード例 #29
0
def demo_logs(dog, food, run, walk):
    from models import Log, ExerciseLog, FoodLog
    logs = Log.query.filter(Log.dog_id==dog.id).order_by(desc(Log._date)).all() or [None] * 10
    d = today
    index = 1
    weight = 25
    calories = randint(400, 600)
    for log in logs:
        daily_calories = round(getMER(weight, dog._metric))
        filename = 'Pluto' + str(index) + '.jpg'
        url = 'static/img/demo/' + filename
        thumbnail_url = 'static/img/demo/Pluto' + str(index) + '-thumbnail.jpg'
        if log is None:
            log = Log(d, dog.id, weight, daily_calories, calories, None, filename, url, thumbnail_url)

            db.session.add(log)
            db.session.commit()
        else:
            log._date = d
            log._weight = weight
            log._daily_calories = daily_calories
            log._calories = calories
            log._image_filename = filename
            log._image_url = url

        food_log = FoodLog.query.filter(FoodLog.food_id==food.id, FoodLog.log_id==log.id).first()
        if food_log is None:
            food_log = FoodLog(round((calories * food._serving) / food._calories, 1), food.id, log.id)
        db.session.add(food_log)

        duration = randint(10, 100)
        run_log = ExerciseLog.query.filter(ExerciseLog.exercise_id==run.id, ExerciseLog.log_id==log.id).first()
        if run_log is None:
            run_log = ExerciseLog(duration, run.id, log.id)
        db.session.add(run_log)
        db.session.commit()
        total_duration = duration

        duration = randint(10, 100)
        walk_log = ExerciseLog.query.filter(ExerciseLog.exercise_id==walk.id, ExerciseLog.log_id==log.id).first()
        if walk_log is None:
            walk_log = ExerciseLog(duration, walk.id, log.id)
        db.session.add(walk_log)
        db.session.commit()
        total_duration += duration

        log._total_duration = total_duration
        db.session.add(log)
        db.session.commit()
        logs[index - 1] = log
        d -= timedelta(days=1)
        weight += randint(-1, 1)
        index += 1
        calories += randint(10, 50)
    return logs
コード例 #30
0
    def append_to_log(self, request):
        if request['size'] is not None:
            request['size'] = int(request['size'])

        request['request_time'] = datetime.datetime.now()
        request['expiresAt'] = request['request_time'] + datetime.timedelta(
            weeks=1)
        request['real_sender'] = self.get_sender(request)

        logentry = Log(request)
        self.dbinsert(logentry)