mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-15 09:42:38 -05:00
Provider Statistics added.
Rates command added with a test. Updated to include added migration.
This commit is contained in:
30
app/commands.py
Normal file
30
app/commands.py
Normal file
@@ -0,0 +1,30 @@
|
||||
from datetime import datetime
|
||||
from decimal import Decimal
|
||||
from flask.ext.script import Command, Manager, Option
|
||||
from app.models import PROVIDERS
|
||||
from app.dao.provider_rates_dao import create_provider_rates
|
||||
|
||||
|
||||
class CreateProviderRateCommand(Command):
|
||||
|
||||
option_list = (
|
||||
Option('-p', '--provider_name', dest="provider_name", help='Provider name'),
|
||||
Option('-c', '--cost', dest="cost", help='Cost (pence) per message including decimals'),
|
||||
Option('-d', '--valid_from', dest="valid_from", help="Date (%Y-%m-%dT%H:%M:%S) valid from")
|
||||
)
|
||||
|
||||
def run(self, provider_name, cost, valid_from):
|
||||
if provider_name not in PROVIDERS:
|
||||
raise Exception("Invalid provider name, must be one of ({})".format(', '.join(PROVIDERS)))
|
||||
|
||||
try:
|
||||
cost = Decimal(cost)
|
||||
except:
|
||||
raise Exception("Invalid cost value.")
|
||||
|
||||
try:
|
||||
valid_from = datetime.strptime('%Y-%m-%dT%H:%M:%S', valid_from)
|
||||
except:
|
||||
raise Exception("Invalid valid_from date. Use the format %Y-%m-%dT%H:%M:%S")
|
||||
|
||||
create_provider_rates(provider_name, valid_from, cost)
|
||||
Reference in New Issue
Block a user