def searchByModel(self, model, save=None): allResults = [] conn = psycopg2.connect( host="ec2-54-243-129-189.compute-1.amazonaws.com", database="dbfncufnkimb1n", user=credentials.get_sql_username(), password=credentials.get_sql_password()) cursor = conn.cursor() query = "SELECT (location_longitude, location_latitude, vehicle_id, vehicle_name, vehicle_model) FROM turodb WHERE vehicle_model = '{}'".format( model.title()) if verify(query) == None: return [] cursor.execute(query) for val in cursor.fetchall(): all_vals = [x.strip() for x in str(val[0]).split(",")] vehicle_model = all_vals.pop(-1).replace(")", "").replace('"', '') vehicle_name = all_vals.pop(-1).replace(")", "").replace('"', '') vehicle_id = all_vals.pop(-1).replace(")", "") val = ", ".join(all_vals) print val try: a, b = re.findall(r"[-+]?\d*\.\d+|[-+]?\d+", str(val)) allResults.append( [b, a, vehicle_id, vehicle_name, vehicle_model]) except Exception as exp: print exp pass conn.commit() cursor.close() return allResults
def genRandomID(): allResults = [] conn = psycopg2.connect(host="ec2-54-243-129-189.compute-1.amazonaws.com", database="dbfncufnkimb1n", user=credentials.get_sql_username(), password=credentials.get_sql_password()) cursor = conn.cursor() cursor.execute("SELECT vehicle_id FROM turodb ORDER BY RANDOM() LIMIT 1") return cursor.fetchone()[0]
def getTotalModel(self, vehicle_model): allResults = [] conn = psycopg2.connect( host="ec2-54-243-129-189.compute-1.amazonaws.com", database="dbfncufnkimb1n", user=credentials.get_sql_username(), password=credentials.get_sql_password()) cursor = conn.cursor() #cursor.execute("SELECT vehicle_name, rate_daily, location_address, vehicle_image_thumbnails_620x372, vehicle_year FROM turodb WHERE vehicle_id = {}".format(int(vehicle_id))) query = "SELECT COUNT(rate_daily) FROM turodb WHERE UPPER(vehicle_model) like '{}'".format( vehicle_model.upper()) if verify(query) == None: return [] cursor.execute(query) val = cursor.fetchone()[0] return int(val)
def makeQuery(sqlQuery, params=None): allResults = [] conn = psycopg2.connect(host="ec2-54-243-129-189.compute-1.amazonaws.com", database="dbfncufnkimb1n", user=credentials.get_sql_username(), password=credentials.get_sql_password()) cursor = conn.cursor() if verify(sqlQuery) == None: return [], False cursor.execute(sqlQuery) for v in cursor.fetchall(): if params == None: allResults.append(v) else: info = {} for i, val in enumerate(params): info[val] = v[i] allResults.append(info) return allResults, True
def searchSingleID(self, vehicle_id): allResults = [] conn = psycopg2.connect( host="ec2-54-243-129-189.compute-1.amazonaws.com", database="dbfncufnkimb1n", user=credentials.get_sql_username(), password=credentials.get_sql_password()) cursor = conn.cursor() #cursor.execute("SELECT vehicle_name, rate_daily, location_address, vehicle_image_thumbnails_620x372, vehicle_year FROM turodb WHERE vehicle_id = {}".format(int(vehicle_id))) query = "SELECT {} FROM turodb WHERE vehicle_id = {}".format( ', '.join(ALL_KEYS), int(vehicle_id)) if verify(query) == None: return [] cursor.execute(query) for val in cursor.fetchall(): allResults.append(val) conn.commit() cursor.close() return allResults
def get_all_lng_lat(self): allResults = [] conn = psycopg2.connect( host="ec2-54-243-129-189.compute-1.amazonaws.com", database="dbfncufnkimb1n", user=credentials.get_sql_username(), password=credentials.get_sql_password()) cursor = conn.cursor() cursor.execute( "SELECT (location_longitude, location_latitude, vehicle_id, vehicle_name, vehicle_model) FROM turodb" ) for val in cursor.fetchall(): all_vals = [x.strip() for x in str(val[0]).split(",")] vehicle_model = all_vals.pop(-1).replace(")", "") vehicle_name = all_vals.pop(-1).replace(")", "") vehicle_id = all_vals.pop(-1).replace(")", "") val = ", ".join(all_vals) print val a, b = re.findall(r"[-+]?\d*\.\d+|[-+]?\d+", str(val)) allResults.append([b, a, vehicle_id, vehicle_name, vehicle_model]) conn.commit() cursor.close() return allResults
import psycopg2 import json import credentials values = json.load(open("dataset/data.json")) conn = psycopg2.connect(host="ec2-54-243-129-189.compute-1.amazonaws.com", database="dbfncufnkimb1n", user=credentials.get_sql_username(), password=credentials.get_sql_password()) listofvalues = [ 'reviewCount', 'rating', 'owner_image_thumbnails_225x225', 'location_precision_accuracy', 'responseTime', 'rate_monthly', 'owner_image_thumbnails_84x84', 'vehicle_marketCountry', 'vehicle_listingCreatedTime', 'vehicle_marketCurrency_decimalPlaces', 'owner_image_id', 'vehicle_marketCurrency_currencyCode', 'images_0_thumbnails_170x125', 'rate_averageDailyPriceWithCurrency_currencyCode', 'owner_lastName', 'rate_averageDailyPriceWithCurrency_amount', 'owner_firstName', 'vehicle_image_verified', 'location_city', 'vehicle_id', 'vehicle_marketCurrency_symbol', 'images_0_thumbnails_620x372', 'location_country', 'images_0_resizableUrlTemplate', 'vehicle_image_resizableUrlTemplate', 'location_precision_level', 'distanceLabel', 'location_longitude', 'owner_image_placeholder', 'vehicle_automaticTransmission', 'vehicle_make', 'owner_image_verified', 'vehicle_image_thumbnails_574x343', 'vehicle_year', 'images_0_thumbnails_50x30', 'owner_image_thumbnails_32x32', 'vehicle_url', 'rentableFromSearchedAirport', 'vehicle_marketCurrency_defaultFractionDigits', 'responseRate', 'owner_image_originalImageUrl', 'rate_daily', 'deliveryLabel', 'images_0_originalImageUrl', 'vehicle_image_originalImageUrl',