예제 #1
0
def PCAL_DisplayGotoDate(jalalidate):
    """
    extensions to use:
    persian [OK] , english [OK] , info [OK] , events [OK]
    """
    # =>init vars
    lang = None
    lg = None
    weekday = 0
    interval = 0
    postinterval = 'days'
    # =>check lang option
    lg = Glob.options['lang']
    if lg == 'fa':
        lang = fa
    elif lg == 'en':
        lang = en
    # =>if info is true
    if Glob.options['info'] == 'true':
        # =>print calendar
        __DisplayMonthCalendar(jalalidate, lang)
        # =>convert jalali to gregory
        gregory = convert.JalaliToGregorian(jalalidate['y'], jalalidate['m'],
                                            jalalidate['d'])
        endate = gregory.getGregorianList()
        # =>get weekday
        goto = datetime.datetime(endate['y'], endate['m'], endate['d'])
        weekday = common.PCAL_NormalizeWeekday(goto.weekday())
        # =>calc interval
        today = datetime.datetime.today()
        interval = common.PCAL_CalculateInterval(
            {
                'y': today.year,
                'm': today.month,
                'd': today.day
            }, endate)
        # print(interval)
        # =>check if year is leap
        leapyear = ''
        if common.PCAL_IsLeapYear(jalalidate['y']):
            leapyear = "({})".format(lang['dictionary']['leapyear'])
        # =>print info
        print("{} {} {} {} {} {} {} {}\n{}".format(
            lang['dictionary']['thatday'], lang['weekdays'][weekday],
            common.PCAL_LocalNumber(jalalidate['d'],
                                    lg), lang['months'][jalalidate['m'] - 1],
            common.PCAL_LocalNumber(jalalidate['y'],
                                    lg), lang['dictionary']['equal'],
            "{}/{}/{}".format(endate['y'], endate['m'], endate['d']), leapyear,
            "{} : {}".format(
                lang['dictionary']['interval'],
                common.PCAL_CalculateHumanlyInterval(interval, lang,
                                                     interval['sign']))))

    else:
        __DisplayMonthCalendar(jalalidate, lang)
    #=>if event is true
    if Glob.options['event'] == 'true':
        print()
        PCAL_DisplayEventsList(jalalidate, lang)
예제 #2
0
def PCAL_DisplayToday():
    """
    extensions to use:
    persian [OK] , english [OK] , info [OK] , events [OK]
    """
    # =>init vars
    lang = None
    jalalidate = {}
    tablecol1 = []
    tablecol2 = []
    maxcol1width = 10
    # =>get today from datetime
    today = datetime.datetime.today()
    # =>convert datetime to jalali
    jalali = convert.GregorianToJalali(today.year, today.month, today.day,
                                       today.weekday())
    jalalidate = jalali.getJalaliList()
    if Glob.DEBUG_MODE:
        print(jalalidate)
    # =>check lang option
    lg = Glob.options['lang']
    if lg == 'fa':
        lang = fa
    elif lg == 'en':
        lang = en
    # =>if info is true
    if Glob.options['info'] == 'true':
        # =>check if year is leap
        leapyear = ''
        if common.PCAL_IsLeapYear(jalalidate['y']):
            leapyear = "({})".format(lang['dictionary']['leapyear'])
        # =>print info
        print("{} {} {} {} {} {} {} {}".format(
            lang['dictionary']['today'], lang['weekdays'][jalalidate['w']],
            common.PCAL_LocalNumber(jalalidate['d'],
                                    lg), lang['months'][jalalidate['m'] - 1],
            common.PCAL_LocalNumber(jalalidate['y'],
                                    lg), lang['dictionary']['equal'],
            "{}/{}/{}".format(today.year, today.month, today.day), leapyear))

    else:
        print("{}/{}/{}".format(common.PCAL_LocalNumber(jalalidate['y'], lg),
                                common.PCAL_LocalNumber(jalalidate['m'], lg),
                                common.PCAL_LocalNumber(jalalidate['d'], lg)))

    # =>if event is true
    if Glob.options['event'] == 'true':
        print()
        PCAL_DisplayEventsList(jalalidate, lang)
예제 #3
0
def PCAL_DisplayYear():
    """
    extensions to use:
    persian [OK] , english [OK]
    """
    # =>init vars
    lang = None
    months = []
    maxcols = 3
    splitwidth = '    '  # 4 spaces
    monthindex = 0
    maxcalendarheight = 8
    calendarwidth = 21
    # =>check lang option
    lg = Glob.options['lang']
    if lg == 'fa':
        lang = fa
    elif lg == 'en':
        lang = en
    # =>get curent year from datetime
    today = datetime.datetime.today()
    # =>convert datetime to jalali
    jalali = convert.GregorianToJalali(today.year, today.month, today.day)
    jalalidate = jalali.getJalaliList()
    # =>#TODO:
    for i in range(1, 13, 1):
        # =>create new date for next month for printing
        if i == jalalidate['m']:
            nextmonthdate = {
                'y': jalalidate['y'],
                'm': i,
                'd': jalalidate['d']
            }
        else:
            nextmonthdate = {'y': jalalidate['y'], 'm': i, 'd': 0}
        # =>get month calendar as string, no print it!
        months.append(
            __DisplayMonthCalendar(nextmonthdate, lang, "string").split('\n'))
    # =>print year on center
    yeartitle = str(common.PCAL_LocalNumber(jalalidate['y'], lg))
    totalwidth = calendarwidth * maxcols + len(splitwidth) * maxcols - len(
        splitwidth)
    print(Glob.TerminalColors.GREENBOLD + yeartitle.center(totalwidth, ' '))
    print('----::::::::::----'.center(totalwidth, ' ') + '\n' +
          Glob.TerminalColors.NORMAL)
    # =>print month calendars in 3x4 cols and rows
    for i in range(0, int(12 / maxcols), 1):
        row = ''
        # =>TODO:
        for k in range(0, maxcalendarheight, 1):
            for j in range(0, maxcols, 1):
                if k >= len(months[monthindex + j]) or len(
                        months[monthindex + j][k]) == 0:
                    row += ''.center(calendarwidth, ' ')
                else:
                    row += months[monthindex + j][k]
                row += splitwidth
            row += '\n'
        print(row)
        monthindex += maxcols
예제 #4
0
def __DisplayMonthCalendar(jalalidate, lang, mode="print"):
    # =>init vars
    calendarwidth = 20
    maxheight = 6
    daymonth = 0
    lastday = 0
    startweekday = 0
    output = io.StringIO()
    lg = lang['lang']
    today = datetime.datetime.today()
    # =>get startweekday
    gregory = convert.JalaliToGregorian(jalalidate['y'], jalalidate['m'], 1)
    gregorylist = gregory.getGregorianList()
    firstday = today.replace(year=gregorylist['y'],
                             month=gregorylist['m'],
                             day=gregorylist['d'])
    startweekday = common.PCAL_NormalizeWeekday(firstday.weekday())
    # =>get lastday
    # =>test for 30
    if not common.PCAL_ValidateJalaliDate(jalalidate['y'], jalalidate['m'],
                                          30):
        lastday = 29
    # =>test for 31
    elif not common.PCAL_ValidateJalaliDate(jalalidate['y'], jalalidate['m'],
                                            31):
        lastday = 30
    else:
        lastday = 31
    # =>print for debug mode
    if Glob.DEBUG_MODE:
        print(jalalidate, firstday, lastday, startweekday, gregorylist)
    # =>print in center month name
    monthname = "{} {}".format(lang['months'][jalalidate['m'] - 1],
                               common.PCAL_LocalNumber(jalalidate['y'], lg))
    print(Glob.TerminalColors.CYANBOLD + monthname.center(calendarwidth, ':') +
          Glob.TerminalColors.NORMAL,
          end=' \n',
          file=output)
    # print weekdays names
    print(Glob.TerminalColors.OKBLUE, end='', file=output)
    for i in range(0, 7, 1):
        print(lang['weekdays'][i][0:2], sep='', end=' ', file=output)
    print(Glob.TerminalColors.NORMAL, end='', file=output)
    # print('\n'+''.center(width,'-'))
    print(file=output)
    # =>print month days
    for i in range(0, maxheight, 1):
        for j in range(0, 7, 1):
            # =>print empty if is before startweekday or after lastday
            if (daymonth == 0 and j < startweekday) or (daymonth == lastday):
                print('  ', end=' ', file=output)
            else:
                daymonth += 1
                eventtype = common.PCAL_ReturnEventsFromJalaliDay(
                    jalalidate['y'], jalalidate['m'], daymonth, True)
                # =>if day is current day, then selected by blue color
                if daymonth == jalalidate['d']:
                    print(Glob.TerminalColors.WHITEBLUE, end='', file=output)
                # =>if day is personal
                elif eventtype == 'personal':
                    print(Glob.PERSONAL_EVENT_COLOR, end='', file=output)
                # =>if day is holiday or jomøe (holiday by default)
                elif j == 6 or eventtype == 'holiday':
                    print(Glob.HOLIDAY_EVENT_COLOR, end='', file=output)
                # =>if day is occasion
                elif eventtype == 'occasion':
                    print(Glob.OCCASION_EVENT_COLOR, end='', file=output)
                # =>print day of month
                print('{:>2}'.format(common.PCAL_LocalNumber(daymonth, lg)),
                      end='',
                      file=output)
                # =>set normal style
                print(Glob.TerminalColors.NORMAL, end=' ', file=output)

        # =>go to new line
        print(file=output)
        # =>check if end day
        if daymonth >= lastday:
            break

    # =>print output or return output
    if mode == 'print':
        print(output.getvalue())
    elif mode == 'string':
        return output.getvalue()
    output.close()
예제 #5
0
def PCAL_DisplayEventsList(jalalidate,
                           lang,
                           maxcol1width=10,
                           mode='day',
                           drawtable=True):
    # =>init vars
    tablecol1 = []
    tablecol2 = []
    colorcol1 = []
    lg = lang['lang']
    # =>get events list of day
    events = common.PCAL_ReturnEventsFromJalaliDay(jalalidate['y'],
                                                   jalalidate['m'],
                                                   jalalidate['d'])
    # =>fill col1,col2 of table
    for i in range(0, len(events), 1):
        col1 = ''
        colord = ''
        #=>check type of event day for set a good color
        if events[i]['type'] == 'personal':
            colord = Glob.PERSONAL_EVENT_COLOR
        # =>if day is holiday or jomøe (holiday by default)
        elif events[i]['type'] == 'holiday':
            colord = Glob.HOLIDAY_EVENT_COLOR
        # =>if day is occasion
        elif events[i]['type'] == 'occasion':
            colord = Glob.OCCASION_EVENT_COLOR
        else:
            colord = Glob.TerminalColors.NORMAL
        #=>check if mode is month
        if mode == 'month':
            # =>make col1 text from type of event file and month and day date
            col1 = "{} {} ({})".format(
                common.PCAL_LocalNumber(jalalidate['d'], lg),
                lang['months'][jalalidate['m'] - 1],
                lang['dictionary'][events[i]['type']])
        # =>if mode is day
        elif mode == 'day':
            # =>make col1 text from name and type of event file
            col1 = "{} ({})".format(events[i]['name'].split('.')[0],
                                    lang['dictionary'][events[i]['type']])
        # =>reassign max col1 width for draw table
        if len(col1) > maxcol1width:
            maxcol1width = len(col1)
        #=> append to colorcol1 list, color of col1
        colorcol1.append(colord)
        # =>append to tablecol1,tablecol2 lists
        tablecol1.append(col1)
        tablecol2.append(events[i]['text'])
    # =>draw table if exist any events and if drawtable is true
    if drawtable:
        if len(tablecol1) > 0:
            PCAL_DisplayTable(lang['dictionary']['events'],
                              tablecol1,
                              tablecol2,
                              maxcol1width,
                              color1=colorcol1)
        # =>if not any event, then print message
        else:
            print(lang['dictionary']['no_event_thisday'])
    # =>if drawtable is false, then return all
    else:
        return {
            'maxcol1width': maxcol1width,
            'tablecol1': tablecol1,
            'tablecol2': tablecol2,
            'colorcol1': colorcol1
        }