Romanius

Untitled

Feb 22nd, 2013
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.20 KB | None | 0 0
  1. #!/usr/bin/python
  2. # -*- coding: utf-8 -*-
  3.  
  4. import time
  5. import calendar
  6. from sys import *
  7.  
  8.  
  9.  
  10. cur_date = time.localtime()#time.strptime("25 Sep 13", "%d %b %y")
  11.  
  12. week_days = ["Пн", "Вт", "Ср", "Чт", "Пт", "Сб", "Вс"]
  13. months_names = ["Январь", "Февраль", "Март", "Апрель", "Май", "Июнь", "Июль", "Август", "Сентябрь", "Октябрь", "Ноябрь", "Декабрь"]
  14. #week_days = ["Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"]
  15.  
  16. month_weekdays = [0] * (calendar.mdays[cur_date.tm_mon])
  17.  
  18. # To past
  19.  
  20. cur_day = cur_date.tm_mday
  21. cur_weekday = cur_date.tm_wday
  22.  
  23. while cur_day != 0:
  24.  
  25.     if cur_weekday < 0:
  26.         cur_weekday = 6
  27.  
  28.     month_weekdays[cur_day - 1] = cur_weekday
  29.  
  30.     cur_day -= 1
  31.     cur_weekday -= 1
  32.  
  33. # To future
  34.  
  35. cur_day = cur_date.tm_mday
  36. cur_weekday = cur_date.tm_wday
  37.  
  38. while cur_day <= len(month_weekdays):
  39.    
  40.     if cur_weekday > 6:
  41.         cur_weekday = 0
  42.  
  43.     month_weekdays[cur_day - 1] = cur_weekday
  44.  
  45.     cur_day += 1
  46.     cur_weekday += 1
  47.  
  48. # Print output
  49.  
  50. # 28 - 4 = 24 - len
  51. months_names[cur_date.tm_mon - 1]
  52. stdout.write("\033[0;31m+")
  53. stdout.write("\033[0;36m-" * 2)
  54. stdout.write("\033[0;33m %s " % months_names[cur_date.tm_mon - 1])
  55. stdout.write("\033[0;36m-" * (24 - (months_names[cur_date.tm_mon - 1].__len__() / 2)))
  56. stdout.write("\033[0;31m+\n\033[0;36m|")
  57.  
  58. for wday in week_days:
  59.     stdout.write(" \033[0m%s " % wday)
  60.  
  61. stdout.write("\033[0;36m|\n")
  62.  
  63. stdout.write("\033[0;31m+")
  64. stdout.write("\033[0;36m-" * 28)
  65. stdout.write("\033[0;31m+\n")
  66.  
  67. for date in range(len(month_weekdays)):
  68.     if date == 0:
  69.         stdout.write("\033[0;36m|")
  70.         stdout.write(" " * (4 * month_weekdays[date]))
  71.  
  72.     if (date + 1) == cur_date.tm_mday:
  73.         stdout.write("\033[1;32m %02d \033[0m" % (date + 1))
  74.     else:
  75.         stdout.write("\033[0m %02d " % (date + 1))
  76.  
  77.     if date == len(month_weekdays) - 1 and month_weekdays[date] != 6:
  78.         stdout.write(" " * (4 * (6 - month_weekdays[date])))
  79.         stdout.write("\033[0;36m|")
  80.  
  81.     if month_weekdays[date] == 6:
  82.         if date == len(month_weekdays) - 1:
  83.             stdout.write("\033[0;36m|")
  84.         else:
  85.             stdout.write("\033[0;36m|\n|")
  86.  
  87. stdout.write("\n\033[0;31m+")
  88. stdout.write("\033[0;36m-" * 28)
  89. stdout.write("\033[0;31m+\n\033[0m")
Advertisement
Add Comment
Please, Sign In to add comment