def getItunes(title, date, id): # print(title[1:len(title)-1]) info = db_reader_m.check_price(id, "Itunes") if (info == None): data = engine.get_Itunes(title, date) if (db_writer_m.update_price(id, "$" + str(data['price']), str(data['link']), "Itunes")): print("update itunes price successful") else: print(data) return jsonify(data) else: # print("++++++++++++++++++itunes+++++++++++++++++=") return jsonify({"name": "itunes", "price": info[1], "link": info[2]})
def getGoogle(title, year, id): # print(title[1:len(title)-1]) info = db_reader_m.check_price(id, "Google") # print(title+"asdfadsf") year = year[0:4] # print(year) if (info == None): pass else: return jsonify({"name": "google", "price": info[1], "link": info[2]}) #Mac: # running the shell scrip to web scrap the google price # p = Popen(['./webscraping/google_price.sh', title, year], # stdin=PIPE, stdout=PIPE, stderr=PIPE) #Windows: command = "sh ./webscraping/google_price_w.sh " + title + " " + year args = shlex.split(command) p = subprocess.Popen(args, shell=True, stdout=subprocess.PIPE) output = p.communicate()[0] # split the output line by line info_list = output.splitlines() # print(info_list) # get the price price = info_list[0].decode('ascii') # print(price) # check if the price is in correct format if not price.startswith("$"): return jsonify({"name": "Google", "price": "N/A", "link": "N/A"}) # get the link link = info_list[1].decode('ascii') # making json object data = {"name": "Google", "price": price, "link": link} # print(data) if (db_writer_m.update_price(id, price, link, "Google")): print("update google price successful") return jsonify(data)
def getGoogle(title, year, id): # print(title[1:len(title)-1]) info = db_reader_m.check_price(id, "Google") # print(title+"asdfadsf") year = year[0:4] # print(year) if (info == None): pass else: return jsonify({"name": "google", "price": info[1], "link": info[2]}) # running the shell scrip to web scrap the google price p = Popen(['./webscraping/google_price.sh', title, year], stdin=PIPE, stdout=PIPE, stderr=PIPE) output, err = p.communicate( b"input data that is passed to subprocess' stdin") rc = p.returncode # split the output line by line info_list = output.splitlines() # print(info_list) # get the price price = info_list[0].decode('ascii') # print(price) # check if the price is in correct format if not price.startswith("$"): return jsonify({"name": "Google", "price": "N/A", "link": "N/A"}) # get the link link = info_list[1].decode('ascii') # making json object data = {"name": "Google", "price": price, "link": link} # print(data) if (db_writer_m.update_price(id, price, link, "Google")): print("update google price successful") return jsonify(data)
def getYoutobePrice(title, year, id): info = db_reader_m.check_price(id, "Youtobe") title = title.replace(' ', '_') if (info == None): pass else: data = {"name": "youtube", "price": info[1], "link": info[2]} return jsonify(data) # running the shell scrip to web scrap the youtobe price #Mac: # p = Popen(['./webscraping/youtobe_price.sh', title, year], # stdin=PIPE, stdout=PIPE, stderr=PIPE) #Windows: command = "sh ./webscraping/youtube_price_w.sh " + title + " " + year args = shlex.split(command) print("youyube" + title) p = subprocess.Popen(args, stdout=subprocess.PIPE, shell=True) output = p.communicate()[0] print(output) # split the output line by line info_list = output.splitlines() # get the price price = info_list[0].decode('ascii') # check if the price is in correct format if not price.startswith("$"): return jsonify({"name": "youtube", "price": "N/A", "link": "N/A"}) # get the link link = info_list[1].decode('ascii') # making json object data = {"name": "youtube", "price": price, "link": link} if (db_writer_m.update_price(id, price, link, "Youtube")): print("update youtobe price successful") return jsonify(data)
def getYoutobePrice(title, year, id): info = db_reader_m.check_price(id, "Youtobe") if (info == None): pass else: data = {"name": "youtube", "price": info[1], "link": info[2]} return jsonify(data) # running the shell scrip to web scrap the youtobe price p = Popen(['./webscraping/youtobe_price.sh', title, year], stdin=PIPE, stdout=PIPE, stderr=PIPE) output, err = p.communicate( b"input data that is passed to subprocess' stdin") rc = p.returncode # split the output line by line info_list = output.splitlines() # get the price price = info_list[0].decode('ascii') # check if the price is in correct format if not price.startswith("$"): return jsonify({"name": "youtube", "price": "N/A", "link": "N/A"}) # get the link link = info_list[1].decode('ascii') # making json object data = {"name": "youtube", "price": price, "link": link} if (db_writer_m.update_price(id, price, link, "Youtube")): print("update youtobe price successful") return jsonify(data)