Python time.month() Examples

The following are 8 code examples for showing how to use time.month(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.

You may check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module time , or try the search function .

Example 1
Project: rpi_ai   Author: schollz   File: visual_cortex.py    License: MIT License 6 votes vote down vote up
def saveImage():
	keepDiskSpaceFree(config.diskSpaceToReserve)
	time = datetime.datetime.now()
	filenameFull = config.filepath + config.filenamePrefix + "-%04d%02d%02d%02d%02d%02d" % (time.year, time.month, time.day, time.hour, time.minute, time.second)+ "." + config.fileType
	
	# save onto webserver
	filename = "/var/www/temp.jpg"
	subprocess.call("sudo raspistill -w "+ str(config.saveWidth) +" -h "+ str(config.saveHeight) + " -t 1 -n -vf -e " + config.fileType + " -q 15 -o %s" % filename, shell=True)
	print "Captured image: %s" % filename

	theSpeech = recognizeFace(filename,filenameFull)
	if len(theSpeech)>2:
		print theSpeech
		saySomething(theSpeech,"en")
		config.lookForFaces = 0


# Keep free space above given level 
Example 2
Project: augur   Author: nextstrain   File: frequency_estimators.py    License: GNU Affero General Public License v3.0 6 votes vote down vote up
def timestamp_to_float(time):
    """Convert a pandas timestamp to a floating point date.

    >>> import datetime
    >>> time = datetime.date(2010, 10, 1)
    >>> timestamp_to_float(time)
    2010.75
    >>> time = datetime.date(2011, 4, 1)
    >>> timestamp_to_float(time)
    2011.25
    >>> timestamp_to_float(datetime.date(2011, 1, 1))
    2011.0
    >>> timestamp_to_float(datetime.date(2011, 12, 1)) == (2011.0 + 11.0 / 12)
    True
    """
    return time.year + ((time.month - 1) / 12.0) 
Example 3
Project: fluids   Author: CalebBell   File: spa.py    License: MIT License 6 votes vote down vote up
def julian_day_dt(year, month, day, hour, minute, second, microsecond):
    """This is the original way to calculate the julian day from the NREL paper.
    However, it is much faster to convert to unix/epoch time and then convert
    to julian day. Note that the date must be UTC."""
    # Not used anywhere!
    if month <= 2:
        year = year-1
        month = month+12
    a = int(year/100)
    b = 2 - a + int(a * 0.25)
    frac_of_day = (microsecond + (second + minute * 60 + hour * 3600)
                   ) * 1.0 / (3600*24)
    d = day + frac_of_day
    jd = (int(365.25 * (year + 4716)) + int(30.6001 * (month + 1)) + d +
          b - 1524.5)
    return jd 
Example 4
Project: augur   Author: nextstrain   File: frequency_estimators.py    License: GNU Affero General Public License v3.0 5 votes vote down vote up
def float_to_datestring(time):
    """Convert a floating point date to a date string

    >>> float_to_datestring(2010.75)
    '2010-10-01'
    >>> float_to_datestring(2011.25)
    '2011-04-01'
    >>> float_to_datestring(2011.0)
    '2011-01-01'
    >>> float_to_datestring(2011.0 + 11.0 / 12)
    '2011-12-01'

    In some cases, the given float value can be truncated leading to unexpected
    conversion between floating point and integer values. This function should
    account for these errors by rounding months to the nearest integer.

    >>> float_to_datestring(2011.9166666666665)
    '2011-12-01'
    >>> float_to_datestring(2016.9609856262834)
    '2016-12-01'
    """
    year = int(time)

    # After accounting for the current year, extract the remainder and convert
    # it to a month using the inverse of the logic used to create the floating
    # point date. If the float date is sufficiently close to the end of the
    # year, rounding can produce a 13th month.
    month = min(int(np.rint(((time - year) * 12) + 1)), 12)

    # Floating point dates do not encode day information, so we always assume
    # they refer to the start of a given month.
    day = 1

    return "%s-%02d-%02d" % (year, month, day) 
Example 5
Project: piecewisecrf   Author: Vaan5   File: train.py    License: MIT License 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 6
Project: oggm   Author: OGGM   File: test_utils.py    License: BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
def test_date_to_floatyear(self):

        r = utils.date_to_floatyear(0, 1)
        self.assertEqual(r, 0)

        r = utils.date_to_floatyear(1, 1)
        self.assertEqual(r, 1)

        r = utils.date_to_floatyear([0, 1], [1, 1])
        np.testing.assert_array_equal(r, [0, 1])

        yr = utils.date_to_floatyear([1998, 1998], [6, 7])
        y, m = utils.floatyear_to_date(yr)
        np.testing.assert_array_equal(y, [1998, 1998])
        np.testing.assert_array_equal(m, [6, 7])

        yr = utils.date_to_floatyear([1998, 1998], [2, 3])
        y, m = utils.floatyear_to_date(yr)
        np.testing.assert_array_equal(y, [1998, 1998])
        np.testing.assert_array_equal(m, [2, 3])

        time = pd.date_range('1/1/1800', periods=300*12-11, freq='MS')
        yr = utils.date_to_floatyear(time.year, time.month)
        y, m = utils.floatyear_to_date(yr)
        np.testing.assert_array_equal(y, time.year)
        np.testing.assert_array_equal(m, time.month)

        myr = utils.monthly_timeseries(1800, 2099)
        y, m = utils.floatyear_to_date(myr)
        np.testing.assert_array_equal(y, time.year)
        np.testing.assert_array_equal(m, time.month)

        myr = utils.monthly_timeseries(1800, ny=300)
        y, m = utils.floatyear_to_date(myr)
        np.testing.assert_array_equal(y, time.year)
        np.testing.assert_array_equal(m, time.month)

        time = pd.period_range('0001-01', '6000-1', freq='M')
        myr = utils.monthly_timeseries(1, 6000)
        y, m = utils.floatyear_to_date(myr)
        np.testing.assert_array_equal(y, time.year)
        np.testing.assert_array_equal(m, time.month)

        time = pd.period_range('0001-01', '6000-12', freq='M')
        myr = utils.monthly_timeseries(1, 6000, include_last_year=True)
        y, m = utils.floatyear_to_date(myr)
        np.testing.assert_array_equal(y, time.year)
        np.testing.assert_array_equal(m, time.month)

        with self.assertRaises(ValueError):
            utils.monthly_timeseries(1) 
Example 7
Project: oggm   Author: OGGM   File: test_utils.py    License: BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
def test_hydro_convertion(self):

        # October
        y, m = utils.hydrodate_to_calendardate(1, 1, start_month=10)
        assert (y, m) == (0, 10)
        y, m = utils.hydrodate_to_calendardate(1, 4, start_month=10)
        assert (y, m) == (1, 1)
        y, m = utils.hydrodate_to_calendardate(1, 12, start_month=10)
        assert (y, m) == (1, 9)

        y, m = utils.hydrodate_to_calendardate([1, 1, 1], [1, 4, 12],
                                               start_month=10)
        np.testing.assert_array_equal(y, [0, 1, 1])
        np.testing.assert_array_equal(m, [10, 1, 9])

        y, m = utils.calendardate_to_hydrodate(1, 1, start_month=10)
        assert (y, m) == (1, 4)
        y, m = utils.calendardate_to_hydrodate(1, 9, start_month=10)
        assert (y, m) == (1, 12)
        y, m = utils.calendardate_to_hydrodate(1, 10, start_month=10)
        assert (y, m) == (2, 1)

        y, m = utils.calendardate_to_hydrodate([1, 1, 1], [1, 9, 10],
                                               start_month=10)
        np.testing.assert_array_equal(y, [1, 1, 2])
        np.testing.assert_array_equal(m, [4, 12, 1])

        # Roundtrip
        time = pd.period_range('0001-01', '1000-12', freq='M')
        y, m = utils.calendardate_to_hydrodate(time.year, time.month,
                                               start_month=10)
        y, m = utils.hydrodate_to_calendardate(y, m, start_month=10)
        np.testing.assert_array_equal(y, time.year)
        np.testing.assert_array_equal(m, time.month)

        # April
        y, m = utils.hydrodate_to_calendardate(1, 1, start_month=4)
        assert (y, m) == (0, 4)
        y, m = utils.hydrodate_to_calendardate(1, 4, start_month=4)
        assert (y, m) == (0, 7)
        y, m = utils.hydrodate_to_calendardate(1, 9, start_month=4)
        assert (y, m) == (0, 12)
        y, m = utils.hydrodate_to_calendardate(1, 10, start_month=4)
        assert (y, m) == (1, 1)
        y, m = utils.hydrodate_to_calendardate(1, 12, start_month=4)
        assert (y, m) == (1, 3)

        y, m = utils.hydrodate_to_calendardate([1, 1, 1], [1, 4, 12],
                                               start_month=4)
        np.testing.assert_array_equal(y, [0, 0, 1])
        np.testing.assert_array_equal(m, [4, 7, 3])

        # Roundtrip
        time = pd.period_range('0001-01', '1000-12', freq='M')
        y, m = utils.calendardate_to_hydrodate(time.year, time.month,
                                               start_month=4)
        y, m = utils.hydrodate_to_calendardate(y, m, start_month=4)
        np.testing.assert_array_equal(y, time.year)
        np.testing.assert_array_equal(m, time.month) 
Example 8
Project: Malicious_Domain_Whois   Author: h-j-13   File: get_data1.py    License: GNU General Public License v3.0 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恶意域名总体生存时间分布展示   横轴动态定