def __init__(self): self.CONFIG_FILE = "jwt-config.json" with open(self.CONFIG_FILE, 'r') as config_file: self.data_set = json.load(config_file) self.starter_config = self.data_set['SWIGGY']['CONFIG']['STARTER'] self.config = self.data_set['SWIGGY']['CONFIG'] self.dishes_data = [] self.restaurants_data = [] self.restaurants_obj = Restaurant(self.config) self.city = os.getenv('CITY', "jaipur") self.country = os.getenv('COUNTRY', "india") self.city_code = self.city + '__' + self.country self.dish_obj = Dish(self.config, self.city, self.country, self.city_code)
def do_POST(self): try: if self.path.endswith("/edit"): ctype, pdict = cgi.parse_header( self.headers.getheader('content-type')) if ctype == 'multipart/form-data': fields = cgi.parse_multipart(self.rfile, pdict) messagecontent = fields.get('newRestaurantName') restaurantIDPath = self.path.split("/")[2] myRestaurantQuery = session.query(Restaurant).filter_by( id=restaurantIDPath).one() if myRestaurantQuery: myRestaurantQuery.name = messagecontent[0] session.add(myRestaurantQuery) session.commit() self.send_response(301) self.send_header('Content-type', 'text/html') self.send_header('Location', '/restaurants') self.end_headers() if self.path.endswith("/delete"): ctype, pdict = cgi.parse_header( self.headers.getheader('content-type')) if ctype == 'multipart/form-data': fields = cgi.parse_multipart(self.rfile, pdict) messagecontent = fields.get('deleteRestaurantID') restaurantIDPath = self.path.split("/")[2] myRestaurantQuery = session.query(Restaurant).filter_by( id=restaurantIDPath).one() if myRestaurantQuery: myRestaurantQuery.id = messagecontent[0] session.delete(myRestaurantQuery) session.commit() self.send_response(301) self.send_header('Content-type', 'text/html') self.send_header('Location', '/restaurants') self.end_headers() if self.path.endswith("/restaurants/new"): ctype, pdict = cgi.parse_header( self.headers.getheader('content-type')) if ctype == 'multipart/form-data': fields = cgi.parse_multipart(self.rfile, pdict) messagecontent = fields.get('newRestaurantName') # Create new Restaurant class newRestaurant = Restaurant(name=messagecontent[0]) session.add(newRestaurant) session.commit() self.send_response(301) self.send_header('Content-type', 'text/html') self.send_header('Location', '/restaurants') self.end_headers() except: pass
def addRestaurant(self, restaurantName): engine = create_engine('sqlite:///restaurantmenu.db') Base.metadata.bind=engine DBSession = sessionmaker(bind = engine) session = DBSession() newRestaurant = Restaurant(name = restaurantName) session.add(newRestaurant) session.commit() return True
def __init__(self): self.CONFIG_FILE = "jwt-config.json" with open(self.CONFIG_FILE, 'r') as config_file: self.data_set = json.load(config_file) self.starter_config = self.data_set['ZOMATO']['CONFIG']['STARTER'] self.config = self.data_set['ZOMATO']['CONFIG'] self.dishes_data = [] self.restaurants_data = [] self.restaurants_obj = Restaurant(self.config) self.city = os.getenv('CITY', "jaipur") self.country = os.getenv('COUNTRY', "india") self.city_code = self.city + '__' + self.country self.dish_obj = Dish(self.config, self.city, self.country, self.city_code) self.options = Options() self.options.headless = True self.driver = webdriver.Chrome(options=self.options)
from restaurants import Restaurant restaurant = Restaurant('KF', 'fast food') restaurant.describe_restaurant()
class Customer_Details(data_base, QtWidgets.QWidget): def __init__(self): super().__init__() def init_ui(self, QtWidgets, QtGui): self.w = QtWidgets.QWidget() #LineEdits defined self.name = QtWidgets.QLineEdit(self.w) self.phone = QtWidgets.QLineEdit(self.w) self.address = QtWidgets.QLineEdit(self.w) self.email = QtWidgets.QLineEdit(self.w) self.area_btn = QtWidgets.QPushButton(self.w) self.area_btn.setText("Proceed Further") #Labels defined self.customerdetails = QtWidgets.QLabel(self.w) self.L1 = QtWidgets.QLabel(self.w) self.L2 = QtWidgets.QLabel(self.w) self.L3 = QtWidgets.QLabel(self.w) self.L4 = QtWidgets.QLabel(self.w) #Labels set TEXT self.L1.setText('Customer Name:') self.L2.setText('Customer Mobile No: ') self.L3.setText('Customer Email: ') self.L4.setText('Customer Address: ') #setting fontsize textfont = QFont("Calibiri", 16) self.L1.setFont(textfont) self.L2.setFont(textfont) self.L3.setFont(textfont) self.L4.setFont(textfont) self.pic1 = QtWidgets.QLabel(self.w) self.pic1.setPixmap(QtGui.QPixmap('icon')) self.pic1.move(0, 0) #allignment of labels self.L1.move(10, 250) self.L2.move(400, 250) self.L3.move(415, 295) self.L4.move(10, 295) self.area_btn.setGeometry(220, 330, 400, 20) self.area_btn.clicked.connect(self.btn_click) self.name.setGeometry(190, 255, 200, 20) self.phone.setGeometry(600, 255, 200, 20) self.address.setGeometry(600, 300, 200, 20) self.email.setGeometry(190, 300, 200, 20) self.w.setGeometry(240, 150, 820, 360) self.w.setWindowTitle('FOOD ORDERING SYSTEM') self.w.show() def btn_click(self): try: a = self.name.text() b = self.phone.text() c = self.address.text() d = self.email.text() if a.isdigit() or b == '' or c == '' or d == '': raise Exception('INVALID INPUT') else: self.database(self.name.text(), self.phone.text(), self.address.text(), self.email.text()) self.w = QtWidgets.QWidget() self.w.setWindowTitle('Restaurant Selection') #Buttons defined self.b1 = QtWidgets.QPushButton(self.w) self.b2 = QtWidgets.QPushButton(self.w) self.b3 = QtWidgets.QPushButton(self.w) self.b4 = QtWidgets.QPushButton(self.w) self.b5 = QtWidgets.QPushButton(self.w) self.b6 = QtWidgets.QPushButton(self.w) self.b1.clicked.connect(self.btn_clicked1) self.b2.clicked.connect(self.btn_clicked2) self.b3.clicked.connect(self.btn_clicked3) self.b4.clicked.connect(self.btn_clicked4) self.b5.clicked.connect(self.btn_clicked5) self.b6.clicked.connect(self.btn_clicked6) #setting text for buttons self.b1.setText("Student Biryani") self.b2.setText("McDonald's") self.b3.setText("Burger Lab") self.b4.setText("Pizza Max") self.b5.setText("Del Frio") self.b6.setText("Shaheen Shinwari") #allignment of buttons self.b1.setGeometry(0, 10, 200, 100) self.b2.setGeometry(200, 10, 200, 100) self.b3.setGeometry(400, 10, 200, 100) self.b4.setGeometry(0, 110, 200, 100) self.b5.setGeometry(200, 110, 200, 100) self.b6.setGeometry(400, 110, 200, 100) self.w.setGeometry(390, 210, 600, 220) self.w.show() except Exception: QMessageBox.question( self, 'Error', "Either Wrong Input Is Given Or Fields Are Empty ", QMessageBox.Yes | QMessageBox.Yes, QMessageBox.Yes) print("Exception Raised") #button clicks for all restaurants def btn_clicked1(self): self.det = Restaurant() self.det.Student_Biryani(QtWidgets, QtGui) def btn_clicked2(self): self.det = Restaurant() self.det.McDonalds(QtWidgets, QtGui) def btn_clicked3(self): self.det = Restaurant() self.det.burgerlab(QtWidgets, QtGui) def btn_clicked4(self): self.det = Restaurant() self.det.pizzamax(QtWidgets, QtGui) def btn_clicked5(self): self.det = Restaurant() self.det.del_frio(QtWidgets, QtGui) def btn_clicked6(self): self.det = Restaurant() self.det.shaheen_shinwari(QtWidgets, QtGui)
from restaurants import Restaurant, IcecreamStand rest1 = Restaurant('Chong Li\'s dog chop', 'Chinese') rest2 = Restaurant('Oves grill', 'Mosbricka') rest3 = Restaurant('Pacos MexMix', 'Texican') rest1.describe() rest1.open_restaurant() rest1.increment_number_served(10) print("We have served " + str(rest1.number_served)) rest2.describe() rest2.open_restaurant() rest3.describe() rest3.open_restaurant() icestand1 = IcecreamStand('Cheech and Chongs icecream van', 'herbal') icestand1.describe() icestand1.get_flavours() icestand1.open_restaurant()
from restaurants import Restaurant my_restaurant = Restaurant('nice', 'stake') my_restaurant.describe_restaurant()
print("5. See Average rating") # print("6. See total revenue") opt = int(input()) if opt == 1: service.list_restaurants() elif opt == 2: id = int(input("Enter restaurant id: ")) service.get_restaurant(id) elif opt == 3: id = int(input("Enter restaurant id: ")) name = raw_input("Enter restaurant name: ") address = raw_input("Enter restaurant address: ") restaurant = Restaurant(id, name, address) service.create_restaurant(restaurant) elif opt == 4: id = int(input("Enter restaurant id: ")) service.list_items(id) elif opt == 5: id = int(input("Enter restaurant id: ")) service.get_avg_rating(id) # elif opt == 6: # id = int(input("Enter restaurant id: ")) # service.get_total_revenue(id) else: print("Please select one from the given options.") elif inp == 2:
def btn_clicked6(self): self.det = Restaurant() self.det.shaheen_shinwari(QtWidgets, QtGui)
def btn_clicked5(self): self.det = Restaurant() self.det.del_frio(QtWidgets, QtGui)
def btn_clicked4(self): self.det = Restaurant() self.det.pizzamax(QtWidgets, QtGui)
def btn_clicked3(self): self.det = Restaurant() self.det.burgerlab(QtWidgets, QtGui)
def btn_clicked2(self): self.det = Restaurant() self.det.McDonalds(QtWidgets, QtGui)
def btn_clicked1(self): self.det = Restaurant() self.det.Student_Biryani(QtWidgets, QtGui)
# declaratives can be accessed through a DBSession instance Base.metadata.bind = engine DBSession = sessionmaker(bind=engine) # A DBSession() instance establishes all conversations with the database # and represents a "staging zone" for all the objects loaded into the # database session object. Any change made against the objects in the # session won't be persisted into the database until you call # session.commit(). If you're not happy about the changes, you can # revert all of them back to the last commit by calling # session.rollback() session = DBSession() # Menu for UrbanBurger restaurant1 = Restaurant(name="Urban Burger") session.add(restaurant1) session.commit() menuItem2 = MenuItem(name="Veggie Burger", description="Juicy grilled veggie patty with tomato mayo and lettuce", price="$7.50", course="Entree", restaurant=restaurant1) session.add(menuItem2) session.commit() menuItem1 = MenuItem(name="French Fries", description="with garlic and parmesan", price="$2.99", course="Appetizer", restaurant=restaurant1) session.add(menuItem1)
from restaurants import Restaurant # 导入模块和类 my_like = Restaurant('神厨', '珍珠翡翠白玉汤') my_like.describe_restaurant()
# 9-10 Imported Restaurant from restaurants import Restaurant food = Restaurant('Pizza Land', 'pizza') food.describe_restaurant() # 9-11 Imported Admin from users import Admin tyson = Admin('tyson', 'nguyen', 'tysonnguyen', 22, 'oregon') tyson.privileges.show_privileges() # 9-12 Multiple Modules where User class in one module, and store the Privileges and Admin separately. from user_privileges import Admin, Privileges tyson = Admin('tyson', 'nguyen', 'tysonnguyen', 22, 'oregon') tyson.privileges.show_privileges()
from restaurants import Restaurant new_restaurant = Restaurant('OCharleys', 'southern') new_restaurant.describe_restaurant() new_restaurant.open_restaurant() new_restaurant.increment_number_served(5) new_restaurant.describe_restaurant()
from restaurants import Restaurant EggHarbor = Restaurant('Egg Harbor Cafe', 'Breakfast', 0) EggHarbor.describe_restaruant() EggHarbor.set_number_served(200) EggHarbor.increment_number_served(50) print("This restaurant serves " + str(EggHarbor.number_served) + " patrons.") #BerryYo = IceCreamStand('BerryYo', 'Yogurt', 0) #BerryYo.flavor = ['Chocolate', 'Vanilla', 'Caramel', 'Peanut Butter', 'Chocolate Chip Cookie Dough', 'French Vanilla'] #BerryYo.display_flavors_list()
from restaurants import Restaurant restaurant1 = Restaurant("rest1", "chinese") print restaurant1.restaurant_name.title(), restaurant1.cuisine_type.title() restaurant1.describe() restaurant1.open() restaurant2 = Restaurant("rest2", "japanese") restaurant2.describe() restaurant2.open() restaurant3 = Restaurant("rest3", "italian") restaurant3.describe() restaurant3.open()
class Swiggy: def __init__(self): self.CONFIG_FILE = "jwt-config.json" with open(self.CONFIG_FILE, 'r') as config_file: self.data_set = json.load(config_file) self.starter_config = self.data_set['SWIGGY']['CONFIG']['STARTER'] self.config = self.data_set['SWIGGY']['CONFIG'] self.dishes_data = [] self.restaurants_data = [] self.restaurants_obj = Restaurant(self.config) self.city = os.getenv('CITY', "jaipur") self.country = os.getenv('COUNTRY', "india") self.city_code = self.city + '__' + self.country self.dish_obj = Dish(self.config, self.city, self.country, self.city_code) def get_data(self, url=None): print('+++++++IT WILL RUN') URL = self.starter_config["URLS"]['jaipur'] r = requests.get(URL) soup = BeautifulSoup(r.content, 'html5lib') TAG = self.starter_config['SELECTORS']['WAIT']['TAG'] FIND_BY = self.starter_config['SELECTORS']['WAIT']['FIND_BY'] VALUE = self.starter_config['SELECTORS']['WAIT']['VALUE'] data = soup.find_all(TAG, attrs={FIND_BY: VALUE}) _list = [] for row in data: link = row['href'] subzone = row.text _list.append({ 'subzone': subzone, 'link': "https://www.swiggy.com" + link }) no_of_threads = 3 last_chunk = -1 subzone_batch_threads = [] length_of_subzones = len(_list) chunk_size = int(length_of_subzones / no_of_threads) print('************chunk size', chunk_size) if length_of_subzones >= no_of_threads: for i in range(no_of_threads): batch = _list[i * chunk_size:(i + 1) * chunk_size] # batch = _list[0:1] subzone_batch_threads.append( threading.Thread(target=self.get_restaurants_thread, args=(batch, ))) subzone_batch_threads[-1].start() last_chunk = i last_chunk += 1 if no_of_threads * chunk_size < length_of_subzones: batch = _list[last_chunk * chunk_size:length_of_subzones] # batch = _list[0:1] subzone_batch_threads.append( threading.Thread(target=self.get_restaurants_thread, args=(batch, ))) subzone_batch_threads[-1].start() for thread in subzone_batch_threads: print('\n\n**************JOINING***********') thread.join() else: for subzone in _list: self.restaurants_obj.get_restaurants(subzone['link'], subzone['subzone'], self.restaurants_data) self.get_dishes() print('++++DISHES LEN', len(self.dishes_data)) # load data to dynamodb self.dynamodb_batch_write_obj = DynamoDBBatchWrite() self.dynamodb_batch_write_obj.batch_write_to_ddb(self.dishes_data) for dish_data in self.dishes_data: dish_data['stars'] = float(dish_data['stars']) # write data to parquet in s3 self.write_to_s3_parquet_obj = WriteS3Parquet(self.city) self.write_to_s3_parquet_obj.write_to_parquet(self.dishes_data) def get_restaurants_thread(self, subzones): print('+++++=THREAD') for subzone in subzones: self.restaurants_obj.get_restaurants(subzone['link'], subzone['subzone'], self.restaurants_data) def get_dishes(self): no_of_threads = 3 last_chunk = -1 restaurant_batch_threads = [] length_of_restaurants_data = len(self.restaurants_data) chunk_size = int(length_of_restaurants_data / no_of_threads) for i in range(no_of_threads): batch = self.restaurants_data[i * chunk_size:(i + 1) * chunk_size] # batch = restaurants_data[0:2] restaurant_batch_threads.append( threading.Thread(target=self.get_dishes_thread, args=(batch, ))) restaurant_batch_threads[-1].start() last_chunk = i last_chunk += 1 if no_of_threads * chunk_size < length_of_restaurants_data: batch = self.restaurants_data[ last_chunk * chunk_size:length_of_restaurants_data] # batch = restaurants_data[0:2] restaurant_batch_threads.append( threading.Thread(target=self.get_dishes_thread, args=(batch, ))) restaurant_batch_threads[-1].start() for thread in restaurant_batch_threads: thread.join() def get_dishes_thread(self, restaurants): for restaurant in restaurants: self.dish_obj.get_details(restaurant, self.dishes_data)
from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker from restaurants import Base, Restaurant, MenuItem engine = create_engine('sqlite:///restaurantmenu.db') Base.metadata.bind = engine DBSession = sessionmaker(bind=engine) session = DBSession() myFirstRestaurant = Restaurant(name="Pizza Palace") session.add(myFirstRestaurant) #session.commit() print(session.query(Restaurant).all()) cheesepizza = MenuItem(name="Cheese Pizza", description="Made with all natural ingredients amd fresh mozzarella", course="Entree", price="$8.99", restaurant=myFirstRestaurant) session.add(cheesepizza) #session.commit() print(session.query(MenuItem).all())
class Zomato: def __init__(self): self.CONFIG_FILE = "jwt-config.json" with open(self.CONFIG_FILE, 'r') as config_file: self.data_set = json.load(config_file) self.starter_config = self.data_set['ZOMATO']['CONFIG']['STARTER'] self.config = self.data_set['ZOMATO']['CONFIG'] self.dishes_data = [] self.restaurants_data = [] self.restaurants_obj = Restaurant(self.config) self.city = os.getenv('CITY', "jaipur") self.country = os.getenv('COUNTRY', "india") self.city_code = self.city + '__' + self.country self.dish_obj = Dish(self.config, self.city, self.country, self.city_code) def get_data(self, url=None): URL = self.starter_config["URLS"][self.city] print('+++++++++city url ff', self.city, URL) headers = { 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:67.0) Gecko/20100101 Firefox/67.0' } r = requests.get(URL, headers=headers) soup = BeautifulSoup(r.content, 'html5lib') TAG = self.starter_config['SELECTORS']['WAIT']['TAG'] FIND_BY = self.starter_config['SELECTORS']['WAIT']['FIND_BY'] VALUE = self.starter_config['SELECTORS']['WAIT']['VALUE'] data = soup.find_all(TAG, attrs={FIND_BY: VALUE}) _list = [] for row in data: link = row['href'] subzone = row.text.strip().split(' ') index = subzone.index('') subzone = subzone[0:index] subzone = " ".join(subzone) # print('++++++subzone',subzone) _list.append({ 'subzone': subzone, 'link': "https://www.zomato.com/" + self.city + "/delivery-in-" + subzone.lower().replace(' ', '-') + "?ref_page=subzone" }) print(" list of subzones ", len(_list)) # _list = _list[:1] no_of_threads = 3 last_chunk = -1 subzone_batch_threads = [] length_of_subzones = len(_list) chunk_size = int(length_of_subzones / no_of_threads) print('************chunk size', chunk_size) if length_of_subzones >= no_of_threads: for i in range(no_of_threads): batch = _list[i * chunk_size:(i + 1) * chunk_size] # batch = _list[0:1] subzone_batch_threads.append( threading.Thread(target=self.get_restaurants_thread, args=(batch, ))) subzone_batch_threads[-1].start() last_chunk = i last_chunk += 1 if no_of_threads * chunk_size < length_of_subzones: batch = _list[last_chunk * chunk_size:length_of_subzones] # batch = _list[0:1] subzone_batch_threads.append( threading.Thread(target=self.get_restaurants_thread, args=(batch, ))) subzone_batch_threads[-1].start() for thread in subzone_batch_threads: print('\n\n**************JOINING***********') thread.join() else: for subzone in _list: self.restaurants_obj.get_restaurants(subzone['link'], subzone['subzone'], self.restaurants_data) self.get_dishes() print('++++DISHES LEN', len(self.dishes_data)) # # load data to dynamodb self.dynamodb_batch_write_obj = DynamoDBBatchWrite() self.dynamodb_batch_write_obj.batch_write_to_ddb(self.dishes_data) for dish_data in self.dishes_data: dish_data['stars'] = float(dish_data['stars']) # # write data to parquet in s3 self.write_to_s3_parquet_obj = WriteS3Parquet(self.city) self.write_to_s3_parquet_obj.write_to_parquet(self.dishes_data) def get_restaurants_thread(self, subzones): print('+++++=THREAD') for subzone in subzones: self.restaurants_obj.get_restaurants(subzone['link'], subzone['subzone'], self.restaurants_data) def get_dishes(self): no_of_threads = 2 last_chunk = -1 restaurant_batch_threads = [] # self.restaurants_data = self.restaurants_data[3:8] length_of_restaurants_data = len(self.restaurants_data) chunk_size = int(length_of_restaurants_data / no_of_threads) for i in range(no_of_threads): batch = self.restaurants_data[i * chunk_size:(i + 1) * chunk_size] # batch = restaurants_data[0:2] restaurant_batch_threads.append( threading.Thread(target=self.get_dishes_thread, args=(batch, ))) restaurant_batch_threads[-1].start() last_chunk = i last_chunk += 1 if no_of_threads * chunk_size < length_of_restaurants_data: batch = self.restaurants_data[ last_chunk * chunk_size:length_of_restaurants_data] # batch = restaurants_data[0:2] restaurant_batch_threads.append( threading.Thread(target=self.get_dishes_thread, args=(batch, ))) restaurant_batch_threads[-1].start() for thread in restaurant_batch_threads: thread.join() def get_dishes_thread(self, restaurants): for restaurant in restaurants: try: options = Options() options.headless = True driver = webdriver.Firefox(options=options) # driver.set_page_load_timeout(10) self.dish_obj.get_details(driver, restaurant, self.dishes_data) driver.close() except Exception as e: print('++++++error while getting dish', e) try: driver.close() except: pass