Exemplo n.º 1
0
def home():
    latitude = safe_float(request.args.get('city_lat'))
    longitude = safe_float(request.args.get('city_long'))
    radius = safe_int(request.args.get('radius'))
    python = bool(request.args.get('python'))
    r = bool(request.args.get('r'))

    people = db.get_session().query(Person).join(Person.facts).\
             join(Facts.airport).\
             filter(Facts.active == True)

    if python:
        people = people.filter(Facts.python == True)
    if r:
        people = people.filter(Facts.r == True)

    if latitude is not None and longitude is not None and radius:
        people = (
            person for person in people
            if person.facts.airport.is_within_radius_of(
                radius,
                latitude,
                longitude,
                units='km'
            )
        )

    return render_template('index.html', people=people)
Exemplo n.º 2
0
def home():
    latitude = safe_float(request.args.get('city_lat'))
    longitude = safe_float(request.args.get('city_long'))
    radius = safe_int(request.args.get('radius'))
    closest = safe_int(request.args.get('closest'))
    python = bool(request.args.get('python'))
    r = bool(request.args.get('r'))

    people = db.get_session().query(Person).join(Person.facts).\
             join(Facts.airport).\
             filter(Facts.active == True)

    if python:
        people = people.filter(Facts.python == True)
    if r:
        people = people.filter(Facts.r == True)

    if latitude is not None and longitude is not None and radius:
        people = (
            person for person in people
            if person.facts.airport.is_within_radius_of(
                radius,
                latitude,
                longitude,
                units='km'
            )
        )
    elif latitude is not None and longitude is not None and closest:
        # not searching radius but rather closest people
        people = sorted(people,
            key=lambda x: x.facts.airport.distance_from(latitude, longitude))[:closest]

    return render_template('index.html', people=people)
Exemplo n.º 3
0
def home():
    latitude = safe_float(request.args.get('city_lat'))
    longitude = safe_float(request.args.get('city_long'))
    radius = safe_int(request.args.get('radius'))
    closest = safe_int(request.args.get('closest'))
    python = bool(request.args.get('python'))
    r = bool(request.args.get('r'))

    people = db.get_session().query(Person).join(Person.facts).\
             join(Facts.airport).\
             filter(Facts.active == True)

    if python:
        people = people.filter(Facts.python == True)
    if r:
        people = people.filter(Facts.r == True)

    if latitude is not None and longitude is not None and radius:
        people = (person for person in people
                  if person.facts.airport.is_within_radius_of(
                      radius, latitude, longitude, units='km'))
    elif latitude is not None and longitude is not None and closest:
        # not searching radius but rather closest people
        people = sorted(people,
                        key=lambda x: x.facts.airport.distance_from(
                            latitude, longitude))[:closest]

    return render_template('index.html', people=people)
Exemplo n.º 4
0
 async def wait_then_delete(self, message, user):
     wait_time = safe_float(self.db[user.id, 'delete_response_time'])
     await asyncio.sleep(wait_time)
     try:
         await self.client.delete_message(message)
     except (Forbidden, NotFound):
         pass
Exemplo n.º 5
0
def parse_paper_size(option, opt_str, value, parser):
    # read paper size/print all known paper-size names
    value = value.upper()
    parser.values.use_bbox = False
    try:
        parser.values.paper_size = (pw, ph) = paper_size[value]
        log.debug("Paper size set to %s (%dmm x %dmm)", value, pw, ph)
        return
    except KeyError:
        pass  # ok, maybe query or bbox passed

    if value == "QUERY":
        for name in sorted(paper_size.keys()):
            (pw, ph) = paper_size[name]
            print "%-4s: %dmm x %dmm" % (name, pw, ph)
        sys.exit()

    if value.startswith("BBOX"):  # Bounding box
        parser.values.paper_size = (0.0, 0.0)
        parser.values.use_bbox = True

        # variants:
        #  1. BBOX
        #  2. BBOX:number
        #  3. BBOX:number,number
        #  4. BBOX:number,number,number,number

        mT = mB = mL = mR = 0.0
        if value.startswith("BBOX:"):
            tmp = value[5:].split(",", 4)
            if len(tmp) == 1:  # BBOX:number
                mT = mB = mL = mR = abs(utils.safe_float(tmp[0]))
            elif len(tmp) == 2:  # BBOX:number,number
                mL = mR = abs(utils.safe_float(tmp[0]))
                mT = mB = abs(utils.safe_float(tmp[1]))
            elif len(tmp) == 4:  # BBOX:number,number,number,number
                mL = abs(utils.safe_float(tmp[0]))
                mR = abs(utils.safe_float(tmp[1]))
                mT = abs(utils.safe_float(tmp[2]))
                mB = abs(utils.safe_float(tmp[3]))
            else:
                log.warning("Bbox: invalid syntax, margins set to 0")

        parser.values.bbox_margin_L = mL
        parser.values.bbox_margin_R = mR
        parser.values.bbox_margin_T = mT
        parser.values.bbox_margin_B = mB
        log.debug(
            "BBox margins: left=%0.2f, right=%0.2f, top=%0.2f, bottom=%0.2f",
            mL, mR, mT, mB)
    else:
        log.warning("Know nothing about paper size %s, defaults to A4" % value)
        parser.values.paper_size = paper_size['A4']
Exemplo n.º 6
0
    def get_args(self, command, tokens, message, user, server, channel):
        args = []
        mention_index = 0
        for index in range(len(self.commands[command]["args"])):
            arg = self.commands[command]['args'][index]

            if arg == "user":
                args.append(user)

            elif arg == "message":
                args.append(message)

            elif arg == "server":
                args.append(server)

            elif arg == "channel":
                args.append(channel)

            elif arg == "mention":
                if mention_index < len(message.mentions):
                    args.append(message.mentions[mention_index].id)
                    mention_index += 1
                else:
                    args.append(None)

            elif arg == '*mentions':
                args.append([p.id for p in message.mentions])

            elif len(tokens) != 0:

                if arg == 'force?':
                    args.append(self.autocomplete(tokens.pop().lower(), self.force_words))
                elif arg == 'no?':
                    args.append(self.autocomplete(tokens.pop().lower(), self.no_words))
                elif arg == 'yes?':
                    args.append(self.autocomplete(tokens.pop().lower(), self.yes_words))
                elif arg == 'str':
                    args.append(tokens.pop())
                elif arg == '*str':
                    args.append([tokens.pop().lower() for x in
                                    range(len(tokens) - (len(self.commands[command]['args']) - index - 1))])

                elif arg == 'int':
                    args.append(safe_int(tokens.pop()))
                elif arg == 'float':
                    args.append(safe_float(tokens.pop()))


        return args
Exemplo n.º 7
0
def parse_paper_size(option, opt_str, value, parser):
	# read paper size/print all known paper-size names
	value = value.upper()
	parser.values.use_bbox = False
	try:
		parser.values.paper_size = (pw, ph) = paper_size[value]
		log.debug("Paper size set to %s (%dmm x %dmm)", value, pw, ph)
		return
	except KeyError:
		pass # ok, maybe query or bbox passed
	
	if value == "QUERY":
		for name in sorted(paper_size.keys()):
			(pw, ph) = paper_size[name]
			print "%-4s: %dmm x %dmm" % (name, pw, ph)
		sys.exit()
	
	if value.startswith("BBOX"): # Bounding box
		parser.values.paper_size = (0.0, 0.0)
		parser.values.use_bbox = True

		# variants:
		#  1. BBOX
		#  2. BBOX:number
		#  3. BBOX:number,number
		#  4. BBOX:number,number,number,number
		
		mT = mB = mL = mR = 0.0
		if value.startswith("BBOX:"):
			tmp = value[5:].split(",", 4)
			if len(tmp) == 1: # BBOX:number
				mT = mB = mL = mR = abs(utils.safe_float(tmp[0]))
			elif len(tmp) == 2: # BBOX:number,number
				mL = mR = abs(utils.safe_float(tmp[0]))
				mT = mB = abs(utils.safe_float(tmp[1]))
			elif len(tmp) == 4: # BBOX:number,number,number,number
				mL = abs(utils.safe_float(tmp[0]))
				mR = abs(utils.safe_float(tmp[1]))
				mT = abs(utils.safe_float(tmp[2]))
				mB = abs(utils.safe_float(tmp[3]))
			else:
				log.warning("Bbox: invalid syntax, margins set to 0")

		parser.values.bbox_margin_L = mL
		parser.values.bbox_margin_R = mR
		parser.values.bbox_margin_T = mT
		parser.values.bbox_margin_B = mB
		log.debug("BBox margins: left=%0.2f, right=%0.2f, top=%0.2f, bottom=%0.2f", mL, mR, mT, mB)
	else:
		log.warning("Know nothing about paper size %s, defaults to A4" % value)
		parser.values.paper_size = paper_size['A4']