|
| 1 | +"""Get details for an image.""" |
| 2 | +# :license: MIT, see LICENSE for more details. |
| 3 | + |
| 4 | +import click |
| 5 | + |
| 6 | +from SoftLayer.CLI import environment |
| 7 | +from SoftLayer.CLI import formatting |
| 8 | +from SoftLayer.managers.account import AccountManager |
| 9 | +from SoftLayer.managers.email import EmailManager |
| 10 | +from SoftLayer import utils |
| 11 | + |
| 12 | + |
| 13 | +@click.command() |
| 14 | +@environment.pass_env |
| 15 | +def cli(env): |
| 16 | + """""" |
| 17 | + manager = AccountManager(env.client) |
| 18 | + email_manager = EmailManager(env.client) |
| 19 | + result = manager.get_Network_Message_Delivery_Accounts() |
| 20 | + |
| 21 | + table = formatting.KeyValueTable(['name', 'value']) |
| 22 | + |
| 23 | + table_information = formatting.KeyValueTable(['id', 'username', 'hostname', 'description', 'vendor']) |
| 24 | + table_information.align['id'] = 'r' |
| 25 | + table_information.align['username'] = 'l' |
| 26 | + |
| 27 | + for email in result: |
| 28 | + # print(email['id']) |
| 29 | + table_information.add_row([email.get('id'), email.get('username'), email.get('emailAddress'), |
| 30 | + utils.lookup(email, 'type', 'description'), |
| 31 | + utils.lookup(email, 'vendor', 'keyName')]) |
| 32 | + |
| 33 | + overview_table = _build_overview_table(email_manager.get_AccountOverview(email.get('id'))) |
| 34 | + statistics = email_manager.get_statistics(email.get('id'), |
| 35 | + ["requests", "delivered", "opens", "clicks", "bounds"], |
| 36 | + True, True, True, 6) |
| 37 | + |
| 38 | + table.add_row(['email information', table_information]) |
| 39 | + table.add_row(['email overview', overview_table]) |
| 40 | + for statistic in statistics: |
| 41 | + table.add_row(['statistics', _build_statistics_table(statistic)]) |
| 42 | + |
| 43 | + env.fout(table) |
| 44 | + |
| 45 | + |
| 46 | +def _build_overview_table(email_overview): |
| 47 | + table = formatting.KeyValueTable(['name', 'value']) |
| 48 | + table.align['name'] = 'r' |
| 49 | + table.align['value'] = 'l' |
| 50 | + |
| 51 | + table.add_row(['creditsAllowed', email_overview.get('creditsAllowed')]) |
| 52 | + table.add_row(['creditsRemain', email_overview.get('creditsRemain')]) |
| 53 | + table.add_row(['package', email_overview.get('package')]) |
| 54 | + table.add_row(['reputation', email_overview.get('reputation')]) |
| 55 | + table.add_row(['requests', email_overview.get('requests')]) |
| 56 | + |
| 57 | + return table |
| 58 | + |
| 59 | + |
| 60 | +def _build_statistics_table(statistics): |
| 61 | + table = formatting.KeyValueTable(['name', 'value']) |
| 62 | + table.align['name'] = 'r' |
| 63 | + table.align['value'] = 'l' |
| 64 | + |
| 65 | + table.add_row(['delivered', statistics.get('delivered')]) |
| 66 | + table.add_row(['requests', statistics.get('requests')]) |
| 67 | + table.add_row(['bounces', statistics.get('bounces')]) |
| 68 | + table.add_row(['opens', statistics.get('opens')]) |
| 69 | + table.add_row(['clicks', statistics.get('clicks')]) |
| 70 | + table.add_row(['spam Reports', statistics.get('spamReports')]) |
| 71 | + |
| 72 | + return table |
0 commit comments