-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathraffle.py
71 lines (63 loc) · 1.84 KB
/
raffle.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
from random import shuffle, choice
from tabulate import tabulate
prizes = [
'Licencia JetBrains #1',
'Licencia JetBrains #2',
'Entrada Pycon',
'Cursos Net University #1',
'Cursos Net University #2',
'Cursos Net University #3',
'Cursos Net University #4',
'Cursos Net University #5',
'Paquete JSConf #1',
'Paquete JSConf #2',
'Paquete JSConf #3',
'Paquete JSConf #4',
'Paquete JSConf #5',
'Paquete JSConf #6',
'Pin ScaleConf #1',
'Pin ScaleConf #2',
'Pin ScaleConf #3'
]
# noinspection PyBroadException
def get_attendees():
attendees = []
try:
f = open('./attendees.txt', 'r')
except Exception:
return []
lines = f.readlines()
if len(lines) > 1:
lines.pop(0)
for line in lines:
full_name = ''
is_here = False
try:
portions = line.split(',')
full_name = portions[4]
ticket = portions[14]
is_here = str(portions[32]) == '1'
full_name += ' (%s)' % ticket.strip()
except Exception:
pass
if len(full_name) > 0 and is_here:
attendees.append(full_name)
return attendees
def main():
attendees = get_attendees()
if len(attendees) <= 0:
print("No hay asistentes registrados")
return 1
shuffle(attendees)
indices = range(len(attendees))
winners_indices = []
while len(winners_indices) < len(prizes):
winners_indices.append(choice(indices))
winners_indices = list(set(winners_indices))
winners = [attendees[i] for i in winners_indices]
shuffle(winners)
assigned_prizes = [[i + 1, prizes[i], attendees[i]] for i in range(len(prizes))]
print(tabulate(assigned_prizes, headers=['No.', 'Prize', 'Winner'], tablefmt='orgtbl'))
return 0
if __name__ == '__main__':
main()