-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_vote.py
20 lines (20 loc) · 915 Bytes
/
generate_vote.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#!/usr/bin/env python
import os
from random import randint
from voting.models import *
seats=Seat.objects.all()
for seat in seats:
booths = seat.booth_set.all() #get all the booths of each district
for booth in booths:
file_name='voting_data/District'+str(seat.id)+'/booth-'+str(booth.id)+'.txt'
if not os.path.exists('voting_data/District'+str(seat.id)):
os.mkdir('voting_data/District'+str(seat.id))
i=1
while i<=100:
parties=Party.objects.all().values('name')
index=randint(0,len(parties)-1)
party_name=parties[index]['name']
f = open(file_name, 'a+' )
f.write(party_name+"\n")
f.close()
i+=1