Created
January 15, 2017 20:00
-
-
Save anonymous/b7d04f0961405a40d0f51e8f2bca6cef to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import xlsxwriter | |
import sys | |
#### Kvicksundspokalen parser | |
#Parse file | |
#Extract fields | |
#Sort by date? | |
#Format xml output | |
#Add to sheet | |
#Create an new Excel file and add a worksheet. | |
workbook = xlsxwriter.Workbook('demo.xlsx') | |
worksheet = workbook.add_worksheet() | |
reload(sys) | |
sys.setdefaultencoding('utf-8') | |
# Widen the first column to make the text clearer. | |
worksheet.set_column('A:A', 20) | |
worksheet.set_column('C:C', 15) | |
worksheet.set_column('E:E', 20) | |
worksheet.set_column('F:F', 15) | |
worksheet.set_column('G:G', 30) | |
# Add a bold format to use to highlight cells. | |
bold = workbook.add_format({'bold': True}) | |
# Write some simple text. | |
worksheet.write('A1', "Lagnamn", bold) | |
worksheet.write('B1', "Klass", bold) | |
worksheet.write('C1', "Anmdatum", bold) | |
worksheet.write('D1', "Status", bold) | |
worksheet.write('E1', "Namn", bold) | |
worksheet.write('F1', "Telefon", bold) | |
worksheet.write('G1', "Mail", bold) | |
rowCount = 1 | |
with open("kvicksundscupen_raw.txt", "r") as infile, open("mail_adresser.txt", "w") as outfile: | |
for line in infile: | |
if "Lagnamn : " in line: | |
worksheet.write(rowCount, 0,line.split(" : ")[1]) | |
elif "Klass : " in line: | |
worksheet.write(rowCount, 1,line.split(" : ")[1]) | |
elif "datum : " in line: | |
worksheet.write(rowCount, 2,line.split(" : ")[1]) | |
elif "Status : " in line: | |
worksheet.write(rowCount, 3,line.split(" : ")[1]) | |
elif "Namn : " in line: | |
worksheet.write(rowCount, 4,line.split(" : ")[1]) | |
elif "Telefon : " in line: | |
worksheet.write(rowCount, 5,line.split(" : ")[1]) | |
elif "E-mail : " in line: | |
outfile.write((line.split(" : ")[1])+",") | |
worksheet.write(rowCount, 6,line.split(" : ")[1]) | |
rowCount = rowCount + 1 | |
workbook.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment