本文整理汇总了Python中utils.now函数的典型用法代码示例。如果您正苦于以下问题:Python now函数的具体用法?Python now怎么用?Python now使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了now函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: signin
def signin(db):
"""
登陆
"""
passwd = request.POST.get('passwd','')
db.execute('SELECT PASSWD FROM USER')
v, = db.getone()
if v != passwd:
return template("error",msg="密码错误")
#-设定cookie
token = md5sum('%s-%s' % (now(),random.random()*now()))
db.execute('INSERT INTO COOKIE(TOKEN) VALUES(%s)',token)
d = urlparse.urlparse(CFG.domain).netloc.split(':')[0]
response.set_cookie('token',token,path="/",expires=int(now()/1000)+3600*24*365,domain=d)
redirect("/",301)
开发者ID:D-L,项目名称:SimpleBookMarks,代码行数:15,代码来源:user.py
示例2: historicalData
def historicalData(self, reqId, date, open, high, low, close, volume,
count, WAP, hasGaps):
msg = {'type': 'historicalData', 'reqId': reqId, 'date': date,
'open': open, 'high': high, 'low': low, 'close': close,
'volume': volume, 'count': count, 'WAP': WAP,
'hasGaps': hasGaps, 'ts': now()}
self.msgs.put(msg)
开发者ID:bryntrader,项目名称:botty_mcbotface,代码行数:7,代码来源:wrapper.py
示例3: execute_download_and_extraction
def execute_download_and_extraction(config_filename):
config = ReceptionConfiguration(config_filename)
if config.is_valid:
print('running')
organizer = Organizer(config.serial_path, config.unidentified_path)
while config.status() == 'ON':
sleep = 0
if str(datetime.today().weekday()) in config.weekdays:
h = int(utils.now()[1][0:2])
if config.start_hour <= h <= config.end_hour:
receive_and_organize(config, organizer)
sleep = 60*config.frequency
elif h < config.start_hour:
sleep = 60*60*(config.start_hour - h)
elif h > config.end_hour:
sleep = 60*60*(24 - h + config.start_hour)
else:
# volta em 24h
sleep = 60*60*24
if sleep > 0:
print(sleep)
time.sleep(sleep)
print('stopped')
else:
print('configuration problem')
开发者ID:robertatakenaka,项目名称:PC-Programs,代码行数:26,代码来源:xml_reception.py
示例4: authenticate_token
def authenticate_token(self, email, token):
user = self.session.query(User).filter_by(email=email).first()
if user and user.token and user.tokendate:
if user.token == token and \
(utils.now()-user.tokendate) <= cfg.token_max_age:
return user
return None
开发者ID:swalladge,项目名称:snsrv,代码行数:7,代码来源:database.py
示例5: add_group
def add_group(self, title):
"""
Creates a new group and adds it to this group.
`title` is the title for the new group. It can't be None or empty string.
Returns the created group.
"""
if not title:
raise ValueError("title is not set.")
now = utils.now()
initargs = {
'group_id': groupid.generate(),
'title': title,
'creation': now,
'last_mod': now,
'last_access': now,
'image': 1,
'level': self.level + 1,
'parent': self,
}
group = Group(**initargs)
self._children.append(group)
return group
开发者ID:toikarin,项目名称:py-keepassx,代码行数:28,代码来源:kdbdatabase.py
示例6: update_feed
def update_feed(feed):
log.debug('Updating feed %d (%s)', feed['id'], feed['url'])
feed_fields_updates = {'lastcheck': utils.now()}
selectors = str(feed['selector']).splitlines()
res = htmlproc.get_prepared_html(feed['url'], selectors)
if 'error' in res:
if feed['lasterror'] == res['error']:
log.warn('Repeated error getting page content" %s', res['error'])
else:
log.warn('New error getting page content: %s', res['error'])
feed_fields_updates['lasterror'] = res['error']
model.add_feed_change(feed['id'], summary='Error getting page', details=res['error'], is_error=True)
else:
changes = htmlproc.get_web_safe_diff(feed['lastcontent'], res['txt'])
feed_fields_updates['lasterror'] = None
if not changes:
log.debug('Page not changed')
if feed['lasterror']:
model.add_feed_change(feed['id'], summary='Fixed getting page',
details='Page retreiving now works fine, no changes detected', is_error=True)
else:
log.debug('Page changed')
details = changes
summary = get_summary_from_diff(changes)
model.add_feed_change(feed['id'], details=details, is_error=False, summary=summary)
feed_fields_updates['lastcontent'] = res['txt']
model.update_feed(feed['id'], feed_fields_updates)
开发者ID:wladich,项目名称:page2feed,代码行数:28,代码来源:updater.py
示例7: generate_markdown_report
def generate_markdown_report(self, loop_start):
"""
Separate from the others as this logs to a sidebar rather than
a file
"""
s = self.session
land_report = StatusCommand.lands_status_for(s, self.config)
hq = self.reddit.get_subreddit(self.config.headquarters)
cur = now()
elapsed = (cur - loop_start) + self.config["bot"]["sleep"]
version_str = version(self.config)
bot_report = ("Bot Status:\n\n" "* Last run at %s\n\n" "* Seconds per Frame: %d\n\n" "* Version: %s") % (
timestr(cur),
elapsed,
version_str,
)
report = "%s\n\n%s" % (land_report, bot_report)
# This is apparently not immediately done, or there's some caching.
# Keep an eye on it.
hq.update_settings(description=report)
开发者ID:JBoggsy,项目名称:chromabot,代码行数:25,代码来源:main.py
示例8: test_got_moved
def test_got_moved(self):
"""Make sure you can't finish moving if you're warped"""
started = self.alice.region
londo = self.get_region("Orange Londo")
# For testing purposes, londo is now alice's
londo.owner = self.alice.team
# But she's at the fight
self.alice.region = self.get_region('sapphire')
order = self.alice.move(100, londo, 60 * 60 * 24)[0]
n = self.sess.query(db.MarchingOrder).count()
self.assertEqual(n, 1)
# The sapphire battle ends poorly for alice's team, and she gets
# booted out
self.alice.region = self.get_region('oraistedarg')
# Invoke the update routine to set everyone's location
order.arrival = now()
arrived = MarchingOrder.update_all(self.sess)
self.assert_(arrived)
# Alice should be back where she started, as the move isn't valid
self.assertEqual(started, self.alice.region)
n = self.sess.query(db.MarchingOrder).count()
self.assertEqual(n, 0)
开发者ID:JBoggsy,项目名称:chromabot,代码行数:28,代码来源:playtest.py
示例9: _wait_for_steps
def _wait_for_steps(self, num_of_steps_to_wait):
self.log.info("Waiting for steps...")
self._clear_camera_queue()
timestamp = utils.now()
while num_of_steps_to_wait > 0:
data = self.db.fetch_data(sid=FOOT_SENSOR_ID, since=timestamp)
timestamp = data[-1][0]
for data_pt in [x[2] for x in data]:
if self.sc.detect_step(data_pt) and GPIO.input(GPIO_OVERRIDE_PIN):
num_of_steps_to_wait -= 2
self.log.info("Step to go: %d", num_of_steps_to_wait)
if num_of_steps_to_wait < 6:
self.audio.prompt_step(num_of_steps_to_wait)
else:
self.audio.prompt_step()
if num_of_steps_to_wait <= 0:
break
try:
node_id = QUEUE.get_nowait()
if str(node_id) in self.path:
self.log.info("Captured node %s", node_id)
self.log.info("Resetting steps to 2")
num_of_steps_to_wait = 2
self.next_node_idx = self.path.index(str(node_id))
self.audio.prompt_camera()
except Empty:
continue
self.log.info("Completed steps")
开发者ID:KaranKamath,项目名称:CG3002,代码行数:28,代码来源:navigator.py
示例10: _report_event
def _report_event(self, event_m):
events = []
current = now()
for (k, v) in event_m.iteritems():
events.append(Event(timestamp=current, category=self._event_category, key=[k, self._hostname], value=v))
if events:
self._reporter.add_events(events)
开发者ID:yancl,项目名称:collectd,代码行数:7,代码来源:aggregator.py
示例11: create_favorite_for
def create_favorite_for(user, face_id):
global Favorites
global Users
if face_id in user.get('favorites', []):
return False
if user.get('nb_favorited') >= NB_MAX_FAVORITES:
return False
# create favorite object
Favorites.insert({_FACE_ID: face_id,
'user_id': user.get('ident'),
'datetime': now()})
# update facepicture counter for favorites
face = get_face_from(face_id)
update_face(face, {'nb_favorited': face.get('nb_favorited', 0) + 1})
# update user counter + list of favs
user.update({'favorites': user.get('favorites', []) + [face_id, ]})
Users.save(user)
# maybe update winner cache
update_winner_cache_if_winner(face)
开发者ID:jokkolabs,项目名称:face.ml,代码行数:25,代码来源:users.py
示例12: add_tag_to_face
def add_tag_to_face(face_id, tag_id, user):
# check if user already tagged with same tag
global TaggedFace
global FacePictures
if TaggedFace.find({'from': user.get('ident'),
_FACE_ID: face_id,
'tag': tag_id}).count():
return False
# create tag object
TaggedFace.insert({'from': user.get('ident'),
'from_type': user.get('type'),
_FACE_ID: face_id,
'tag': tag_id,
'datetime': now()})
face = get_face_from(face_id)
# update face tags list
face.update({'tags': face_tags_dict_for(face=face)})
# maybe update main tag of face
face.update({'tag': main_tag_for(face=face)})
# save face
FacePictures.save(face)
# maybe update winner cache
update_winner_cache_if_winner(face)
开发者ID:jokkolabs,项目名称:face.ml,代码行数:28,代码来源:face_data.py
示例13: test_situation_changes
def test_situation_changes(self):
"""Can't move somewhere that changes hands while you're moving"""
started = self.alice.region
londo = self.get_region("Orange Londo")
# For testing purposes, londo is now alice's
londo.owner = self.alice.team
order = self.alice.move(100, londo, 60 * 60 * 24)[0]
n = self.sess.query(db.MarchingOrder).count()
self.assertEqual(n, 1)
# BUT WAIT! Londo's government is overthrown!
londo.owner = self.bob.team
# Push back arrival time
order.arrival = now()
self.sess.commit()
# Invoke the update routine to set everyone's location
arrived = MarchingOrder.update_all(self.sess)
self.assert_(arrived)
# Alice should be back where she started, as she can't be in londo
self.assertEqual(started, self.alice.region)
n = self.sess.query(db.MarchingOrder).count()
self.assertEqual(n, 0)
开发者ID:JBoggsy,项目名称:chromabot,代码行数:27,代码来源:playtest.py
示例14: friend_time
def friend_time(seconds):
diff = now() - seconds
days = diff / 86400
if days > 730:
return '%s years ago' % (days / 365)
if days > 365:
return '1 year ago'
if days > 60:
return '%s months ago' % (days / 30)
if days > 30:
return '1 month ago'
if days > 14:
return '%s weeks ago' % (days / 7)
if days > 7:
return '1 week ago'
if days > 1:
return '%s days ago' % days
if diff > 7200:
return '%s hours ago' % (diff / 3600)
if diff > 3600:
return '1 hour ago'
if diff > 120:
return '%s minutes ago' % (diff / 60)
if diff > 60:
return '1 minute ago'
if diff > 1:
return '%s seconds ago' % diff
return '%s second ago' % diff
开发者ID:ponxu,项目名称:pxblog,代码行数:31,代码来源:func4temp.py
示例15: new_note
def new_note(self, user):
now = utils.now()
key = self._gen_unique_key()
note = Note()
note.user = user
note.key = key
note.deleted = 0
note.modify = now
note.create = now
note.syncnum = 1
note.version = 1
note.minversion = 1
note.sharekey = None
note.tags = []
note.content = ''
note.pinned = 0
note.unread = 0
note.markdown = 0
note.islist = 0
return note
开发者ID:swalladge,项目名称:snsrv,代码行数:25,代码来源:database.py
示例16: insert_location
def insert_location(self, x, y, heading, altitude, is_reset=False):
self._open_conn()
query = 'INSERT INTO user_location values(?, ?, ?, ?, ?)'
if is_reset:
self.conn.execute('UPDATE reset_state SET is_reset = 1')
self.conn.execute(query, [now(), x, y, heading, altitude])
self._close_conn()
开发者ID:KaranKamath,项目名称:CG3002,代码行数:7,代码来源:db.py
示例17: fit_datasets
def fit_datasets():
"""Fit datasets
:returns: google fit datasets
"""
service = fit_client()
datasets = service.users().dataset().aggregate(
userId='me',
body={
'aggregateBy': [{
'dataSourceId':
app.config['GOOGLE_FIT_SOURCE'],
}],
'startTimeMillis': yesterday_millis(),
'endTimeMillis': now(),
'bucketByTime': {
'durationMillis': 86400000,
'period': 'day'
},
# 1 day = 86400000, 1hr = 3600000
}
).execute()
return datasets
开发者ID:jeffgodwyll,项目名称:my-dashboard,代码行数:25,代码来源:googlefit.py
示例18: f
def f(uuid, features):
if (uuid in models_dict and
'date' in models_dict[uuid] and
'features' in models_dict[uuid] and
(utils.now() - models_dict[uuid]['date']).seconds < seconds and
models_dict[uuid]['features'] == features):
return models_dict[uuid]['model']
else:
models_dict[uuid] = {
'model': get_model(uuid, features),
'date': utils.now(),
'features': features
}
return models_dict[uuid]['model']
开发者ID:Chouffe,项目名称:az,代码行数:16,代码来源:ml_service.py
示例19: _report_alarm
def _report_alarm(self, alarm_l):
alarms = []
current = now()
for (level, category, key, reason) in alarm_l:
alarms.append(Alarm(timestamp=current, category=category, key=key,
reason=reason, level=level, host=self._hostname))
if alarms:
self._reporter.add_alarms(alarms)
开发者ID:yancl,项目名称:collectd,代码行数:8,代码来源:aggregator.py
示例20: _report_timeline
def _report_timeline(self, timeline_m):
current = now()
time_slices = []
for (k, v) in timeline_m.iteritems():
points = self._compute_timeline_sample_point(v)
time_slices.append(TimeSlice(timestamp=current, category=self._timeline_category, key=k, points=points))
if time_slices:
self._reporter.add_time_slices(time_slices)
开发者ID:yancl,项目名称:collectd,代码行数:8,代码来源:aggregator.py
注:本文中的utils.now函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论