Advertisement
tsounakis

Untitled

Dec 19th, 2019
332
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.54 KB | None | 0 0
  1. import calendar
  2.  
  3. class Gr_Calendar():
  4.     def __init__(self,year):
  5.         if type(year) is int:
  6.             self.year = calendar.calendar(year).replace(6*" "+str(year), "Ημερολόγιο "+str(year))
  7.             self.lexikon = {'April': 'Απρίλιος', 'June': 'Ιούνιος', 'July': 'Ιούλιος', 'January': 'Ιανουάριος',
  8.                             'March': 'Μάρτιος', 'November':'Νοέμβριος', 'February':'Φεβρουάριος','December':'Δεκέμβριος',
  9.                             'September': 'Σεπτέμβριος','May': 'Μάιος', 'October': 'Οκτώβριος', 'August': 'Αύγουστος'}
  10.             en_days = "Mo Tu We Th Fr Sa Su"
  11.             gr_days = "Δε Τρ Τε Πε Πα Σα Κυ"
  12.             self.year = self.year.replace(en_days, gr_days)
  13.             for month in self.lexikon:
  14.                 self.replace_center(month, self.lexikon[month])
  15.         else: self.year = ""
  16.        
  17.     def replace_center(self, m_en, m_gr):
  18.         l_en = len(m_en)
  19.         l_gr = len(m_gr)
  20.         l_dif = l_gr - l_en # Greek months longer than English in all cases
  21.         leading_spaces = l_dif//2
  22.         trailing_spaces = l_dif - leading_spaces
  23.         to_replace = leading_spaces * " " + m_en + trailing_spaces * " "
  24.         if to_replace not in self.year: # case of month at end of line, so no trailing spaces
  25.             to_replace = leading_spaces * " " + m_en
  26.         self.year = self.year.replace(to_replace, m_gr)
  27.  
  28.     def __str__(self):
  29.         return "\n"+self.year
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement