1
Fork 0

summertime: table

master
Valdos Sine 2014-05-08 20:40:04 +04:00
parent 78592185da
commit 4f8df36c76
2 changed files with 48 additions and 0 deletions

32
2014/2-summertime/randomize.py Executable file
View File

@ -0,0 +1,32 @@
#!/usr/bin/python2
# -*- coding: utf-8 -*-
import random, time
def write_user(username, table_size):
repeater = False
random_seed = random.choice(range(1, table_size))
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
if repeater == False:
tfile.write("%i | %s\n" % (random_seed, username))
def check_file(username, table_size):
try:
tablefile = open('table.txt', 'r')
write_user(username, table_size)
except IOError:
tablefile = open('table.txt', 'w')
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)
nickname = raw_input("Введите имя игрока: ")
check_file(nickname, 11)

View File

@ -0,0 +1,16 @@
Жеребьевка участников LORChess.
Размер таблицы участников: 10.
Данный файл является неизменяемым и создаваемым один раз.
UNIX timestamp: 1399567032
========
3 | DoctorSinus
5 | iVS
8 | HunOL
7 | redgremlin
4 | MyTrooName
9 | MikeDM
10 | raven_cler
2 | shell-script
1 | J
6 | n1l