示例#1
0
################################################################################
# Query or email template
################################################################################
query_template = load_template("archive_unused_reports.sql.template")

query = query_template.format(
  archive_window = settings.ARCHIVE_WINDOW,
  domain = settings.EMAIL_DOMAIN)

################################################################################
# Data to process
################################################################################
curs = conn.cursor()
curs.execute(query)
records = list_dict([col.name for col in curs.description], curs.fetchall())
email_sort = sorted(records, key = lambda rec: rec['owner_email'])
unique_emails = groupby(email_sort, lambda rec: rec['owner_email'])

################################################################################
# Emailing the report owners
################################################################################
with open("archive_unused_reports.html.template", "r") as f:
  body_template = f.read()

for line in unique_emails:
  email = line[0]
  workbooks = map(lambda rec: rec['workbook'], list(line[1]))
  subj = 'Archiving unused Tableau Reports'
  body = body_template.format(
    archive_window = settings.ARCHIVE_WINDOW,
################################################################################
# Query or email template
################################################################################
query_template = load_template("archive_unused_reports.sql.template")

query = query_template.format(
  archive_window = settings.ARCHIVE_WINDOW,
  domain = settings.EMAIL_DOMAIN)

################################################################################
# Data to process
################################################################################
curs = conn.cursor()
curs.execute(query)
records = list_dict([col.name for col in curs.description], curs.fetchall())
email_sort = sorted(records, key = lambda rec: rec['owner_email'])
unique_emails = groupby(email_sort, lambda rec: rec['owner_email'])

################################################################################
# Emailing the report owners
################################################################################
with open("archive_unused_reports.html.template", "r") as f:
  body_template = f.read()

for line in unique_emails:
  email = line[0]
  workbooks = map(lambda rec: rec['workbook'], list(line[1]))
  subj = 'Archiving unused Tableau Reports'
  body = body_template.format(
    archive_window = settings.ARCHIVE_WINDOW,
示例#3
0
parser.add_argument('--archive_path', action="store", dest="archive_path", required=True,  help="Where to store the workbook files")
parser.add_argument('--vert_user', action='store', dest='vert_user', required=False, help='Username to database to store workbook connection info')
parser.add_argument('--vert_pass', action='store', dest='vert_pass', required=False, help='Password to database to store workbook connection info')
args = parser.parse_args()



########################################
#Pulling down twb, twbx, tds, and tdsx files
########################################
conn = psycopg2.connect(host=settings.TABLEAU_HOST, port=8060,database="workgroup", user=args.postgres_user, password=args.postgres_pass)
print 'Pulling down twb and twbx files from server...'
twbx_workbooks_query = open('./wb_and_ds_contentID.sql', 'r').read()
curs = conn.cursor()
curs.execute(twbx_workbooks_query)
workbook_query_records = helper_functions.list_dict([col.name for col in curs.description], curs.fetchall())

def tabExport(record):
	if record['sourcetype'] == 'Datasource':
		fileExt = 'tdsxm'
		fileSearch = 'tds'
	elif record['sourcetype'] == 'Workbook':
		fileExt = 'twbxm'
		fileSearch = 'twb'
	lobj = psycopg2.extensions.lobject(conn, record['content'], 'r')
	file_path = '%s/%s.%s' % (args.archive_path, record['repository_url'], fileExt)
	lobj.export(file_path)
	if zipfile.is_zipfile(file_path):
		file_zip = zipfile.ZipFile(file_path)
		for files in file_zip.namelist():
			if files.find('.%s' % fileSearch) > 0: