import sys, os
import xlrd


def run():
	files = os.listdir()
	print('filename\tregion\ttotal\tmedia\tmediashare\ttelevision\ttelshare')
	for name in files:
		name = name.lower()
		if name[-4:] == '.xls':
			wb = xlrd.open_workbook(name)
			sheet = wb.sheet_by_index(1)
			reg = sheet.cell(4, 3)
			sheet = wb.sheet_by_index(2)
			tel = 0
			total = 0
			media = 0
			for row in sheet.get_rows():
				if row[1].value == '200':
					total = row[6].value
				if row[3].value == '1200' and row[5].value == '000':
					media = row[6].value
				if row[3].value == '1201' and row[5].value == '000':
					tel = row[6].value
					break
			print('%s\t%s\t%f\t%f\t%f\t%f\t%f' % (name, reg.value, total / 1000000, media / 1000000, ((media * 100) / total) if total > 0 else 0, tel / 1000000, ((tel * 100) / media) if media > 0 else 0 ) )


	pass

if __name__ == '__main__':
	run()