def make_random_service(self): new_service = Service() new_service.name = "Service 45" new_service.description = "Much service" new_service.service_type = "night" new_service.route = "[{'destination':'Gyle Centre','points':[{'latitude':55.93879,'longitude':-3.104563},{'latitude':55.93862,'longitude':-3.105503}]}]" return new_service
def update_services_stops(): # Delete all data first delete_services_stops() # Get services as json data json_data = requests.get(API_SERVICES, headers=API_HEADER) service_dict = json.loads(json_data.text) # Array of service objects services = service_dict["services"] # Get stops as json data json_data = requests.get(API_STOPS, headers=API_HEADER) stop_dict = json.loads(json_data.text) # Array of stop objects stops = stop_dict["stops"] # Update the tables' last_updated field service_date = datetime.fromtimestamp(int(service_dict["last_updated"])) update_table_date("service", service_date) stop_date = datetime.fromtimestamp(int(stop_dict["last_updated"])) update_table_date("stop", stop_date) # Create a service instance of each service and store them in a new dictionary service_dict = {} for service in services: new_service = Service() new_service.name = service["name"] new_service.service_type = service["service_type"] new_service.description = service["description"] new_service.route = json.dumps(service["routes"][0]["points"]) if len(service["routes"]) > 0 else "none" service_dict[service["name"]] = new_service db_session.add(new_service) # Create a stop instance of each stop and add corresponding services to them for stop in stops: new_stop = Stop() new_stop.name = stop["name"] new_stop.latitude = stop["latitude"] new_stop.longitude = stop["longitude"] # Add services to stops # Must take the set because sometimes the services are listed multiple times for a particular stop. stop_services = set(stop["services"]) for service_name in stop_services: new_stop.services.append(service_dict[service_name]) db_session.add(new_stop) db_session.commit() db_session.flush()
def _find_service(id): """ Find a service by id """ service = Service.find(id) if not service: msg = f"Service not found" raise exceptions.NotFound({"services": msg})
def resolve(self, authorization: http.Header, route: Route) -> AuthData: """ Describe """ if route.handler.__name__ in self.no_auth_list: log.info(f"No auth handler") return AuthData() scheme, token = self.get_data_by_header(authorization) if "Bearer" in scheme: try: payload = jwt.decode(token, self.secret, self.algorithms) user_id = payload.get("user_id") user = User.find(user_id) if user is None: msg = "Unauthorized, invalid token" raise exceptions.HTTPException({"message": msg}, status_code=401) return AuthData(user, None) except jwt.DecodeError: msg = "Unauthorized, invalid token" raise exceptions.HTTPException({"message": msg}, status_code=401) except jwt.ExpiredSignatureError: msg = "Unauthorized, token expired" raise exceptions.HTTPException({"message": msg}, status_code=401) if "Token" in scheme: if route.handler.__name__ in self.accept_token_list: service = Service.where("token", token).first() if service is None: msg = "Unauthorized, invalid token" raise exceptions.HTTPException({"message": msg}, status_code=401) return AuthData(None, service) msg = f"This endpoint is not available by Token, please use Bearer header" raise exceptions.Forbidden({"message": msg})
from models.service import Service from models.account import Account from app import db, settings _pyflakes = Account db.drop_all() db.create_all() s = Service() s.type = "reddit" opt = { 'host': 'http://%s:%s/captcha' % (settings.CAPTCHA_HOST, settings.CAPTCHA_PORT), 'headless': True } s.set_options(opt) db.session.add(s) db.session.commit()
mlab.connect() fake = Faker() print(fake.address()) for i in range(50): # print("Saving servive", i + 1) new_service = Service( name=fake.name(), yob=randint(1990, 2000), gender=randint(0, 1), height=randint(150, 190), phone=fake.phone_number(), address=fake.address(), status=choice([True, False]), image= "https://globalcosmeticsnews.com/wp-content/uploads/2017/11/ceee4096d5685eeea05189db7dc04044.jpg", description=fake.sentence(nb_words=10, variable_nb_words=True, ext_word_list=None), measurements=[randint(60, 100), randint(60, 100), randint(60, 100)], ) # new_service.save() for j in range(50): # print("Customer......", i + 1) new_customer = Customer(name=fake.name(), gender=randint(0, 1), phone=fake.phone_number(),
from models.service import Service import mlab from faker import Faker from random import randint, choice mlab.connect() fake = Faker() for i in range(50): print("saving service", i + 1, ".......") new_service = Service(name=fake.name(), yob=randint(1990, 2000), gender=randint(0, 1), height=randint(150, 190), phone=fake.phone_number(), address=fake.address(), Status=choice([True, False])) new_service.save()
def admin(): all_service = Service.objects() return render_template('admin.html', all_service=all_service)
def find(g): all_service = Service.objects(status=False, gender=g) return render_template('service.html', all_service=all_service)
from models.service import Service import mlab mlab.connect() item = Service.objects() for i in item: if i is not None: i.delete() print('Deleting item ....') else: print("service not found")
def detail(service_id): service = Service.objects().with_id(service_id) return render_template('detail.html', service = service )
import mlab from models.service import Service from faker import Faker from random import randint, choice from cFake import * mlab.connect() fake = Faker() # print(fake.address()) # create Document # service = Service(name="Chung", yob=1997, gender=1,height=168,phone="01693446595", address="Hà Nội", status= False) for i in range(10): print(i, "....") g = randint(0, 1) if g == 0: n = female_name() elif g == 1: n = male_name() service = Service(name=n, yob=randint(1990, 2001), gender=g, height=randint(150, 190), phone=sdt(), address=tp(), status=choice([True, False])) service.save()
from mlab import mlab_connect from models.service import Service from faker import Faker from random import choice, randint service_faker = Faker() mlab_connect() Service.drop_collection() for _ in range(30): service = Service(name= service_faker.name(), yob=randint(1995, 2000), gender =randint(0, 1), height=randint(140, 170), occupied=choice([False, True]), phone="12345") service.save()
link = img.get('src') if "scale-to-width-down/300" in link: image = link break name = soup.find('h1', class_='page-header__title').text # description = soup.find('div', class_ = "mw-content-ltr mw-content-text").findAll('p') # for p in description: # if "is a" in p: # description = p # break # # print(description) # height = soup.find('table', class_ = 'infobox box colored bordered innerbordered fill-td type-character list-noicon float-right-clear').find('span', class_ ='smw-highlighter smwttinline').span fake = Faker() service = Service( image, name, yob=0, # Year of birth gender=1, #0: female, 1: male height=151, measurements=[67, 55, 64], # List phone=fake.phone_number(), address="Hidden Leaf Village", description= "Sasuke Uchiha (うちはサスケ, Uchiha Sasuke) is one of the last surviving members of Konohagakure's Uchiha clan. After his older brother, Itachi, slaughtered their clan, Sasuke made it his mission in life to avenge them by killing Itachi. He is added to Team 7 upon becoming a ninja and, through competition with his rival and best friend, Naruto Uzumaki, Sasuke starts developing his skills. ", status=choice([True, False])) service.save()
def admin(): if 'logged_admin' in session: all_service = Service.objects() return render_template("admin.html", all_service=all_service) else: return redirect(url_for('login_admin'))
def _parse(self, model: List[Dict[str, Any]]) -> bool: # Store ip: service_name service_ips = {} # Store span_id: span span_ids = {} # Store all services with their respective endpoint ip's for span in model: span_ids[span['id']] = span local = span['localEndpoint'] if 'localEndpoint' in span else {} remote = span['remoteEndpoint'] if 'remoteEndpoint' in span else {} source_name = local['serviceName'] if 'serviceName' in local else '' target_name = remote[ 'serviceName'] if 'serviceName' in remote else '' if source_name: if source_name not in self._services: source = Service(source_name) self._services[source_name] = source service_ips[local['ipv4']] = source_name if target_name: if target_name not in self._services: source = Service(target_name) self._services[target_name] = source service_ips[remote['ipv4']] = target_name # Add operations for span in model: local = span['localEndpoint'] if 'localEndpoint' in span else {} if local['ipv4'] in service_ips: service = service_ips[local['ipv4']] elif 'serviceName' in local and local[ 'serviceName'] in self._services: service = local['serviceName'] # Unknown service else: return False self._services[service].add_operation(Operation(span['name'])) # Add dependencies for span in model: if 'parentId' in span: # Callee service_name = span['localEndpoint']['serviceName'] operation_name = span['name'] operation = self._services[service_name].operations[ operation_name] # Caller parent_id = span['parentId'] parent_span = span_ids[parent_id] local = parent_span['localEndpoint'] parent_service_name = service_ips[local['ipv4']] parent_operation_name = parent_span['name'] parent_operation = self._services[ parent_service_name].operations[parent_operation_name] parent_operation.add_dependency(operation) return True
def admin(): if "loggedin" in session: all_service = Service.objects() return render_template('admin.html', all_service=all_service) else: return redirect(url_for("login"))
from models.service import Service import mlab mlab.connect() all_service = Service.objects() # list first_service = all_service[0] print(first_service.name)
from random import randint, choice mlab.connect() fake = Faker() for i in range(50): print("Saving service", i + 1, "......") new_service = Service( name=fake.name(), yob=randint(1990, 2000), gender=randint(0, 1), height=randint(150, 190), phone=fake.phone_number(), address=fake.address(), status=randint(0, 1), description=fake.sentence(nb_words=10, variable_nb_words=True, ext_word_list=None), measurements=[randint(60, 100), randint(60, 100), randint(60, 100)], image= 'https://dantricdn.com/thumb_w/640/2017/hotgirl-reuters-kieu-trinh6-1496928968014.jpg' ) new_service.save() # for i in range(50): # print("Saving customer", i+1,"......") # new_customer = Customer( # name = fake.name(), # gender = randint(0,1),
def detail(id): all_service = Service.objects() return render_template('detail.html', all_service=all_service)
def find(gender): service_gender = Service.objects(gender=gender) return render_template('find.html', service_gender=service_gender)
from models.service import Service import mlab mlab.connect() # all_service = Service.objects() # first_service = all_service[0] # print(first_service.address) id_to_find = "5b2ba7f2bc54f42684b0c46a" # hera = Service.objects().get(id=id_to_find) person = Service.objects().with_id(id_to_find) if person is not None: # hera.delete() # print(person.name) print(person.yob) person.update(set__yob=1995) person.reload() print(person.yob) else: print("not found") # print(hera.to_mongo())
def service(): service_data = {"name": fake.first_name(), "description": fake.text(100)} service = Service.create(**service_data, token=secrets.token_urlsafe(31)) yield service service.delete()
def search(g): all_service = Service.objects(gender=g,yob__lte = 1998,height__gte=165,address__icontains="Hà Nội") return render_template('search.html',all_service=all_service)
def search_all(): all_service = Service.objects() return render_template( "search.html", all_service = all_service)
def delete_all(): all_service = Service.objects() for service in all_service: service.delete() return render_template('service.html')
def search(g): all_service = Service.objects(gender=g) return render_template( "search.html", all_service=all_service )
def search(): all_service = Service.objects() return render_template( 'search.html', all_service = all_service )
def detail(service_id): all_service = Service.objects() id_to_get = Service.objects().get(id=service_id) return render_template('detail.html', id_to_get=id_to_get)
def index(): all_services = Service.objects() return render_template('index.html', all_services=all_services)
import mlab from models.service import Service mlab.connect() all_services = Service.objects() all_services.delete()
# gender = randint(0,1) , # phone = fake.phone_number(), # email = fake.email(), # job = fake.job(), # company = fake.company(), # contacted = choice([True, False]) # ) # new_customer.save() mlab.connect() new_service = Service( name="Lương Mạnh", yob=1995, gender=1, height=175, phone="01662595895", address="Hà Nội", status=False, description="Đẹp trai, cool ngầu", image="../static/image/manhdeptrai.jpg", measurements=["unknow", "unknow", "unknow"], ) new_service.save() new_user = User(fullname="Lương Mạnh", email="aaA", username="******", password="******") new_user.save()
def search(g): all_service = Service.objects(gender=g, yob__lte=1998) return render_template('search.html', all_service=all_service)
def analysis(): error = 0 income = float(session['income']) saving = float(session['saving']) money = round(income - saving, 2) if request.method == "GET": return render_template('detail.html', money=money) elif request.method == "POST": form = request.form n1 = form['n1'] n2 = form['n2'] n3 = form['n3'] n4 = form['n4'] n5 = form['n5'] if n1 == "" or n2 == "" or n3 == "" or n4 == "" or n5 == "": error = 1 return render_template('detail.html', money=money, error=error) else: n1 = int(form['n1']) n2 = int(form['n2']) n3 = int(form['n3']) n4 = int(form['n4']) n5 = int(form['n5']) if (n1 + n2 + n3 + n4 + n5) != 100: error = 2 return render_template('detail.html', money=money, error=error) else: n1 = round(n1 * money / 100, 2) n2 = round(n2 * money / 100, 2) n3 = round(n3 * money / 100, 2) n4 = round(n4 * money / 100, 2) n5 = round(n5 * money / 100, 2) food = round(n1 * 0.6, 2) go = round(n1 * 0.1, 2) life = round(n1 * 0.2, 2) other = round(n1 * 0.1, 2) book = round(n2 * 0.4, 2) training = round(n2 * 0.6, 2) all_food = Service.objects(type="food", price__lte=food * 1000000 / 90).limit(6) all_book = Service.objects(type="book", price__lte=n2 * 1000000).limit(6) all_luxury = Service.objects(type="luxury", price__lte=n3 * 1000000).limit(6) all_charity = Service.objects(type="charity", price__lte=n4 * 1000000).limit(6) all_invest = Service.objects(type="invest", price__lte=n5 * 1000000).limit(6) count_food = len(all_food) count_book = len(all_book) count_luxury = len(all_luxury) count_charity = len(all_charity) count_invest = len(all_invest) return render_template('spending.html', money=money, n1=n1, n2=n2, n3=n3, n4=n4, n5=n5, food=food, go=go, life=life, other=other, book=book, training=training, all_food=all_food, all_book=all_book, all_luxury=all_luxury, all_charity=all_charity, all_invest=all_invest, count_food=count_food, count_book=count_book, count_luxury=count_luxury, count_charity=count_charity, count_invest=count_invest)
import mlab from models.service import Service mlab.connect() service = Service( name="Chè thái sầu riêng tươi", type="food", price=28000, link="https://www.now.vn/ha-noi/co-lien-che-da-nang", picture= "https://media.foody.vn/res/g20/193679/s600x600/201682173441-che-thai-sau-rieng-tuoi.jpg" ) service.save()