From fb3e0030737394fd4e8dc01846d1c9671c6e4bca Mon Sep 17 00:00:00 2001 From: Valdos Sine Date: Mon, 26 Aug 2013 21:12:19 +0400 Subject: [PATCH] randomize works --- randomize.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/randomize.py b/randomize.py index 99637e9..6ad6238 100755 --- a/randomize.py +++ b/randomize.py @@ -1,20 +1,21 @@ #!/usr/bin/python2 # -*- coding: utf-8 -*- -import random - -# TODO: вернуться, отладить +import random, time def write_user(username, table_size): + repeater = False random_seed = random.choice(range(1, table_size)) - tfile = open('table.txt', 'a+r') + tfile = open('table.txt', 'r+a') tabledata = tfile.readlines() for line in tabledata: if line.split(' | ')[0] == str(random_seed): # repeat from begin + repeater = True write_user(username, table_size) # if we haven't matching number, write das line - tfile.write("%i | %s\n" % (random_seed, username)) + if repeater == False: + tfile.write("%i | %s\n" % (random_seed, username)) def check_file(username, table_size): try: @@ -22,7 +23,7 @@ def check_file(username, table_size): write_user(username, table_size) except IOError: tablefile = open('table.txt', 'w') - tablefile.write("Рандомизатор: составление таблицы методом случайных чисел.\nРазмер таблицы: %s\n\n========\n\n" % table_size) + tablefile.write("Жеребьевка участников LORChess.\nРазмер таблицы участников: %s.\nДанный файл является неизменяемым и создаваемым один раз.\nUNIX timestamp: %i\n========\n\n" % (table_size - 1, int(time.time()))) tablefile.close() write_user(username, table_size)