The Lurker's Guide to Babylon 5
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.

115 lines
2.4 KiB

17 years ago
  1. #!/usr/bin/python
  2. #
  3. # Print a bunch of dates, one week apart, replacing dates at the beginning
  4. # of standard input.
  5. #
  6. import string, sys
  7. from time import gmtime,mktime
  8. ndays = [ 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ]
  9. step = 7
  10. skipdays = [ 0, 0, 0, 0, 0, 0, 0 ]
  11. countdays = [ 1, 1, 1, 1, 1, 1, 1 ]
  12. europe = 0
  13. while sys.argv[1][0] == '-':
  14. if sys.argv[1] == '-step':
  15. step = string.atoi(sys.argv[2])
  16. sys.argv = sys.argv[2:]
  17. if sys.argv[1] == '-e':
  18. europe = 1
  19. sys.argv = sys.argv[1:]
  20. if sys.argv[1] == '-daily':
  21. step = 1
  22. # Skip Saturday and Sunday
  23. skipdays[5] = 1
  24. skipdays[6] = 1
  25. sys.argv = sys.argv[1:]
  26. if sys.argv[1] == '-on':
  27. step = 1
  28. skipdays = [ 1, 1, 1, 1, 1, 1, 1 ]
  29. for num in string.splitfields(sys.argv[2], ','):
  30. skipdays[string.atoi(num)] = 0
  31. sys.argv = sys.argv[2:]
  32. if sys.argv[1] == '-repeat':
  33. for num in string.splitfields(sys.argv[2], ','):
  34. n = string.atoi(num)
  35. countdays[n] = countdays[n] + 1
  36. sys.argv = sys.argv[2:]
  37. if sys.argv[1] == '-skip':
  38. step = 1
  39. skipdays = [ 0, 0, 0, 0, 0, 0, 0 ]
  40. for num in string.splitfields(sys.argv[2], ','):
  41. skipdays[string.atoi(num)] = 1
  42. sys.argv = sys.argv[2:]
  43. year = string.atoi(sys.argv[1])
  44. month = string.atoi(sys.argv[2])
  45. day = string.atoi(sys.argv[3])
  46. if year < 93:
  47. year = year + 100
  48. (x,x,x,x,x,x,weekday,x,x) = gmtime(mktime(year + 1900, month,
  49. day, 10, 0, 0, 0, 0, 0))
  50. thisdaycount = 0
  51. if len(sys.argv) > 4:
  52. step = string.atoi(sys.argv[4])
  53. if (year & 3) == 0:
  54. ndays[2] = 29
  55. line = sys.stdin.readline()
  56. while line != '':
  57. if line[0:5] == '<pre>':
  58. head = '<pre>'
  59. line = line[5:]
  60. else:
  61. head = ''
  62. if not (line[0] in ['0','1','2','3','4','5','6','7','8','9','?']):
  63. sys.stdout.write(head + line)
  64. line = sys.stdin.readline()
  65. continue
  66. else:
  67. if europe == 1:
  68. sys.stdout.write('%s%02d/%02d/%02d%s' % (head,
  69. day, month, year % 100, line[8:]))
  70. else:
  71. sys.stdout.write('%s%02d/%02d/%02d%s' % (head,
  72. year % 100, month, day, line[8:]))
  73. line = sys.stdin.readline()
  74. thisdaycount = thisdaycount + 1
  75. if thisdaycount < countdays[weekday]:
  76. continue
  77. day = day + step
  78. (x,x,x,x,x,x,weekday,x,x) = gmtime(mktime(year + 1900, month,
  79. day, 10, 0, 0, 0, 0, 0))
  80. thisdaycount = 0
  81. while skipdays[weekday]:
  82. day = day + 1
  83. weekday = (weekday + 1) % 7
  84. if day > ndays[month]:
  85. day = day - ndays[month]
  86. month = month + 1
  87. if month > 12:
  88. month = 1
  89. year = year + 1
  90. if (year & 3) == 0:
  91. ndays[2] = 29
  92. else:
  93. ndays[2] = 28