python - Methods within my while Loop not working -


i'm making simple script looks see if favourite youtuber casey neistat has uploaded new video. want script loop on , on see if there new video or not. however, whenever run program continually says there new video, though should recognize there has been no changes 'output.txt' file contains links videos. new python , programming in general, , might simple fix more experienced recognize.

my code 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') 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 @ time")              return true          else:             print("there new video!")              print('...')             print('writing new text file')             print('...')               f = open("output.txt", "w")             f.write(results)              print('...')             print('done writing new text file')             print('...')                  return true   mainloop() 

calling open(output.txt) returns file object, not the text within file. calling str on file object gives description of object, not text. need like

output = open('output.txt') past_results = output.read() 

also, looks you're calling str on output of getneistatnewvideo list, not want do. guess format of output.txt bunch of links on separate lines. if that's case, want

results = "\n".join(getneistatnewvideo()) 

which give single string each link on it's own line. should print output of str calls see like. so, reason says there new because

results == past_results  

is false because of reasons outlined


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -