Why does this python script work on Ubuntu but not Raspbian? -
a friend , created following script utilizing beautifulsoup html of job page, append job array, file, email job in human-readable format ourselves. script works on ubuntu, on raspberry pi, uses raspbian, doesn't work.
the message see when running terminal is: 'end of file' , 'start write...' lines in code. there no error messages when running pi, nothing gets appended array , no emails sent.
can take look? thanks.
import urllib2, email, smtplib, os.path import cpickle pickle bs4 import beautifulsoup class job: """docstring job""" def __init__(self, title, date, url): self.title = title self.date = date self.url = "http://www.forensicfocus.com/"+url def describjob(self): return (self.title +" "+ self.date +" "+ self.url) def createjobsarray(): soup = beautifulsoup(urllib2.urlopen('http://www.forensicfocus.com/jobs').read()) bigfatstring = soup.find_all('a') #print(bigfatstring) #this gets webpage html. no issues here findall = soup.find_all("tr", class_="topic") jobsarray = [] section in findall: title = section.find("a", class_="topictitle").get_text() titleencoded = title.encode('ascii','ignore') row = section.find_all("td") date = row[3].find("div").get_text() url = section.find_all("a")[3].get("href") job = job(titleencoded, date, url) print "printing job" print job print "printing job" jobsarray.append(job) return jobsarray def sendemail(job): senderemail = "sender@example.com" recipients = ["destination@example.com"] s = smtplib.smtp("smtp.gmail.com",587) s.ehlo() s.starttls() s.ehlo() s.login(senderemail, 'pass_goes_here') job in jobsfilteredbylocation: msg = email.message_from_string(job.describjob()) msg['subject'] = "new job found: " + job.title s.sendmail(senderemail, recipients, msg.as_string()) print "sending email..." s.quit() def savejobstodisk(jobs): open('hadooken', 'wb') output: print "start write..." job in jobs: print job.title pickle.dump(job, output) output.close() def getjobsfromdisk(): oldjobsarray = [] open('hadooken', 'rb') input: while true: try: job = pickle.load(input) print job.title, "was read file" oldjobsarray.append(job) except eoferror: print "end of file" break return oldjobsarray input.close() # script starts here open('hadooken', 'ab') input: input.close() locationsarray = ["london"] jobsarray = createjobsarray() oldjobsarray = getjobsfromdisk() jobsfilteredbylocation = [] job in jobsarray: location in locationsarray: found = job.title.find(location) if found > 0: if len(oldjobsarray) > 0: if any(oldjob.title == job.title oldjob in oldjobsarray): print "job found , sent..." else: print "adding ", job.title, "to array because isnt in old array" jobsfilteredbylocation.append(job) else: print "adding ", job.title, "to array" jobsfilteredbylocation.append(job) sendemail(jobsfilteredbylocation) mergedarray = oldjobsarray + jobsfilteredbylocation job in mergedarray: print "job title: ", job.title savejobstodisk(mergedarray)
Comments
Post a Comment