Linux.org.ru chess tournament logs and tables
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
1.2KB

  1. #!/usr/bin/python2
  2. # -*- coding: utf-8 -*-
  3. import random, time
  4. def write_user(username, table_size):
  5. repeater = False
  6. random_seed = random.choice(range(1, table_size))
  7. tfile = open('table.txt', 'r+a')
  8. tabledata = tfile.readlines()
  9. for line in tabledata:
  10. if line.split(' | ')[0] == str(random_seed):
  11. # repeat from begin
  12. repeater = True
  13. write_user(username, table_size)
  14. # if we haven't matching number, write das line
  15. if repeater == False:
  16. tfile.write("%i | %s\n" % (random_seed, username))
  17. def check_file(username, table_size):
  18. try:
  19. tablefile = open('table.txt', 'r')
  20. write_user(username, table_size)
  21. except IOError:
  22. tablefile = open('table.txt', 'w')
  23. tablefile.write("Жеребьевка участников LORChess.\nРазмер таблицы участников: %s.\nДанный файл является неизменяемым и создаваемым один раз.\nUNIX timestamp: %i\n========\n\n" % (table_size - 1, int(time.time())))
  24. tablefile.close()
  25. write_user(username, table_size)
  26. nickname = raw_input("Введите имя игрока: ")
  27. check_file(nickname, 17)