From 53586d0195c8ed52b5b60be753071d5aeb2fcd14 Mon Sep 17 00:00:00 2001 From: pluja Date: Sat, 10 Oct 2020 09:41:14 +0200 Subject: [PATCH] Fix twitter not working on fresh installations There was a problem with cache not being created --- app/routes.py | 7 +++++-- youtube_data/videos.py | 10 ++++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/app/routes.py b/app/routes.py index 3d503ec..3075aef 100644 --- a/app/routes.py +++ b/app/routes.py @@ -77,8 +77,10 @@ def twitter(page=0): posts = [] cache_file = glob.glob("app/cache/{}_*".format(current_user.username)) - - time_diff = round(time.time()-os.path.getmtime(cache_file[0])) + if(len(cache_file) > 0): + time_diff = round(time.time()-os.path.getmtime(cache_file[0])) + else: + time_diff = 999 # If cache file is more than 1 minute old if page == 0 and time_diff > 60: if cache_file: @@ -663,6 +665,7 @@ def importYoutubeSubscriptions(file): def importYotterSubscriptions(file): filename = secure_filename(file.filename) data = json.load(file) + print(data) for acc in data['twitter']: r = followTwitterAccount(acc['username']) diff --git a/youtube_data/videos.py b/youtube_data/videos.py index feda8aa..3764c9c 100644 --- a/youtube_data/videos.py +++ b/youtube_data/videos.py @@ -259,8 +259,14 @@ def get_video_info(id): jsonIni = response[start:end1] dataInitial = json.loads(jsonIni) - jsonDet = response[start2:end2] - dataDetails = json.loads(jsonDet) + try: + jsonDet = response[start2:end2] + dataDetails = json.loads(jsonDet) + except: + response = requests.get(url, headers=headers).json() + jsonDet = response[start2:end2] + dataDetails = json.loads(jsonDet) + #title, views, date videoInfo = get_video_primary_info(dataDetails, dataInitial)