示例#1
0
def action():
    if request.form.get('open'):
        open_door()
        call = Call(open=True, user_id=current_user.get_id())
    elif request.form.get('reject'):
        reject_knock()
        call = Call(open=False, user_id=current_user.get_id())
    db.session.add(call)
    db.session.commit()
    return redirect(url_for('index'))
示例#2
0
 def test_model_creation(self):
     u1 = User()
     l1 = Lead()
     c1 = Call()
     d1 = Donation()
     p1 = Pass()
     cb1 = Callback()
     self.assertTrue(True)
def check_files_in_dir():
    list_files = os.listdir(os.path.abspath('files'))
    if list_files:

        rate_gsm_for_minute = Rate.query.filter_by(
            type_connect='GSM').first().price_per_minute
        rate_cdma_for_minute = Rate.query.filter_by(
            type_connect='CDMA').first().price_per_minute
        rate_lte_for_minute = Rate.query.filter_by(
            type_connect='LTE').first().price_per_minute

        for file in list_files:
            if file[-4:] == 'json':
                with open(os.path.abspath('files') + '/' +
                          file) as file_handler:
                    line_list = file_handler.read().splitlines()
                    number_in, number_target, timestamp_start_call, timestamp_end_call, type_connect = line_list

                    dt_object_timestamp_start_call = datetime.fromtimestamp(
                        float(timestamp_start_call))
                    dt_object_timestamp_end_call = datetime.fromtimestamp(
                        float(timestamp_end_call))
                    count_minutes = (
                        dt_object_timestamp_end_call -
                        dt_object_timestamp_start_call).seconds / 60

                    if type_connect == 'GSM':
                        result_cost_call = int(count_minutes *
                                               rate_gsm_for_minute)
                    elif type_connect == 'CDMA':
                        result_cost_call = int(count_minutes *
                                               rate_cdma_for_minute)
                    elif type_connect == 'LTE':
                        result_cost_call = int(count_minutes *
                                               rate_lte_for_minute)
                    else:
                        result_cost_call = 0

                    add_call = Call(number_in=number_in,
                                    number_target=number_target,
                                    timestamp_start_call=timestamp_start_call,
                                    timestamp_end_call=timestamp_end_call,
                                    cost_call=result_cost_call)

                    db.session.add(add_call)
                    db.session.commit()

                os.remove(os.path.abspath('files') + '/' + file)
示例#4
0
def db_update(from_date, to_date, size=50):
    esi = ESIScraper(password='******')
    logger.info("scraper created...")
    esi._set_date_filters(fromdate=from_date, todate=to_date)
    count = esi.get_total_record_count()
    logger.info(
        'loading %s call(s) to the database', count)
    esi.set_page_size(count=size)
    data = esi.read_call_history_data()
    esi.quit()
    if len(data) > 0:
        for item in data:
            call = Call(
                from_name=item.caller_id,
                caller_phone=item.caller_num,
                dialed_phone=item.dialed_num,
                answer_phone=item.answer_num,
                timestamp=item.timestamp,
                duration=item.duration.seconds
            )
            call.save()
示例#5
0
def deploy():
    """Run deployment tasks."""
    if 'sqlite://' in app.config['SQLALCHEMY_DATABASE_URI']:
        path = Path(app.config['SQLALCHEMY_DATABASE_URI'][10:])
        if path.is_file():
            path.unlink()
    db.create_all()

    # insert sample data
    # this is part of olist's original requirements
    from app.models import Call
    source = '99988526423'
    destination = '9933468278'
    data = (
        (70, datetime(2016, 2, 29, 12, 0, 0), datetime(2016, 2, 29, 14, 0, 0)),
        (71, datetime(2017, 12, 11, 15, 7,
                      13), datetime(2017, 12, 11, 15, 14, 56)),
        (72, datetime(2017, 12, 12, 22, 47,
                      56), datetime(2017, 12, 12, 22, 50, 56)),
        (73, datetime(2017, 12, 12, 21, 57,
                      13), datetime(2017, 12, 12, 22, 10, 56)),
        (74, datetime(2017, 12, 12, 4, 57,
                      13), datetime(2017, 12, 12, 6, 10, 56)),
        (75, datetime(2017, 12, 13, 21, 57,
                      13), datetime(2017, 12, 14, 22, 10, 56)),
        (76, datetime(2017, 12, 12, 15, 7,
                      58), datetime(2017, 12, 12, 15, 12, 56)),
        (77, datetime(2018, 2, 28, 21, 57,
                      13), datetime(2018, 3, 1, 22, 10, 56)),
    )
    # bulk insert
    # ref: https://docs.sqlalchemy.org/en/latest/_modules/examples/performance/bulk_inserts.html
    db.session.add_all(
        Call(id=v[0],
             source=source,
             destination=destination,
             start_timestamp=v[1],
             end_timestamp=v[2]) for v in data)
    db.session.flush()
    db.session.commit()