Advertisement
Guest User

Untitled

a guest
Dec 12th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.76 KB | None | 0 0
  1. from prettytable import PrettyTable
  2. import boto3
  3.  
  4. list_of_tables = [
  5.     {
  6.         "db": "rds",
  7.         "tables":
  8.         [
  9.             "bill_",
  10.             "set_",
  11.             "my_",
  12.             "ocpi_",
  13.             "sub_",
  14.             "trff_",
  15.             "ecl_",
  16.             "hub_",
  17.             "avail_",
  18.             "cn_"
  19.         ],
  20.         "isprefix": True
  21.     },
  22.     {
  23.         "db": "salesforce",
  24.         "tables":
  25.         [
  26.             "sf_payment_account__c",
  27.             "payment_account_data_errors",
  28.             "payment_accounts_view"
  29.         ],
  30.         "isprefix": False
  31.     }
  32. ]
  33.  
  34. list_of_locations = []
  35.  
  36. glue_client = boto3.client("glue")
  37.  
  38. for income in list_of_tables:
  39.     resp = glue_client.get_tables(DatabaseName=income['db'])
  40.     for glue_table in resp['TableList']:
  41.         glue_table_name = str(glue_table['Name'])
  42.         if income['isprefix']:
  43.             for prefix in income['tables']:
  44.                 if glue_table_name.startswith(prefix):
  45.                     list_of_locations.append({"db": income['db'],
  46.                                               "table": glue_table_name,
  47.                                               "location": glue_table['StorageDescriptor']['Location']})
  48.         if glue_table_name in income['tables']:
  49.             list_of_locations.append({"db": income['db'],
  50.                                       "table": glue_table_name,
  51.                                       "location": glue_table['StorageDescriptor']['Location']})
  52.  
  53.  
  54. print(list_of_locations)
  55. result = PrettyTable()
  56. result.field_names = ["Database", "Table", "S3"]
  57. for location in list_of_locations:
  58.     result.add_row([location['db'],
  59.                    location['table'],
  60.                    location['location']])
  61.  
  62. print(result)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement