I'm making a simple script that looks to see if my favourite YouTuber Casey Neistat has uploaded a new video. I want the script to loop over and over so see if there is a new video or not. However, whenever I run the program it continually says that there is a new video, even though it should recognize that there has been no changes to the 'output.txt' file that contains all the links to his videos. I am very new to python and programming in general, and thus this might be a simple fix someone more experienced than I would recognize.
My code is as follows:
import bs4 import requests import re root_url = 'https://www.youtube.com/' index_url = root_url + 'user/caseyneistat/videos' def getNeistatNewVideo(): response = requests.get(index_url) soup = bs4.BeautifulSoup(response.text) return [a.attrs.get('href') for a in soup.select('div.yt-lockup-thumbnail a[href^=/watch]')] def mainLoop(): while True: results = str(getNeistatNewVideo()) past_results = str(open("output.txt")) if results == past_results: print("No new videos at this time") return True else: print("There is a new video!") print('...') print('Writing to new text file') print('...') f = open("output.txt", "w") f.write(results) print('...') print('Done writing to new text file') print('...') return True mainLoop()