def loopUpdateDB(mybot, bot_chatID): while (1): try: updateDB(daysHisto=1, stockRes='daily') updateDB(daysHisto=1, stockRes='intraday') logging.info('Sleeping 30 minutes') except Exception as e: print(e) logging.error('loopUpdateDB') logging.error(e) mybot.sendMessage(chat_id, "Error : \n" + str(e)) time.sleep(60 * 30)
def search_channel(channel2): #channel_url = web_url + channel + ".html" #soup = getBSoup(channel_url) time = [] ratings = [] title_search = re.compile('/title/tt\d+') #movie_name = soup.find_all('p', {"class": "title2"}) channel2_url= web_url2 + channel2 soup2 = getBSoup(channel2_url) for s in soup2.find_all("strong"): if s.string: s.string.replace_with(s.string.strip()) movie_name=[] movie_name2 = soup2.find_all("strong") for i in range(0,len(movie_name2)): movie_name2[i]=movie_name2[i].text #for i in range(0, len(movie_name)): # movie_name[i] = movie_name[i].text #print movie_name #time1 = soup.find_all('div', {"class": "col-lg-12"}) for s in soup2.find_all('b',{"class":"from"}): if s.string: s.string.replace_with(s.string.strip()) for s in soup2.find_all('b',{"class":"to"}): if s.string: s.string.replace_with(s.string.strip()) time2_from = soup2.find_all('b',{"class":"from"}) time2_to = soup2.find_all('b',{"class":"to"}) for i in range(0,len(time2_from)): time2_from[i]=time2_from[i].text for i in range(0,len(time2_to)): time2_to[i]=time2_to[i].text #for i in range(1, len(time1)-1, 2): # time.append(time1[i].text[0:13].strip('')) #time = [x for x in time if x != ''] for i in range(0,len(movie_name2)): movie_name.append(movie_name2[i]) #movie_name[i]=movie_name[i].encode('utf-8') movie_name[i]=movie_name[i].encode('ascii','ignore').strip() time.append(time2_from[i]+"-"+time2_to[i]) #print movie_name # time = filter(None, time) for i in range(0, len(movie_name)): try: print ("Checking IMDb rating of "+ movie_name[i]) movie_search = '+'.join(movie_name[i].split()) movie_url = base_url + movie_search + '&s=all' #print movie_url br = Browser() #print "check1" br.open(movie_url) #print "check2" link = br.find_link(url_regex=re.compile(r'/title/tt.*')) res = br.follow_link(link) #print "check3" soup = BeautifulSoup(res.read(), "lxml") #print "check4" movie_title = soup.find('title').contents[0] #print "check5" rate = soup.find('span', itemprop='ratingValue') if rate is not None: ratings.append(str(rate.contents[0])) else: ratings.append("-") except: ratings.append("-") headers = ['Movies', 'Time', 'Rating'] data_movies = [] for i in range(0, len(movie_name)): data_movies.append([str(movie_name[i]), str(time[i]), ratings[i]]) updateDB(channel2, movie_name, time2_from, time2_to, ratings) print (tabulate(data_movies, headers=headers)) #Saving to pdf print("\nWant to save as pdf? Y/N") choice = raw_input().lower() if choice == 'y': pdf_save(data_movies,headers) print('\nSaved!') else: print('\nBye!')
def displayNewProf(): netID = request.cookies.get('netid') prof = newProf(netID) profsDB_ = profsDB() try: profsDB_.connect() conn = profsDB_.conn error_statement, returned = updateDB(conn, prof) if returned == False: error_statement = createProf(conn, prof) except (Exception, psycopg2.DatabaseError) as error: error_statement = str(error) print(error_statement) finally: profsDB_.disconnect() prof_, error_statement = getProfs('netid ILIKE %s', [netID]) prof = prof_[0] if error_statement == '': html = "<div class='profForm'>" + \ "<form>" + \ "<div class='form-group row'>" + \ "<label for='colFormLabel' class='col-sm-2 col-form-label'>NetID</label>" + \ "<div class='col-sm-10'>" + \ "<input type='text' class='form-control' id='netid' name='netid' value='" + prof[0] + "' readonly>" + \ "</div>" + \ "</div>" + \ "<div class='form-group row'>" + \ "<label for='colFormLabel' class='col-sm-2 col-form-label'>First Name</label>" + \ "<div class='col-sm-10'>" + \ "<input type='text' class='form-control' id='firstname' name='firstname' value=''>" + \ "</div>" + \ "</div>" + \ "<div class='form-group row'>" + \ "<label for='colFormLabel' class='col-sm-2 col-form-label'>Last Name</label>" + \ "<div class='col-sm-10'>" + \ "<input type='text' class='form-control' id='lastname' name='lastname' value=''>" + \ "</div>" + \ "</div>" + \ "<div class='form-group row'>" + \ "<label for='colFormLabel' class='col-sm-2 col-form-label'>Title</label>" + \ "<div class='col-sm-10'>" + \ "<input type='text' class='form-control' id='title' name='title' value=''>" + \ "</div>" + \ "</div>" + \ "<div class='form-group row'>" + \ "<label for='colFormLabel' class='col-sm-2 col-form-label'>Email</label>" + \ "<div class='col-sm-10'>" + \ "<input type='text' class='form-control' id='email' value=''>" + \ "</div>" + \ "</div>" + \ "<div class='form-group row'>" + \ "<label for='colFormLabel' class='col-sm-2 col-form-label'>Phone Number</label>" + \ "<div class='col-sm-10'>" + \ "<input type='text' class='form-control' id='phone' name='phone' value=''>" + \ "</div>" + \ "</div>" + \ "<div class='form-group row'>" + \ "<label for='colFormLabel' class='col-sm-2 col-form-label'>Website</label>" + \ "<div class='col-sm-10'>" + \ "<input type='text' class='form-control' id='website' name='website' value=''>" + \ "</div>" + \ "</div>" + \ "<div class='form-group row'>" + \ "<label for='colFormLabel' class='col-sm-2 col-form-label'>Office</label>" + \ "<div class='col-sm-10'>" + \ "<input type='text' class='form-control' id='rooms' name='rooms' value=''>" + \ "</div>" + \ "</div>" + \ "<div class='form-group row'>" + \ "<label for='colFormLabel' class='col-sm-2 col-form-label'>Department</label>" + \ "<div class='col-sm-10'>" + \ "<input type='text' class='form-control' id='department' name='department' value=''>" + \ "</div>" + \ "</div>" + \ "<div class='form-group row'>" + \ "<label for='colFormLabel' class='col-sm-2 col-form-label'>Research Interests</label>" + \ "<div class='col-sm-10'>" + \ "<input type='text' class='form-control' id='areas' name='areas' value=''>" + \ "</div>" + \ "</div>" + \ "<div class='form-group row'>" + \ "<label for='colFormLabel' class='col-sm-2 col-form-label'>Bio</label>" + \ "<div class='col-sm-10'>" + \ "<textarea class='form-control' id='bio' name='bio' rows='5'></textarea>" + \ "</div>" + \ "</div>" + \ "</form>" + \ "<form id='upload-form' action='/upload' method='POST' enctype='multipart/form-data'>" + \ "<input type='file' id='file' name='file' accept='image/*'>" + \ "</form>" + \ "<p>*Small images (< 1MB) of dimensions 300x400 px work best.<p>" + \ "<img class='profImageDisplay' id='profImageDisplay'></img>" + \ "</div>" + \ """<form method="get" id="saveForm"> <button type="submit" class="btn btn-secondary btn btn-block" id="Save">Save</button> <button type="submit" class="btn btn-danger btn btn-block" id="Delete">Delete</button> </form>""" response = make_response(html) response.set_cookie('netid', netID) return response
def displayprof(): netID = request.cookies.get('netid') prof = newProf(netID) profsDB_ = profsDB() error_statement = profsDB_.connect() if error_statement != '': return error_statement conn = profsDB_.conn error_statement, returned = updateDB(conn, prof) if returned == False: error_statement = createProf(conn, prof) profsDB_.disconnect() if error_statement != '': print(error_statement) prof_, error_statement = getProfs('netid ILIKE %s', [netID]) prof = prof_[0] if error_statement == '': src = prof[11] # display image if in database if prof[12] != None: imageBytes = bytes(prof[12]) image = Image.open(io.BytesIO(imageBytes)) imageExtension = prof[13] netID = prof[0] filename = netID + '.' + imageExtension destination = "/".join(["static/profImages/", filename]) image.save(destination) src = destination html = "<h2 class='heading'>This the updated information for " + prof[ 1] + " " + prof[2] + ":</h2><hr>" html += "<table style='text-align: left;' class='profInfoTable'> " + \ '<tr>' + \ "<td align='right' class='label'>NetID:</td>" + \ "<td>" + prof[0] + "</td>" + \ "</tr>" + \ "<tr>" + \ "<td align='right' class='label'></title>First Name:</td>" + \ "<td>" + prof[1] + "</td>" + \ "</tr>" + \ "<tr>" + \ "<td align='right' class='label'></title>Last Name:</td>" + \ "<td>" + prof[2] + "</td>" + \ "</tr>" + \ "<tr>" + \ "<td align='right' class='label'>Phone:</td>" + \ "<td>" + prof[5] + "</td>" + \ "</tr>" + \ "<tr>" + \ "<td align='right' class='label'>Email:</td>" + \ "<td>" + prof[4] + "</td>" + \ "</tr>" + \ "<tr>" + \ "<td align='right' class='label'>Title:</td>" + \ "<td>" + prof[3] + "</td>" + \ "</tr>" + \ "<tr>" + \ "<td align='right' class='label'>Website:</td>" + \ "<td>" + prof[6] + "</td>" + \ "</tr>" + \ "<tr>" + \ "<td align='right' class='label'>Rooms:</td>" + \ "<td>" + prof[7] + "</td>" + \ "</tr>" + \ "<tr>" + \ "<td align='right' class='label'>Department:</td>" + \ "<td>" + prof[8] + "</td>" + \ "</tr>" + \ "<tr>" + \ "<td align='right' class='label'>Areas:</td>" + \ "<td>" + prof[9]+ "</td>" + \ "</tr>" + \ "<tr>" + \ "<td align='right' class='label'>Bio:</td>" + \ "<td>" + prof[10] + "</td>" + \ "</tr>" + \ "<tr>" + \ "<td align='right' class='label'>Image File:</td>" + \ "<td>" + prof[11] + "</td>" + \ "</tr>" + \ "<tr>" + \ "<td>" + "<img class='profImageDisplay' id='profImageDisplay' src='" + src + "'></img>" + "</td>" +\ "</tr>" + \ "</table>" + \ """<form method="get" id="editOtherForm"> <button type="submit" class="btn btn-secondary btn-lg">Edit Another Professor</button> </form>""" else: print(error_statement, file=stderr) response = make_response(html) return response
def test_updateDB(self): updateDB() self.assertTrue(True)
qq="./bq.py -d "+date+" -f "+fName os.system(qq) else: print 'Warning: Already existed NDT data File used.' if not os.path.exists('CSV/'+fName+'.db'): makeDB(fName,bgpFile) else: print 'Warning: Already existed NDT database used.' if not os.path.exists('Model/'+fName+'.pk'): spDump(fName,the) else: print 'Use already existing service plan models' online_C=False if not os.path.exists('CSV/Graphs/'+fName): csv2gml(fName,0) walktrapFile(fName) rwcd(fName,tx='6') online_C=True else: print 'Use already existing graphs are used' if not online_C: if not os.path.exists('CSV/Walktrap/'+fName): walktrapFile(fName) rwcd(fName,tx='6') else: pass print 'Updating database...' updateDB(fName)