Skip to content

Commit 7f7c787

Browse files
committed
fixed james' garbage
1 parent 94d4a28 commit 7f7c787

File tree

1 file changed

+47
-47
lines changed

1 file changed

+47
-47
lines changed

raffle.py

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -19,67 +19,65 @@ def gen_list(argcsv):
1919
Args:
2020
argcsv - csv file from parse_args() to read and pull the list of possible winners from
2121
Returns:
22-
winlist - the list of possible winners. It takes in the ticketholder's
22+
inputlist - the list of possible winners. It takes in the ticketholder's
2323
username and ticketnumber and appends them before inserting them into
2424
winlist to be passed to html_writer()
2525
2626
"""
27-
winlist = []
27+
banned_tix = ['CORE', 'Vendor Ticket', 'SPU Dorm Room - Friday and Saturday', 'SPU Dorm Room - Saturday ONLY',
28+
'Soldering Workshop: Fourier (BYOS) 10am-11:30am', 'Soldering Workshop: Fourier 10am-11:30am',
29+
'Soldering Workshop: 4x4 Handwire 1pm-3pm']
30+
31+
inputlist = []
2832
with open(argcsv) as csvfile:
2933
reader = csv.DictReader(csvfile)
30-
print(reader)
3134
for row in reader:
3235
username = row['What username do you go by online?']
3336
if row['What username do you go by online?'] == '-':
34-
username = row['Ticket First Name'] + " " + row['Ticket Last Name'][0:1] + "."
37+
username = "{} {}.".format(row['Ticket First Name'], row['Ticket Last Name'][0:1])
3538
num = row['Number']
36-
winlist[num] = username
37-
winlist.append({'id': row['Number', 'name': row['Ticket First Name'] + " " + row['Ticket Last Name'][0:1], 'uname': row['What username do you go by online?']})
38-
return winlist
39-
def html_writer(winlist, total_winners):
39+
if row['Ticket'] not in banned_tix:
40+
inputlist.append({'number':num,'username':username})
41+
return inputlist
42+
def html_writer(inputlist, total_winners, csvout, htmlout):
4043
"""
4144
This function writes the html file to display the winners.
4245
43-
Args:
44-
winlist - list of winners generated by gen_list()
46+
Args
47+
inputlist - full list of entrants
4548
total_winners - total number of specified winners taken from command line args
4649
4750
Returns:
4851
None. Writes an html file.
4952
5053
"""
51-
winreader = open('winners.csv', 'r')
52-
for x in winlist:
53-
for y in winreader:
54-
if x in y:
55-
del x[y]
56-
winreader.close()
57-
slide = open('winners.html', 'w')
58-
slide.write("""
59-
<!doctype html>
60-
<html lang=en>
61-
<head>
62-
<meta charset=utf-8>
63-
<title>SMKmeetup Giveaway Winners!</title>
64-
<link rel="stylesheet" href="raffle-style.css">
65-
</head>
66-
<body>
67-
<h2>SMKmeetup Giveaway Winners</h2>
68-
<ul class="multi-12">
69-
""")
70-
for i in random.sample(list(winlist), total_winners):
71-
winwriter = open('winners.csv', 'a')
72-
winner = i + " " + winlist[i] + " "
73-
slide.write("<li>"+winner+"</li>\n")
74-
winwriter.write(i + "," + winlist[i] + "\n")
75-
print(winner)
76-
winwriter.close()
77-
slide.write("""
78-
</ul>
79-
</body>
80-
</html>
81-
""")
82-
slide.close()
54+
with open(htmlout, 'w') as slide:
55+
slide.write(
56+
'<!doctype html>\n'
57+
'<html lang=en>\n'
58+
'<head>\n'
59+
'<meta charset=utf-8>\n'
60+
'<title>SMKmeetup Giveaway Winners!</title>\n'
61+
'<link rel="stylesheet" href="raffle-style.css">\n'
62+
'</head>\n'
63+
'<body>\n'
64+
'<h2>SMKmeetunp Giveaway Winners</h2>\n'
65+
'<ul class="multi-12">\n'
66+
)
67+
for winner in random.sample(inputlist, total_winners):
68+
slide.write("<li>{} {}</li>\n".format(winner['number'], winner['username']))
69+
inputlist.pop(inputlist.index(winner))
70+
slide.write(
71+
'</ul>\n'
72+
'</body>\n'
73+
'</html>\n'
74+
)
75+
with open(csvout, 'w') as csvfile:
76+
writer = csv.DictWriter(csvfile, fieldnames=['number','username'])
77+
writer.writerow({'number': 'Number', 'username': 'What username do you go by online?'})
78+
for loser in inputlist:
79+
writer.writerow({'number': loser['number'], 'username': loser['username']})
80+
8381
def parse_args():
8482
"""
8583
This function parses the arguments from the command line.
@@ -92,15 +90,17 @@ def parse_args():
9290
9391
"""
9492
parser = argparse.ArgumentParser()
95-
parser.add_argument("csv", help="the location of the csv input")
96-
parser.add_argument("total_winners", type=int, help="total number of selected winners")
97-
parser.add_argument("rerun", type=bool, help="boolean value to determine whether or not the script will be rerun")
93+
parser.add_argument('-i', "--csvin", help="the location of the csv input")
94+
parser.add_argument('-w', "--total_winners", type=int, help="total number of selected winners")
95+
parser.add_argument('-o', "--csvout", help="csv output file")
96+
parser.add_argument('-p', "--htmlout", help="html output file")
9897
return parser.parse_args()
98+
9999
def main():
100100
"""
101101
This function calls all the necessary functions needed for the program to run.
102102
"""
103103
args = parse_args()
104-
html_writer(gen_list(args.csv), args.total_winners)
104+
html_writer(gen_list(args.csvin), args.total_winners, args.csvout, args.htmlout)
105105
if __name__ == "__main__":
106-
main()
106+
main()

0 commit comments

Comments
 (0)