Rename variables uid->channel_id, most_recent_video->video_id.

This commit is contained in:
voussoir 2020-11-20 16:13:14 -08:00
parent 5a868dc7bd
commit 4d80237456

View file

@ -9,9 +9,9 @@ log = vlogging.getLogger(__name__)
session = requests.Session() session = requests.Session()
def _get_user_videos(uid): def _get_user_videos(channel_id):
log.info(f'Fetching RSS for {uid}.') log.info(f'Fetching RSS for {channel_id}.')
url = f'https://www.youtube.com/feeds/videos.xml?channel_id={uid}' url = f'https://www.youtube.com/feeds/videos.xml?channel_id={channel_id}'
response = session.get(url) response = session.get(url)
response.raise_for_status() response.raise_for_status()
soup = bs4.BeautifulSoup(response.text, 'lxml') soup = bs4.BeautifulSoup(response.text, 'lxml')
@ -20,18 +20,18 @@ def _get_user_videos(uid):
log.loud('RSS got %s.', video_ids) log.loud('RSS got %s.', video_ids)
return video_ids return video_ids
def get_user_videos(uid): def get_user_videos(channel_id):
try: try:
return _get_user_videos(uid) return _get_user_videos(channel_id)
except Exception: except Exception:
raise exceptions.RSSAssistFailed(f'Failed to fetch RSS videos.') from exc raise exceptions.RSSAssistFailed(f'Failed to fetch RSS videos.') from exc
def get_user_videos_since(uid, most_recent_video): def get_user_videos_since(channel_id, video_id):
video_ids = get_user_videos(uid) video_ids = get_user_videos(channel_id)
try: try:
index = video_ids.index(most_recent_video) index = video_ids.index(video_id)
except ValueError: except ValueError:
raise exceptions.RSSAssistFailed(f'RSS didn\'t contain {most_recent_video}.') raise exceptions.RSSAssistFailed(f'RSS didn\'t contain {video_id}.')
video_ids = video_ids[:index] video_ids = video_ids[:index]
log.loud('Since %s: %s', most_recent_video, str(video_ids)) log.loud('Since %s: %s', video_id, str(video_ids))
return video_ids return video_ids