本文整理汇总了Python中rainwave.user.User.get_top_request_sid方法的典型用法代码示例。如果您正苦于以下问题:Python User.get_top_request_sid方法的具体用法?Python User.get_top_request_sid怎么用?Python User.get_top_request_sid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rainwave.user.User
的用法示例。
在下文中一共展示了User.get_top_request_sid方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: update_line
# 需要导入模块: from rainwave.user import User [as 别名]
# 或者: from rainwave.user.User import get_top_request_sid [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: get_next
# 需要导入模块: from rainwave.user import User [as 别名]
# 或者: from rainwave.user.User import get_top_request_sid [as 别名]
def get_next(sid):
# TODO: Code review
line = cache.get_station(sid, "request_line")
song = None
for pos in range(0, len(line)):
if not line['song_id']:
pass
else:
entry = line.pop(pos)
song = playlist.Song.load_from_id(entry['song_id'], sid)
song.data['elec_request_user_id'] = entry['user_id']
song.data['elec_request_username'] = entry['username']
db.c.update("DELETE FROM r4_request_store WHERE user_id = %s AND song_id = %s", (u.id, request['song_id']))
u = User(entry['user_id'])
u.remove_from_request_line()
if u.has_requests():
u.put_in_request_line(u.get_top_request_sid())
cache.set_station(sid, "request_line", line)
break
return song