Last active
April 22, 2018 10:28
-
-
Save mkoskinen/99fdbc4d1ff54feb917733ae5094a39b 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
#!/usr/bin/env python | |
""" | |
A script for operating on futubileet CSV information. | |
""" | |
from __future__ import print_function | |
import csv | |
import sys | |
RESULT = [] | |
def syntax(execname): | |
print("Syntax: %s <input.csv>" % execname) | |
sys.exit(1) | |
def handle_row(row): | |
global RESULT | |
if "".join(row) == "": | |
# Skip empty rows. Has 'pass' now if we want some later processing. | |
pass | |
else: | |
# User listing, columns as follows | |
# 1. Name, 2. Email, 3. Inviter (email), 4. Dietary restrictions, 5. Attending boolean | |
RESULT.append([row[2], row[1], row[1], row[5], row[3]]) | |
if row[6] != "No": | |
RESULT.append([row[7], row[8], row[1], row[9], "Yes"]) | |
# Checking if a second guest exists below. Magic number 3 is for the next invitee | |
if "".join(row[10:13]) != "": | |
RESULT.append([row[7+3], row[8+3], row[1], row[9+3], "Yes"]) | |
def print_result(): | |
global RESULT | |
column_names = ["Name", "Email", "Inviter e-mail", "Dietary restrictions", "Attendance boolean"] | |
print (";".join(column_names)) | |
for entry in RESULT: | |
print("%s" % ";".join(entry)) | |
def main(infile): | |
# print("Main.") | |
iter_num = 0 | |
with open(infile, 'r') as csvfile: | |
csvreader = csv.reader(csvfile, delimiter=';', quotechar='|') | |
for row in csvreader: | |
# Skip the first line (column names) | |
iter_num += 1 | |
if iter_num == 1: | |
pass | |
else: | |
handle_row(row) | |
print_result() | |
if __name__ == "__main__": | |
if len(sys.argv) != 2: | |
syntax(sys.argv[0]) | |
main(sys.argv[1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment