本文整理汇总了Python中rainwave.user.User.refresh方法的典型用法代码示例。如果您正苦于以下问题:Python User.refresh方法的具体用法?Python User.refresh怎么用?Python User.refresh使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rainwave.user.User
的用法示例。
在下文中一共展示了User.refresh方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: update_line
# 需要导入模块: from rainwave.user import User [as 别名]
# 或者: from rainwave.user.User import refresh [as 别名]
def update_line(sid):
# TODO: This needs code review
# Get everyone in the line
line = db.c.fetch_all("SELECT username, user_id, line_expiry_tune_in, line_expiry_election FROM r4_request_line JOIN phpbb_users USING (user_id) WHERE sid = %s ORDER BY line_wait_start", (sid,))
new_line = []
user_positions = {}
t = time.time()
position = 1
# For each person
for row in line:
add_to_line = False
u = User(row['user_id'])
row['song_id'] = None
# If their time is up, remove them and don't add them to the new line
if row['line_expiry_tune_in'] <= t:
u.remove_from_request_line()
else:
# refresh the user to get their data, using local cache only - speed things up here
u.refresh(True)
# If they're not tuned in and haven't been marked as expiring yet, mark them, add to line, move on
if not u.data['radio_tuned_in'] and not u.data['radio_tuned_in']:
row['line_expiry_tune_in'] = t + 600
add_to_line = True
# do nothing if they're not tuned in
elif not u.data['radio_tuned_in']:
pass
else:
# Get their top song ID
song_id = u.get_top_request_song_id(sid)
# If they have no song and their line expiry has arrived, boot 'em
if not song_id and (row['line_expiry_election'] <= t):
u.remove_from_request_line()
# Give them a second chance if they still have requests, this is SID-indiscriminate
# they'll get added to whatever line is their top request
if u.has_requests():
u.put_in_request_line(u.get_top_request_sid())
# If they have no song, start the expiry countdown
elif not song_id:
row['line_expiry_election'] = t + 600
add_to_line = True
# Keep 'em in line
else:
row['song_id'] = song_id
add_to_line = True
if add_to_line:
new_line.append(row)
user_positions[u.id] = position
position = position + 1
cache.set_station(sid, "request_line", new_line)
cache.set_station(sid, "request_user_positions", user_positions)
示例2: update_line
# 需要导入模块: from rainwave.user import User [as 别名]
# 或者: from rainwave.user.User import refresh [as 别名]
def update_line(sid):
# Get everyone in the line
line = db.c.fetch_all("SELECT username, user_id, line_expiry_tune_in, line_expiry_election, line_wait_start FROM r4_request_line JOIN phpbb_users USING (user_id) WHERE sid = %s ORDER BY line_wait_start", (sid,))
new_line = []
# user_positions has user_id as a key and position as the value, this is cached for quick lookups by API requests
# so users know where they are in line
user_positions = {}
t = int(time.time())
position = 1
# For each person
for row in line:
add_to_line = False
u = User(row['user_id'])
u.refresh_sid = sid
row['song_id'] = None
# If their time is up, remove them and don't add them to the new line
if row['line_expiry_tune_in'] and row['line_expiry_tune_in'] <= t:
u.remove_from_request_line()
else:
u.refresh()
# do nothing if they're not tuned in
if not u.data['radio_tuned_in']:
pass
else:
# Get their top song ID
song_id = u.get_top_request_song_id(sid)
# If they have no song and their line expiry has arrived, boot 'em
if not song_id and row['line_expiry_election'] and (row['line_expiry_election'] <= t):
u.remove_from_request_line()
# Give them a second chance if they still have requests
# They'll get added to the line of whatever station they're tuned in to (if any!)
if u.has_requests():
u.put_in_request_line(u.get_tuned_in_sid())
# If they have no song, start the expiry countdown
elif not song_id:
row['line_expiry_election'] = t + 600
db.c.update("UPDATE r4_request_line SET line_expiry_election = %s WHERE user_id = %s", (row['line_expiry_election'], row['user_id']))
add_to_line = True
# Keep 'em in line
else:
row['song_id'] = song_id
add_to_line = True
if add_to_line:
new_line.append(row)
user_positions[u.id] = position
position = position + 1
cache.set_station(sid, "request_line", new_line, True)
cache.set_station(sid, "request_user_positions", user_positions, True)
示例3: RainwaveHandler
# 需要导入模块: from rainwave.user import User [as 别名]
# 或者: from rainwave.user.User import refresh [as 别名]
#.........这里部分代码省略.........
self._output = {}
if not self.sid:
self.sid = fieldtypes.integer(self.get_cookie("r4_sid", None))
hostname = self.request.headers.get('Host', None)
if hostname:
hostname = unicode(hostname).split(":")[0]
if hostname in config.station_hostnames:
self.sid = config.station_hostnames[hostname]
sid_arg = fieldtypes.integer(self.get_argument("sid", None))
if sid_arg is not None:
self.sid = sid_arg
if self.sid is None and self.sid_required:
raise APIException("missing_station_id", http_code=400)
self.arg_parse()
self.sid_check()
if self.sid:
self.set_cookie("r4_sid", str(self.sid), expires_days=365)
if self.phpbb_auth:
self.do_phpbb_auth()
else:
self.rainwave_auth()
if not self.user and self.auth_required:
raise APIException("auth_required", http_code=403)
elif not self.user and not self.auth_required:
self.user = User(1)
self.user.ip_address = self.request.remote_ip
self.user.refresh(self.sid)
if self.user and config.get("store_prefs"):
self.user.save_preferences(self.request.remote_ip, self.get_cookie("r4_prefs", None))
self.permission_checks()
# works without touching cookies or headers, primarily used for websocket requests
def prepare_standalone(self, message_id=None):
self._output = {}
if message_id != None:
self.append("message_id", { "message_id": message_id })
self.setup_output()
self.arg_parse()
self.sid_check()
self.permission_checks()
def do_phpbb_auth(self):
phpbb_cookie_name = config.get("phpbb_cookie_name") + "_"
user_id = fieldtypes.integer(self.get_cookie(phpbb_cookie_name + "u", ""))
if not user_id:
pass
else:
if self._verify_phpbb_session(user_id):
# update_phpbb_session is done by verify_phpbb_session if successful
self.user = User(user_id)
self.user.ip_address = self.request.remote_ip
self.user.authorize(self.sid, None, bypass=True)
return True
if not self.user and self.get_cookie(phpbb_cookie_name + "k"):
can_login = db.c.fetch_var("SELECT 1 FROM phpbb_sessions_keys WHERE key_id = %s AND user_id = %s", (hashlib.md5(self.get_cookie(phpbb_cookie_name + "k")).hexdigest(), user_id))
if can_login == 1:
示例4: RainwaveHandler
# 需要导入模块: from rainwave.user import User [as 别名]
# 或者: from rainwave.user.User import refresh [as 别名]
#.........这里部分代码省略.........
if not self.sid and self.sid_required:
raise APIException("missing_station_id", http_code=400)
for field, field_attribs in self.__class__.fields.iteritems():
type_cast, required = field_attribs
if required and field not in self.request.arguments:
raise APIException("missing_argument", argument=field, http_code=400)
elif not required and field not in self.request.arguments:
self.cleaned_args[field] = None
else:
parsed = type_cast(self.get_argument(field), self)
if parsed == None and required != None:
raise APIException("invalid_argument", argument=field, reason="%s %s" % (field, getattr(fieldtypes, "%s_error" % type_cast.__name__)), http_code=400)
else:
self.cleaned_args[field] = parsed
if not self.sid and not self.sid_required:
self.sid = 5
if not self.sid in config.station_ids:
raise APIException("invalid_station_id", http_code=400)
self.set_cookie("r4_sid", str(self.sid), expires_days=365, domain=config.get("cookie_domain"))
if self.phpbb_auth:
self.do_phpbb_auth()
else:
self.rainwave_auth()
if not self.user and self.auth_required:
raise APIException("auth_required", http_code=403)
elif not self.user and not self.auth_required:
self.user = User(1)
self.user.ip_address = self.request.remote_ip
self.user.refresh(self.sid)
if self.login_required and (not self.user or self.user.is_anonymous()):
raise APIException("login_required", http_code=403)
if self.tunein_required and (not self.user or not self.user.is_tunedin()):
raise APIException("tunein_required", http_code=403)
if self.admin_required and (not self.user or not self.user.is_admin()):
raise APIException("admin_required", http_code=403)
if self.dj_required and (not self.user or not self.user.is_dj()):
raise APIException("dj_required", http_code=403)
if self.perks_required and (not self.user or not self.user.has_perks()):
raise APIException("perks_required", http_code=403)
if self.unlocked_listener_only and not self.user:
raise APIException("auth_required", http_code=403)
elif self.unlocked_listener_only and self.user.data['lock'] and self.user.data['lock_sid'] != self.sid:
raise APIException("unlocked_only", station=config.station_id_friendly[self.user.data['lock_sid']], lock_counter=self.user.data['lock_counter'], http_code=403)
def do_phpbb_auth(self):
phpbb_cookie_name = config.get("phpbb_cookie_name")
user_id = fieldtypes.integer(self.get_cookie(phpbb_cookie_name + "u", ""))
if not user_id:
pass
else:
if self._verify_phpbb_session(user_id):
# update_phpbb_session is done by verify_phpbb_session if successful
self.user = User(user_id)
self.user.authorize(self.sid, None, None, True)
return True
if not self.user and self.get_cookie(phpbb_cookie_name + "k"):
can_login = db.c.fetch_var("SELECT 1 FROM phpbb_sessions_keys WHERE key_id = %s AND user_id = %s", (hashlib.md5(self.get_cookie(phpbb_cookie_name + "k")).hexdigest(), user_id))
if can_login == 1: