Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- import os
- import sys
- def csv_to_htm(filename, minutes):
- outfilename = filename.split('.')[0] + '.html'
- try:
- csv_file = open(filename,"r")
- except IOError as e:
- if e.errno == 2:
- print 'Unable to open file: ' + filename
- sys.exit()
- vouchers = []
- for line in csv_file.readlines():
- if line.find('#') != 0:
- line = line.replace('"','')
- line = line.replace(' ','')
- line = line.replace('\n','')
- vouchers.append(line)
- try:
- html_file = open(outfilename,"w")
- except Exception as e:
- print e
- html_file.write('<html><head></head><body>\n')
- html_file.write('<table border="1" cellpadding="15">\n')
- colcount = 0
- for code in vouchers:
- if colcount > 3:
- html_file.write('</tr>\n')
- colcount = 0
- if colcount == 0:
- html_file.write('<tr>\n')
- html_file.write('<td><center>Internet Access Voucher<br><br>')
- html_file.write('One Time Use Only!<br><br>')
- html_file.write('Valid For ' + str(minutes) + ' Minutes<br><br><b>' + code + '</b></center></td>')
- colcount += 1
- html_file.write('</table></body></html>')
- files = os.listdir('.')
- csv_files = []
- csv_durations = []
- for item in files:
- if item.endswith('.csv'):
- csv_files.append(item)
- for csv_file in csv_files:
- valid_input = False
- while valid_input != True:
- minutes = raw_input('Enter the amount of time for vouchers in file ' + csv_file + ': ')
- minutes = minutes.strip()
- if minutes.isdigit():
- csv_durations.append(minutes)
- valid_input = True
- for filename, minutes in zip(csv_files, csv_durations):
- print 'Generating vouchers: ' + filename, minutes
- csv_to_htm(filename, minutes)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement