本文整理汇总了Python中time.struct_time函数的典型用法代码示例。如果您正苦于以下问题:Python struct_time函数的具体用法?Python struct_time怎么用?Python struct_time使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了struct_time函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_creates_item_from_given_data
def test_creates_item_from_given_data(self):
data = dict(
guid='http://news.com/rss/1234abcd',
published_parsed=struct_time([2015, 2, 25, 16, 45, 23, 2, 56, 0]),
updated_parsed=struct_time([2015, 2, 25, 17, 52, 11, 2, 56, 0]),
title='Breaking News!',
summary='Something happened...',
body_text='This is body text.',
author='author',
)
item = self.instance._create_item(data, source='source')
self.assertEqual(item.get('guid'), 'http://news.com/rss/1234abcd')
self.assertEqual(item.get('uri'), 'http://news.com/rss/1234abcd')
self.assertEqual(item.get('type'), 'text')
self.assertEqual(
item.get('firstcreated'), datetime(2015, 2, 25, 16, 45, 23))
self.assertEqual(
item.get('versioncreated'), datetime(2015, 2, 25, 17, 52, 11))
self.assertEqual(item.get('headline'), 'Breaking News!')
self.assertEqual(item.get('abstract'), 'Something happened...')
self.assertEqual(item.get('body_html'),
'<p><a href="http://news.com/rss/1234abcd" target="_blank">source</a></p>This is body text.')
self.assertEqual(item.get('byline'), 'author')
dateline = item.get('dateline', {})
self.assertEqual(dateline.get('source'), 'source')
self.assertEqual(dateline.get('date'), item.get('firstcreated'))
示例2: knox
def knox(x1, y1, t1, x2, y2, t2, dist_scale, time_scale_days, nrand=1000, verbose=True):
'''Compute the Knox test statistic:
X = # events near in space and time versus time-permuted'''
# First get rid of points where the spatial location is undefined.
t1leads=True
wh1 = np.where(~np.isnan(x1))
wh2 = np.where(~np.isnan(x2))
x1, y1, t1 = x1[wh1], y1[wh1], t1[wh1]
x2, y2, t2 = x2[wh2], y2[wh2], t2[wh2]
# Now compute the times in seconds for easy math.
t1 = np.array([time.mktime(time.struct_time(i)) for i in t1])
t2 = np.array([time.mktime(time.struct_time(i)) for i in t2])
time_scale = time_scale_days * 24 * 3600
# Determine the array sizes. We're going to be looping over (x1,y1,t1),
# so make sure that's the shorter of the two data sets to take maximal
# advantage of numpy's parallelization for vectorized operations.
Nd1 = len(t1)
Nd2 = len(t2)
if Nd1 > Nd2:
x3, y3, t3, Nd3 = x1, y1, t1, Nd1
x1, y1, t1, Nd1 = x2, y2, t2, Nd2
x2, y2, t2, Nd2 = x3, y3, t3, Nd3
t1leads = False
# Compute the test statistic for the real data and the randomized data.
X, randX = compute_test_statistic(x1, y1, t1, Nd1, x2, y2, t2, Nd2, \
dist_scale, time_scale, nrand=nrand, t1leads=t1leads, verbose=verbose)
# OK, we're done now.
return X, randX
示例3: main
def main():
# Script outline
#
# 1. When is the object visible from Paranal?
# 2. Is it visible within 4 hours after the trigger?
# 3. Is it visible long enough (~ 1hr)
RA = "23:18:11.57"
DEC = "32:28:31.8"
EQUINOX = "J2000"
# Format for my script = ?!? skycat!!!
#TRIGGER =
# Example usage
# Set the observatory information and calc twilights
GRB = CelestialObject()
GRB.setObservatory(siteabbrev='e')
intime = time.gmtime(time.time())
intime = time.struct_time(intime[0:9])
timestruct = time.struct_time(intime)
GRB.computeTwilights()
GRB.computeNightLength()
GRB.printInfo()
intime = intime[0:6]
print ""
print "Given date: %s-%s-%s\t %s:%s:%s UT" % (intime[0], intime[1], intime[2], intime[3], intime[4], intime[5])
示例4: test_inactive_date
def test_inactive_date(self):
## fixed day:
self.assertEqual(
OrgFormat.inactive_date(time.struct_time([1980,12,31,0,0,0,0,0,0])),
u'[1980-12-31 Wed]' )
## fixed time with seconds:
self.assertEqual(
OrgFormat.inactive_date(time.struct_time([1980,12,31,23,59,58,0,0,0]), 'foo'),
u'[1980-12-31 Wed 23:59]' ) ## seconds are not (yet) defined in Org-mode
## fixed time without seconds:
self.assertEqual(
OrgFormat.inactive_date(time.struct_time([1980,12,31,23,59,0,0,0,0]), 'foo'),
u'[1980-12-31 Wed 23:59]' )
YYYYMMDDwday = time.strftime('%Y-%m-%d %a', time.localtime())
hhmmss = time.strftime('%H:%M', time.localtime()) ## seconds are not (yet) defined in Org-mode
## simple form with current day:
self.assertEqual(
OrgFormat.inactive_date(time.localtime()),
u'[' + YYYYMMDDwday + u']' )
## show_time parameter not named:
self.assertEqual(
OrgFormat.inactive_date(time.localtime(), True),
u'[' + YYYYMMDDwday + u' ' + hhmmss + u']' )
## show_time parameter named:
self.assertEqual(
OrgFormat.inactive_date(time.localtime(), show_time=True),
u'[' + YYYYMMDDwday + u' ' + hhmmss + u']' )
示例5: test_does_not_use_body_text_populate_fallback_if_aliased
def test_does_not_use_body_text_populate_fallback_if_aliased(self):
class CustomDict(dict):
"""Customized dict class, allows adding custom attributes to it."""
data = CustomDict(
guid='http://news.com/rss/1234abcd',
published_parsed=struct_time([2015, 2, 25, 16, 45, 23, 2, 56, 0]),
updated_parsed=struct_time([2015, 2, 25, 17, 52, 11, 2, 56, 0]),
title='Breaking News!',
summary='Something happened...',
# NOTE: no body_text field
)
content_field = [
CustomDict(type='text/html', value='<p>This is body</p>')
]
content_field[0].value = '<p>This is body</p>'
data.content = content_field
field_aliases = [{'body_text': 'body_text_field_alias'}]
data.body_text_field_alias = None # simulate non-existing alias field
item = self.instance._create_item(data, field_aliases)
self.assertEqual(item.get('body_html'),
'<p><a href="http://news.com/rss/1234abcd" target="_blank">source</a></p>')
示例6: test_returns_items_built_from_retrieved_data
def test_returns_items_built_from_retrieved_data(self):
feed_parse.return_value = MagicMock(
entries=[
MagicMock(
updated_parsed=struct_time(
[2015, 2, 25, 17, 11, 11, 2, 56, 0])
),
MagicMock(
updated_parsed=struct_time(
[2015, 2, 25, 17, 22, 22, 2, 56, 0])
),
]
)
item_1 = dict(
guid='item_1',
firstcreated=datetime(2015, 2, 25, 17, 11, 11),
versioncreated=datetime(2015, 2, 25, 17, 11, 11),
)
item_2 = dict(
guid='item_2',
firstcreated=datetime(2015, 2, 25, 17, 22, 22),
versioncreated=datetime(2015, 2, 25, 17, 22, 22),
)
self.instance._create_item.side_effect = [item_1, item_2]
returned = self.instance._update(
{'last_updated': datetime(2015, 2, 25, 14, 0, 0)}
)
self.assertEqual(len(returned), 1)
items = returned[0]
self.assertEqual(items, [item_1, item_2])
示例7: test_creates_item_taking_field_name_aliases_into_account
def test_creates_item_taking_field_name_aliases_into_account(self):
data = dict(
guid='http://news.com/rss/1234abcd',
published_parsed=struct_time([2015, 2, 25, 16, 45, 23, 2, 56, 0]),
updated_parsed=struct_time([2015, 2, 25, 17, 52, 11, 2, 56, 0]),
title_field_alias='Breaking News!',
summary_field_alias='Something happened...',
body_text_field_alias='This is body text.',
)
field_aliases = [{'title': 'title_field_alias'},
{'summary': 'summary_field_alias'},
{'body_text': 'body_text_field_alias'}]
item = self.instance._create_item(data, field_aliases)
self.assertEqual(item.get('guid'), 'http://news.com/rss/1234abcd')
self.assertEqual(item.get('uri'), 'http://news.com/rss/1234abcd')
self.assertEqual(item.get('type'), 'text')
self.assertEqual(
item.get('firstcreated'), datetime(2015, 2, 25, 16, 45, 23))
self.assertEqual(
item.get('versioncreated'), datetime(2015, 2, 25, 17, 52, 11))
self.assertEqual(item.get('headline'), 'Breaking News!')
self.assertEqual(item.get('abstract'), 'Something happened...')
self.assertEqual(item.get('body_html'),
'<p><a href="http://news.com/rss/1234abcd" target="_blank">source</a></p>This is body text.')
示例8: test_inactive_date
def test_inactive_date(self):
## fixed day:
self.assertEqual(
OrgFormat.inactive_date(time.struct_time([1980,12,31,0,0,0,0,0,0])),
u'[1980-12-31 Mon]' ) ## however, it was a Wednesday
## fixed time with seconds:
self.assertEqual(
OrgFormat.inactive_date(time.struct_time([1980,12,31,23,59,58,0,0,0]), 'foo'),
u'[1980-12-31 Mon 23:59:58]' ) ## however, it was a Wednesday
## fixed time without seconds:
self.assertEqual(
OrgFormat.inactive_date(time.struct_time([1980,12,31,23,59,0,0,0,0]), 'foo'),
u'[1980-12-31 Mon 23:59]' ) ## however, it was a Wednesday
YYYYMMDDwday = time.strftime('%Y-%m-%d %a', time.localtime())
hhmmss = time.strftime('%H:%M:%S', time.localtime())
## simple form with current day:
self.assertEqual(
OrgFormat.inactive_date(time.localtime()),
u'[' + YYYYMMDDwday + u']' )
## show_time parameter not named:
self.assertEqual(
OrgFormat.inactive_date(time.localtime(), True),
u'[' + YYYYMMDDwday + u' ' + hhmmss + u']' )
## show_time parameter named:
self.assertEqual(
OrgFormat.inactive_date(time.localtime(), show_time=True),
u'[' + YYYYMMDDwday + u' ' + hhmmss + u']' )
示例9: _parse_gpgga
def _parse_gpgga(self, args):
# Parse the arguments (everything after data type) for NMEA GPGGA
# 3D location fix sentence.
data = args.split(',')
if data is None or len(data) != 14:
return # Unexpected number of params.
# Parse fix time.
time_utc = int(_parse_float(data[0]))
if time_utc is not None:
hours = time_utc // 10000
mins = (time_utc // 100) % 100
secs = time_utc % 100
# Set or update time to a friendly python time struct.
if self.timestamp_utc is not None:
self.timestamp_utc = time.struct_time((
self.timestamp_utc.tm_year, self.timestamp_utc.tm_mon,
self.timestamp_utc.tm_mday, hours, mins, secs, 0, 0, -1))
else:
self.timestamp_utc = time.struct_time((0, 0, 0, hours, mins,
secs, 0, 0, -1))
# Parse latitude and longitude.
self.latitude = _parse_degrees(data[1])
if self.latitude is not None and \
data[2] is not None and data[2].lower() == 's':
self.latitude *= -1.0
self.longitude = _parse_degrees(data[3])
if self.longitude is not None and \
data[4] is not None and data[4].lower() == 'w':
self.longitude *= -1.0
# Parse out fix quality and other simple numeric values.
self.fix_quality = _parse_int(data[5])
self.satellites = _parse_int(data[6])
self.horizontal_dilution = _parse_float(data[7])
self.altitude_m = _parse_float(data[8])
self.height_geoid = _parse_float(data[10])
示例10: test_buttgmt
def test_buttgmt(self):
self.receive_message('/buttgmt +3')
self.assertReplied('Timezone set to GMT+3')
self.test_buttmeon(status=u'''\
Butt enabled, use /buttmeoff to disable it.
Your timezone is set to *GMT+3*, use /buttgmt to change it.''')
import mock
import time
with mock.patch(
'time.gmtime',
return_value=time.struct_time((2016, 1, 18, 9, 50, 36, 0, 18, 0))
):
self.clear_queues()
self.plugin.cron_go('instagram.butt')
self.assertNoReplies()
with mock.patch(
'time.gmtime',
return_value=time.struct_time((2016, 1, 18, 6, 50, 36, 0, 18, 0))
):
self.plugin.cron_go('instagram.butt')
self.assertEqual(self.pop_reply()[1]['caption'], 'Good morning!')
self.receive_message('/buttgmt -5')
self.assertReplied('Timezone set to GMT-5')
with mock.patch(
'time.gmtime',
return_value=time.struct_time((2016, 1, 18, 18, 50, 36, 0, 18, 0))
):
self.plugin.cron_go('instagram.butt')
self.assertEqual(self.pop_reply()[1]['caption'], 'Bon appetit!')
示例11: checkMakeNewFileName
def checkMakeNewFileName(self):
'''
Routine to check if we need a new filename and to create one if so.
Uses the increment flag (default is daily) to determine how often to
create a new file.
2014-07-17 C. Wingard Added code to create files based on either
daily or hourly increments. Adds time to base
file name.
'''
time_value = gmtime()
time_string = strftime('%Y%m%dT%H%M', time_value) + '_UTC.dat'
if self.increment == 'hourly':
# check if the hour of the day has changed or if this is the first
# time we've run this (e.g. hourOfDay == -1)
if self.hourOfDay != struct_time(time_value).tm_hour:
# create a new filename string
self.fileName = self.basename + '_' + time_string
# update current day of month
self.hourOfDay = struct_time(time_value).tm_hour
if self.increment == 'daily':
# check if the day of month has changed or if this is the first
# time we've run this (e.g. dayOfMonth == -1)
if self.dayOfMonth != struct_time(time_value).tm_mday:
# create a new filename string
self.fileName = self.basename + '_' + time_string
# update current day of month
self.dayOfMonth = struct_time(time_value).tm_mday
示例12: get_today_condition
def get_today_condition(user):
now_time = time.localtime()
last_time = time.mktime(time.struct_time([now_time.tm_year, now_time.tm_mon, now_time.tm_mday, 0, 0, 0, 0, 0, 0])) - 12 * 3600
today = now_time.tm_mday
last_time = time.localtime(last_time)
start_time = process_num(last_time.tm_year) + "-" + process_num(last_time.tm_mon) + "-" + process_num(last_time.tm_mday) + " " + process_num(last_time.tm_hour) + ":" + process_num(last_time.tm_min) + ":" + process_num(last_time.tm_sec)
end_time = process_num(now_time.tm_year) + "-" + process_num(now_time.tm_mon) + "-" + process_num(now_time.tm_mday) + " " + process_num(now_time.tm_hour) + ":" + process_num(now_time.tm_min) + ":" + process_num(now_time.tm_sec)
data = get_data(["user", 'startTime', 'endTime', 'type', 'distance', 'calories', 'steps', 'subType', 'actTime', 'nonActTime', 'dsNum', 'lsNum', 'wakeNum', 'wakeTimes', 'score'], start_time, end_time, user.id, raw=True)
i = 0
length = len(data)
while data[i]["endTime"].split('-')[2].split(' ')[0] != str(today) and i < length:
data.pop(0)
new_data = integrate_by_class(data)
calculate_time(new_data)
new_data.pop(0)
time_first = new_data[0]["endTime"].split('-')[2].split(' ')[1].split(':')
time_first = time.mktime(time.struct_time([now_time.tm_year, now_time.tm_mon, now_time.tm_mday, int(time_first[0]), int(time_first[1]), int(time_first[2]), 0, 0, 0]))
time_00 = time.mktime(time.struct_time([now_time.tm_year, now_time.tm_mon, now_time.tm_mday, 0, 0, 0, 0, 0, 0]))
rate = float(time_first - time_00) / new_data[0]["allTime"]
new_data[0]["allTime"] -= (time_first - time_00)
new_data[0]["startTime"] = (str(now_time.tm_year) + "-" + str(now_time.tm_mon) + "-" + str(now_time.tm_mday) + " " + "00:00:00").encode("utf-8")
new_data[0]["distance"] = int(new_data[0]["distance"] * rate)
new_data[0]["steps"] = int(new_data[0]["steps"] * rate)
new_data[0]["calories"] = int(new_data[0]["calories"] * rate)
new_data[0]["dsNum"] = int(new_data[0]["dsNum"] * rate)
new_data[0]["sleepNum"] = int(new_data[0]["sleepNum"] * rate)
return new_data
示例13: test_old_due_date_format
def test_old_due_date_format(self):
current = datetime.datetime.today()
self.assertEqual(
time.struct_time((current.year, 3, 12, 12, 0, 0, 1, 71, 0)),
DateTest.date.from_json("March 12 12:00"))
self.assertEqual(
time.struct_time((current.year, 12, 4, 16, 30, 0, 2, 338, 0)),
DateTest.date.from_json("December 4 16:30"))
示例14: align_sleep_time
def align_sleep_time():
now_time = time.localtime()
if now_time.tm_hour > 12 or (now_time.tm_hour == 12 and now_time.tm_min > 1):
next_time = time.mktime(time.struct_time([now_time.tm_year, now_time.tm_mon, now_time.tm_mday, 12, 1, 0, 0, 0, 0]))
next_time += 24 * 3600
else:
next_time = time.mktime(time.struct_time([now_time.tm_year, now_time.tm_mon, now_time.tm_mday, 12, 1, 0, 0, 0, 0]))
return (next_time - time.time())
示例15: _strict_date
def _strict_date(self, lean):
py = self._precise_year()
if lean == EARLIEST:
return struct_time(
[py, 1, 1] + TIME_EMPTY_TIME + TIME_EMPTY_EXTRAS)
else:
return struct_time(
[py, 12, 31] + TIME_EMPTY_TIME + TIME_EMPTY_EXTRAS)