Python time.month() Examples

The following are code examples for showing how to use time.month(). They are extracted from open source Python projects. You can vote up the examples you like or vote down the ones you don't like. You can also save this page to your account.

Example 1
Project: webnull   Author: macrael   File: webnull.py    (license) View Source Project 6 votes vote down vote up
def pretty_time(time, now=datetime.datetime.now()):
    tomorrow = now + datetime.timedelta(days=1)
    next_day = now + datetime.timedelta(days=2)
    next_week = now + datetime.timedelta(weeks=1)
    pretty_fmt = '%-I:%M %p'
    pretty_prefix = ''
    if tomorrow < time < next_day:
        pretty_prefix = 'tomorrow at '
    elif time > next_day and time < next_week:
        pretty_prefix = '%A at '
    elif time > next_week and time.month == now.month and time.year == now.year:
        pretty_prefix = '%A the %-d' + pretty_suffix(time.day) + ' at '
    elif time > next_week and time.year == now.year:
        pretty_prefix = '%B %-d' + pretty_suffix(time.day) + ' at '
    elif time > next_week:
        pretty_prefix = '%B %-d' + pretty_suffix(time.day) + ' %Y at '

    return time.strftime(pretty_prefix + pretty_fmt) 
Example 2
Project: live_scoreboard   Author: ClysmiC   File: live_scoreboard.py    (license) View Source Project 6 votes vote down vote up
def update(self):
        self.canvas.delete("updates")
        self.show()

        if self.game["status"] == "Pre":
            topString = "{:3s} @ {:3s}".format(self.game["away"]["name"], self.game["home"]["name"])

            ast = self.game["adjustedStartTime"]

            
            if TWENTY_FOUR_HOUR_CLOCK:
                botString = "{:s} {:d}, {:02d}:{:02d}".format(months[ast.month], ast.day, ast.hour, ast.minute)
            else:
                hour, suffix = toTwelveHourClock(ast)
                botString = "{:s} {:d}, {:02d}:{:02d} {:s}".format(months[ast.month], ast.day, hour, ast.minute, suffix)


            awayLogo = self.scaledLogos[self.game["away"]["name"]]
            homeLogo = self.scaledLogos[self.game["home"]["name"]]

            # Center logo
            awayLogoXOffset = (self.awayLogoRegion.width - awayLogo.width()) // 2
            awayLogoYOffset = (self.awayLogoRegion.height - awayLogo.height()) // 2
            
            homeLogoXOffset = (self.homeLogoRegion.width - homeLogo.width()) // 2
            homeLogoYOffset = (self.homeLogoRegion.height - homeLogo.height()) // 2

            lineY = self.lineYStart

            self.canvas.create_image((self.awayLogoRegion.left + awayLogoXOffset, self.awayLogoRegion.top + awayLogoYOffset), anchor=tk.NW, image=awayLogo, tags="updates")
            self.canvas.create_image((self.homeLogoRegion.left + homeLogoXOffset, self.homeLogoRegion.top + homeLogoYOffset), anchor=tk.NW, image=homeLogo, tags="updates")
            
            self.canvas.create_text((self.topX, lineY), anchor=tk.NW, text=topString, font=self.font, fill=fontColor, tags="updates")

            lineY += self.lineHeight

            self.canvas.create_text((self.botX, lineY), anchor=tk.NW, text=botString, font=self.font, fill=fontColor, tags="updates")
        else:
            self.canvas.create_text((self.width // 2, self.height //2), anchor=tk.CENTER, text="No games found...", font=self.font, fill=fontColor, tags="updates") 
Example 3
Project: piecewisecrf   Author: Vaan5   File: train.py    (license) View Source Project 5 votes vote down vote up
def get_time_string():
    '''

    Returns current time in day_month_HH-MM-SS/ format

    '''
    time = datetime.now()
    name = (str(time.day) + '_' + str(time.month) + '_%02d' % time.hour +
            '-%02d' % time.minute + '-%02d' % time.second + '/')
    return name 
Example 4
Project: live_scoreboard   Author: ClysmiC   File: live_scoreboard.py    (license) View Source Project 5 votes vote down vote up
def update(self):
        self.canvas.delete("updates")

        string1 = daysOfWeek[self.dateAndTime.weekday()] + ", " + months[self.dateAndTime.month] + " " + str(self.dateAndTime.day)

        if TWENTY_FOUR_HOUR_CLOCK:
            string2 = "{:02d}:{:02d}:{:02d}".format(self.dateAndTime.hour, self.dateAndTime.minute, self.dateAndTime.second)
        else:
            hour, suffix = toTwelveHourClock(self.dateAndTime)
            string2 = "{:02d}:{:02d}:{:02d} {:s}".format(hour, self.dateAndTime.minute, self.dateAndTime.second, suffix)

        self.canvas.create_text((self.width // 2, self.height * .30), text=string1, fill=fontColor, font=self.font, tags="updates")
        self.canvas.create_text((self.width // 2, self.height * .70), text=string2, fill=fontColor, font=self.font, tags="updates") 
Example 5
Project: Malicious_Domain_Whois   Author: h-j-13   File: get_data1.py    (license) View Source Project 4 votes vote down vote up
def get_c_e_data(chooseyear):

    date_data = dict(year=[{"name":"??", "cValue":0, "eValue":0}, {"name":"??", "cValue":0, "eValue":0}, {"name":"??", "cValue":0, "eValue":0}, {"name":"??", "cValue":0, "eValue":0}, {"name":"??", "cValue":0, "eValue":0}, {"name":"??", "cValue":0, "eValue":0}, {"name":"??", "cValue":0, "eValue":0}, {"name":"??", "cValue":0, "eValue":0}, {"name":"??", "cValue":0, "eValue":0}, {"name":"??", "cValue":0, "eValue":0}, {"name":"???", "cValue":0, "eValue":0}, {"name":"???", "cValue":0, "eValue":0}], c_date=[], e_date=[])

    standard_year = 2003
    for year in range(standard_year, chooseyear+1):
        date_data['c_date'].append({"name": year,"value":0})
        date_data['e_date'].append({"name": year, "value": 0})

    data = whois.select(whois.creation_date).where(whois.creation_date != '')
    for date in data:
        try:
            try:
                time = arrow.get(date.creation_date, 'DD-MMM-YYYY')
                date_data['c_date'][time.year-standard_year]['value'] += 1
                if time.year == chooseyear:
                    date_data['year'][time.month-1]["cValue"] += 1

            except:
                time = arrow.get(date.creation_date)
                date_data['c_date'][time.year - standard_year]['value'] += 1
                if time.year == chooseyear:
                    date_data['year'][time.month - 1]["cValue"] += 1

        except:
            pass

    data1 = whois.select(whois.expiration_date).where(whois.expiration_date != '')

    for date in data1:
        try:
            try:
                time = arrow.get(date.expiration_date, 'DD-MMM-YYYY')
                date_data['e_date'][time.year - standard_year]['value'] += 1
                if time.year == chooseyear:
                    date_data['year'][time.month - 1]["eValue"] += 1

            except:
                time = arrow.get(date.expiration_date)
                date_data['e_date'][time.year - standard_year]['value'] += 1
                if time.year == chooseyear:
                    date_data['year'][time.month - 1]["eValue"] += 1

        except:
            pass

    return json.dumps(date_data, ensure_ascii=False)

# 4.2??????????????   ????? 
Example 6
Project: live_scoreboard   Author: ClysmiC   File: live_scoreboard.py    (license) View Source Project 4 votes vote down vote up
def update(self):
        self.canvas.delete("updates")

        self.textY = 0
        lastDateLabelDay = None
        firstHour = True

        for hour in self.weather:
            time = hour["time"]
            if time.day != lastDateLabelDay:
                dayString = months[time.month] + " " + str(time.day)
                
                # New lines
                if lastDateLabelDay is not None:
                    self.textY += self.lineHeight

                self.textY += self.lineHeight

                dayTextOffset = self.font.measure("  ")
                textPosition = (max(0, self.textX - dayTextOffset), self.textY)
                self.canvas.create_text(textPosition, anchor=tk.NW, text=dayString, font=self.underlinedFont, fill=fontColor, tags="updates")

                self.textY += self.lineHeight * 1.2 # just a little extra padding here looks better
                lastDateLabelDay = time.day

            if TWENTY_FOUR_HOUR_CLOCK:
                hourString = " {:02d}:{:02d}".format(time.hour, time.minute) + " - " + "{:>3s}".format(hour["temp"]) + " F "
            else:
                timeHour, suffix = toTwelveHourClock(time)
                hourString = " {:02d}:{:02d} {:s}".format(timeHour, time.minute, suffix) + " - " + "{:>3s}".format(hour["temp"]) + " F "

            hourFontColor = fontColor
            if firstHour:
                hourFontColor = "black"

                # draw a yellowish highlight on the current hour
                highlightColor = '#FFFF99'

                highlightX1 = self.textX
                highlightY1 = self.textY - ((self.lineHeight - self.fontHeight) / 2)
                highlightX2 = highlightX1 + self.font.measure(hourString)
                highlightY2 = highlightY1 + self.lineHeight

                self.canvas.create_rectangle((highlightX1, highlightY1, highlightX2, highlightY2), fill=highlightColor, tags="updates")

            self.canvas.create_text((self.textX, self.textY), anchor=tk.NW, text=hourString, font=self.font, fill=hourFontColor, tags="updates")


            icon = self.weatherIcons[hour["condition"]]
            self.canvas.create_image((self.iconX, self.textY), anchor=tk.NW, image=icon, tags="updates")

            self.textY += self.lineHeight
            firstHour = False