fork download
  1. # -*- coding: utf-8 -*-
  2. import datetime
  3. from datetime import timedelta, date
  4. import random
  5.  
  6. twitfilename = 'tweets.txt'
  7.  
  8. A = 10 # начало интервала (час) постинга. Во сколько "просыпается" бот. Минимум 10.
  9. B = 23 # конец интервала (час) постинга. Во сколько "засыпает бот.
  10. N = 5 # кол-во твитов в день.
  11.  
  12. with open(twitfilename) as input_file:
  13. strok = len(input_file.readlines())
  14.  
  15. okrug = strok // N
  16. howmuchdayswenee = okrug * N + N
  17.  
  18. def daterange(start, stop, step=datetime.timedelta(days=1), inclusive=True):
  19. if step.days > 0:
  20. while start < stop:
  21. yield start
  22. start = start + step
  23. elif step.days < 0:
  24. while start > stop:
  25. yield start
  26. start = start + step
  27. if inclusive and start == stop:
  28. yield start
  29.  
  30. start_date = date.today()
  31. end_date = date.today() + timedelta(days=howmuchdayswenee)
  32. dates = [x for x in daterange(start_date,
  33. end_date,
  34. step=timedelta(days=1),
  35. inclusive=True)]
  36.  
  37. datelist = [] # создаем пустой список для дат
  38. for dayz in dates:
  39. addstr = str(dayz) + ' ' + str(random.randint(A, B)) + ':' + str(random.randint(10, 20))
  40. datelist.append(addstr)
  41. addstr = str(dayz) + ' ' + str(random.randint(A, B)) + ':' + str(random.randint(21, 30))
  42. datelist.append(addstr)
  43. addstr = str(dayz) + ' ' + str(random.randint(A, B)) + ':' + str(random.randint(31, 40))
  44. datelist.append(addstr)
  45. addstr = str(dayz) + ' ' + str(random.randint(A, B)) + ':' + str(random.randint(41, 50))
  46. datelist.append(addstr)
  47. addstr = str(dayz) + ' ' + str(random.randint(A, B)) + ':' + str(random.randint(51, 59))
  48. datelist.append(addstr)
  49.  
  50. srez = datelist[0:strok] # оставляем кол-во дат равное кол-ву строк, т.е. твитов
  51.  
  52. with open(twitfilename) as input_file:
  53. j = 0
  54. for line in input_file:
  55. print('\"' + str(srez[j]) + '\",\"' + str(line.strip()) + '\",0') # тут даты соединяются с твитами
  56. j += 1
Runtime error #stdin #stdout #stderr 0.02s 37872KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Traceback (most recent call last):
  File "./prog.py", line 12, in <module>
    with open(twitfilename) as input_file:
FileNotFoundError: [Errno 2] No such file or directory: 'tweets.txt'