Ejemplo n.º 1
0
def send_daily_report(hours_of_day: list):
    audience = get_all_humans_for_telegram_notifications(
        hours_of_day=hours_of_day)

    # create bot
    bot = get_telegram_bot_instance()
    # send to audience
    notify_admin = True
    count = 0
    for member in audience:
        try:
            human = Human(human_id=member[HumanProperties.ID.value])

            # get most recent coordinates
            most_recent_location = human.get_most_recent_location()
            if most_recent_location is None:
                return "NOTHING TO SHOW. SHARE YOUR LOCATION FIRST."
            lat, lng = most_recent_location
            human.send_proximity_alert(lat=lat, lng=lng)
            count += 1

        except Exception as e:
            if notify_admin:
                bot.send_message(
                    chat_id=int(
                        CONFIG.get('telegram-credentials-telegram-admin-id')),
                    text="[ADMIN] `send_daily_report` exception : {}".format(
                        e))
                notify_admin = False

    # alert admin
    bot.send_message(
        chat_id=int(CONFIG.get('telegram-credentials-telegram-admin-id')),
        text="[ADMIN] Sent proximity report to {}/{} humans.".format(
            count, len(audience)))
Ejemplo n.º 2
0
def local_map(human_id):
	try:
		human = Human(human_id=human_id)
	except Exception as e:
		logger.error(e)
		abort(403)

	# get most recent coordinates
	most_recent_location = human.get_most_recent_location()
	if most_recent_location is None:
		return "Nothing to show. Share your location first.", 200
	else:
		lat, lng = most_recent_location

	self_lat_lng = [lng, lat]
	self_geojson_feature = {
		'type': "Point",
		'coordinates': self_lat_lng
	}

	risky_humans_geojson = get_risky_humans_geojson(
		lat=lat,
		lng=lng,
		days_window=int(CONFIG.get('days_window')),
		km_radius=int(CONFIG.get('km_radius'))
	)

	return render_template(
		MAP_TEMPLATE,
		self_geojson_feature=self_geojson_feature,
		self_lat_lng=self_lat_lng,
		risky_humans_geojson=risky_humans_geojson,
		km_radius=int(CONFIG.get('km_radius')),
		include_legend=True,
		zoom_level=9
	)