Exemple #1
0
def extract_text():
    body = app.current_request.json_body
    if file_exist_bucket(body['document_name']):
        plain_str = extract_text_textract(body)
        return custom_responses.post_response(plain_str)
    else:
        return custom_responses.post_response(None)
Exemple #2
0
def upload_to_s3(file_name):
    body = app.current_request.raw_body
    logger.info('Uploading document')
    objs = upload_document_s3(body, file_name)
    if len(objs) > 0 and objs[0].key == file_name:
        public_url = f'{BUCKET_PREFIX}/{BUCKET_NAME}/{file_name}'
        logger.info(f'Document successfully saved in {public_url}')
        return custom_responses.post_response(public_url)
    else:
        logger.error('Document could not be saved')
        return custom_responses.post_response(None)
Exemple #3
0
def sms_message():
    body = app.current_request.json_body
    if body['secret_key'] == SECRET_KEY:
        sns = boto3.client('sns')
        sns.publish(
            Subject='OpenEduGT',
            PhoneNumber="+502" + body['number'],
            Message=body['message'][:160],
            MessageAttributes = {'AWS.SNS.SMS.SenderID': {'DataType': 'String', 'StringValue': 'OpenEduGT'},
                             'AWS.SNS.SMS.SMSType': {'DataType': 'String', 'StringValue': 'Promotional'}}
        )
        print('Sending message to: ' + '+502' + body['number'] + 'message: ' + body['message'][:160])
        return custom_responses.post_response(body['message'])
    else:
        return custom_responses.post_response(None)
Exemple #4
0
def upload_to_s3(file_name):
    body = app.current_request.raw_body
    logger.info('Uploading image')
    tmp_file_name = '/tmp/' + file_name
    with open(tmp_file_name, 'wb') as tmp_file:
        tmp_file.write(body)

    s3_client, bucket = get_s3_resources()
    s3_client.upload_file(tmp_file_name, BUCKET_NAME, file_name)

    objs = list(bucket.objects.filter(Prefix=file_name))
    if len(objs) > 0 and objs[0].key == file_name:
        public_url = f'{BUCKET_PREFIX}/{BUCKET_NAME}/{file_name}'
        logger.info(f'File successfully saved in {public_url}')
        return custom_responses.post_response(public_url)
    else:
        logger.error('File could not be saved')
        return custom_responses.post_response()
Exemple #5
0
def delete_campaign():
    body = app.current_request.json_body
    item = get_app_db().get_item(body['campaign_id'])
    if item['adwords_campaignid']:
        adwords_response = remove_campaign(item['adwords_campaignid'])
        response = get_app_db().delete_campaign(body['campaign_id'])
        if response['HTTPStatusCode'] == 200:
            logger.info(f'Campaing was Deleted')
            return custom_responses.post_response(
                adwords_response['value'][0]['status'], 'Campaing was Deleted')
        else:
            error_message = 'Campaign Could not be deleted'
            logger.info(error_message)
            return custom_responses.post_response(None, error_message)
    else:
        error_message = 'Campaign is already Deleted'
        logger.info(error_message)
        return custom_responses.post_response(None, error_message)
Exemple #6
0
def add_budget():
    filename = (datetime.now(pytz.timezone('America/Guatemala')) +
                timedelta(365)).strftime('%d-%m-%Y,%H:%M:%S') + '.pdf'
    body = app.current_request.json_body
    logger.info(body)
    create_pdf(filename, body)

    s3_client, bucket = get_s3_resources()
    s3_client.upload_file('/tmp/' + filename, BUCKET_NAME, filename)

    objs = list(bucket.objects.filter(Prefix=filename))
    if len(objs) > 0 and objs[0].key == filename:
        public_url = f'{BUCKET_PREFIX}/{BUCKET_NAME}/{filename}'
        logger.info(f'Budget successfully saved in {public_url}')
        return custom_responses.post_response(public_url)
    else:
        logger.info('Budget could not be saved')
        return custom_responses.post_response()
Exemple #7
0
def payment():
    body = app.current_request.json_body
    if validate_transaction_number(body["transaction_number"]):
        val_payment = get_app_db().validate_payment(body["transaction_number"])
        if not val_payment:
            new_payment, error_message = setup_mail(
                str(body["transaction_number"]))
            if new_payment:
                response = get_app_db().add_item(payment=new_payment)
                return custom_responses.post_response(response, error_message)
            else:
                logger.info('Payment could not be saved')
                return custom_responses.post_response(None, error_message)
        else:
            logger.info(
                f'Payment {body["transaction_number"]} already processed')
            error_message = 'Payment already processed'
            return custom_responses.post_response(None, error_message)
    else:
        error_message = 'Bad Format on Transaction Number'
        logger.info(error_message + str(body["transaction_number"]))
        return custom_responses.post_response(None, error_message)
Exemple #8
0
def checkout_treatments():
    body = app.current_request.json_body
    new_item_id = get_app_db().add_item(checkout=body)
    return custom_responses.post_response(new_item_id)
Exemple #9
0
def add_new_patient():
    body = app.current_request.json_body
    new_item_id = get_app_db().add_item(patient=body)
    return custom_responses.post_response(new_item_id)