Python time 模块,year() 实例源码

我们从Python开源项目中,提取了以下9个代码示例,用于说明如何使用time.year()

项目:webnull    作者:macrael    | 项目源码 | 文件源码
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)
项目:Malicious_Domain_Whois    作者:h-j-13    | 项目源码 | 文件源码
def update_redis():
    get_black_name(1)
    get_black_tel(1)
    get_black_email(1)
    get_malicious_domain_whois(1)
    get_malicious_sponsoring_registrar()
    get_malicious_tld()
    get_ip_frequency()
    get_exist_situation()
    get_update_situation()
    for year in range(2007, 2018):
        get_c_e_data(year)
项目:GHCitySim    作者:gperonato    | 项目源码 | 文件源码
def getComponentVersion(self):
        monthDict = {'JAN':'01', 'FEB':'02', 'MAR':'03', 'APR':'04', 'MAY':'05', 'JUN':'06',
                     'JUL':'07', 'AUG':'08', 'SEP':'09', 'OCT':'10', 'NOV':'11', 'DEC':'12'}
        # convert component version to standard versioning
        ver, verDate = ghenv.Component.Message.split("\n")
        ver = ver.split(" ")[1].strip()
        month, day, year = verDate.split("_")
        month = monthDict[month.upper()]
        version = ".".join([year, month, day, ver])
        return version
项目:GHCitySim    作者:gperonato    | 项目源码 | 文件源码
def getVersion(self, LBComponentMessage):
        monthDict = {'JAN':'01', 'FEB':'02', 'MAR':'03', 'APR':'04', 'MAY':'05', 'JUN':'06',
                     'JUL':'07', 'AUG':'08', 'SEP':'09', 'OCT':'10', 'NOV':'11', 'DEC':'12'}
        # convert component version to standard versioning
        try: ver, verDate = LBComponentMessage.split("\n")
        except: ver, verDate = LBComponentMessage.split("\\n")
        ver = ver.split(" ")[1].strip()
        month, day, year = verDate.split("_")
        month = monthDict[month.upper()]
        version = ".".join([year, month, day, ver])
        return version
项目:GHCitySim    作者:gperonato    | 项目源码 | 文件源码
def hour2Date(self, hour, alternate = False):
        numOfDays = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365]
        numOfHours = [24 * numOfDay for numOfDay in numOfDays]
        #print hour/24
        if hour%8760==0 and not alternate: return `31`+ ' ' + 'DEC' + ' 24:00'
        elif hour%8760==0: return 31, 11, 24

        for h in range(len(numOfHours)-1):
            if hour <= numOfHours[h+1]: month = self.monthList[h]; break
        try: month
        except: month = self.monthList[h] # for the last hour of the year

        if (hour)%24 == 0:
            day = int((hour - numOfHours[h]) / 24)
            time = `24` + ':00'
            hour = 24
        else:
            day = int((hour - numOfHours[h]) / 24) + 1
            minutes = `int(round((hour - math.floor(hour)) * 60))`
            if len(minutes) == 1: minutes = '0' + minutes
            time = `int(hour%24)` + ':' + minutes
        if alternate:
            time = hour%24
            if time == 0: time = 24
            month = self.monthList.index(month)
            return day, month, time

        return (`day` + ' ' + month + ' ' + time)
项目:GHCitySim    作者:gperonato    | 项目源码 | 文件源码
def selectHourlyData(self, hourlyData, analysisPeriod):
        # separate data
        indexList, listInfo = self.separateList(hourlyData, self.strToBeFound)

        #separate lists of lists
        separatedLists = []
        for i in range(len(indexList)-1):
            selList = []
            [selList.append(float(x)) for x in hourlyData[indexList[i]+7:indexList[i+1]]]
            separatedLists.append(selList)

        # read analysis period
        stMonth, stDay, stHour, endMonth, endDay, endHour = self.readRunPeriod(analysisPeriod)

        selHourlyData =[];

        for l in range(len(separatedLists)):
            [selHourlyData.append(item) for item in listInfo[l][:4]]
            selHourlyData.append('Hourly')
            selHourlyData.append((stMonth, stDay, stHour))
            selHourlyData.append((endMonth, endDay, endHour))
            # select data
            stAnnualHour = self.date2Hour(stMonth, stDay, stHour)
            endAnnualHour = self.date2Hour(endMonth, endDay, endHour)

            # check it goes from the end of the year to the start of the year
            if stAnnualHour < endAnnualHour:
                for i, item in enumerate(separatedLists[l][stAnnualHour-1:endAnnualHour]):
                    if stHour-1 <= (i + stHour - 1)%24 <= endHour-1: selHourlyData.append(item)
                type = True
            else:
                for i, item in enumerate(separatedLists[l][stAnnualHour-1:]):
                    if stHour-1 <= (i + stHour - 1)%24 <= endHour-1: selHourlyData.append(item)

                for i, item in enumerate(separatedLists[l][:endAnnualHour]):
                    if stHour-1 <= i %24 <= endHour-1: selHourlyData.append(item)
                type = False

        return selHourlyData
项目:GHCitySim    作者:gperonato    | 项目源码 | 文件源码
def createSky(self, doy, year, hour, timeZone, latitude, longitude, turbidity):
        self.doy = doy
        self.year = year
        self.hour = hour
        self.timeZone = timeZone
        self.latitude = latitude
        self.longitude = longitude
        self.turbidity = turbidity

        self.sun = Sun()
        self.setTime()
        self.setSunPosition()
        self.setZenitalAbsolutes()
        self.setCoefficents()
项目:GHCitySim    作者:gperonato    | 项目源码 | 文件源码
def setTime(self):
        self.time = self.hour

        self.julianDay = self.doy
        y = self.year + 4800

        self.julianDay += (self.time - self.timeZone)/24.0  + 365*y + math.floor(y/4) \
            - math.floor(y/100) + math.floor(y/400) - 32045.5 - 59
项目:Malicious_Domain_Whois    作者:h-j-13    | 项目源码 | 文件源码
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??????????????   ?????