Fix yotter data import

This commit is contained in:
pluja 2020-11-06 14:58:43 +01:00
parent 0454c711d4
commit 92689b954c

View File

@ -363,22 +363,23 @@ def ytfollow(channelId):
def followYoutubeChannel(channelId): def followYoutubeChannel(channelId):
try: try:
channelData = YoutubeSearch.channelInfo(channelId, False)
try: try:
if not current_user.is_following_yt(channelId): if not current_user.is_following_yt(channelId):
channelData = ytch.get_channel_tab_info(channelId, tab='about')
if channelData == False:
return False
follow = youtubeFollow() follow = youtubeFollow()
follow.channelId = channelId follow.channelId = channelId
follow.channelName = channelData[0]['name'] follow.channelName = channelData['channel_name']
follow.followers.append(current_user) follow.followers.append(current_user)
db.session.add(follow) db.session.add(follow)
db.session.commit() db.session.commit()
flash("{} followed!".format(channelData[0]['name'])) flash("{} followed!".format(channelData['channel_name']))
return True return True
else: else:
return False return False
except Exception as e: except Exception as e:
print(e) print(e)
flash("Youtube: Couldn't follow {}. Already followed?".format(channelData[0]['name']))
return False return False
except KeyError as ke: except KeyError as ke:
print("KeyError: {}:'{}' could not be found".format(ke, channelId)) print("KeyError: {}:'{}' could not be found".format(ke, channelId))
@ -686,6 +687,7 @@ def importdata():
flash('No selected file') flash('No selected file')
return redirect(request.referrer) return redirect(request.referrer)
else: else:
flash("Data is being imported. You can keep using Yotter.")
importdataasync(file) importdataasync(file)
return redirect(request.referrer) return redirect(request.referrer)
@ -885,7 +887,7 @@ def getFeed(urls):
with FuturesSession() as session: with FuturesSession() as session:
futures = [session.get('{instance}{user}'.format(instance=NITTERINSTANCE, user=u.username)) for u in urls] futures = [session.get('{instance}{user}'.format(instance=NITTERINSTANCE, user=u.username)) for u in urls]
for future in as_completed(futures): for future in as_completed(futures):
res = future.result().content.decode('utf-8') res= future.result().content
html = BeautifulSoup(res, "html.parser") html = BeautifulSoup(res, "html.parser")
userFeed = html.find_all('div', attrs={'class': 'timeline-item'}) userFeed = html.find_all('div', attrs={'class': 'timeline-item'})
if userFeed != []: if userFeed != []: