Exemple #1
0
def update_document(data):
    remote = urllib2.urlopen(config.get(CONFIG_KEY, "url"), timeout=config.getint(CONFIG_KEY, "timeout"))

    whois_data = json.loads(remote.read())

    try:
        if config.get(CONFIG_KEY, "overwrite_open"):  # DEPRECATED
            if not data.get("state"):
                data["state"] = {}
            data["state"] = {"open": len(whois_data["users"]) > 0}
    except ConfigParser.NoOptionError:
        pass

    if config.get(CONFIG_KEY, "update_open"):
        if not data.get("state"):
            data["state"] = {}
        data["state"]["open"] = len(whois_data["users"]) > 0 or data["state"].get("open", False)

    if not data.get("sensors"):
        data["sensors"] = {}

    if not data["sensors"].get("people_now_present"):
        data["sensors"]["people_now_present"] = []

    people_data = {"value": len(whois_data["users"])}

    if len(whois_data["users"]) > 0:
        people_data["names"] = whois_data["users"]

    data["sensors"]["people_now_present"].append(people_data)

    return data
Exemple #2
0
def update_document(data):
	remote = urllib2.urlopen(config.get(CONFIG_KEY, 'url'), timeout=config.getint(CONFIG_KEY, 'timeout'))

	current_date = datetime.datetime.now()

	if not data.get('events'):
		data['events'] = []

	components = vobject.readOne(remote)

	for event in components.contents['vevent']:
		# could be datetime or just date
		e_date = event.dtstart.value

		if type(e_date) is datetime.date:
			e_date = datetime.datetime.combine(e_date, datetime.time(0, 0))
		else:
			e_date = e_date.replace(tzinfo=None)

		# compare with timezone data removed
		if e_date < current_date:
			continue

		data['events'].append({
			'name': event.summary.value,
			'type': 'calendarevent',
			'timestamp': int(time.mktime((event.dtstart.value.timetuple()))),
			'extra': event.description.value,
		})

	return data
Exemple #3
0
def update_document(data):
	remote = urllib2.urlopen(config.get(CONFIG_KEY, 'url'), timeout=config.getint(CONFIG_KEY, 'timeout'))
	remote = json.load(remote)

	if not data.get('sensors'):
		data['sensors'] = {}
	
	if not data['sensors'].get('temperature'):
		data['sensors']['temperature'] = []
	if not data['sensors'].get('humidity'):
		data['sensors']['humidity'] = []
	if not data['sensors'].get('radiation'):
		data['sensors']['radiation'] = {}
		data['sensors']['radiation']['beta_gamma'] = []
	if not data['sensors'].get('barometer'):
		data['sensors']['barometer'] = []
                                                

	temp = {
		'value': '%.2f' % (float(remote[0]['datapoints'][0][0])),
		'unit': '°C',
		'location': 'Hardroom',
	}
	pressure = {
		'value': '%.2f' % (float(remote[1]['datapoints'][0][0])),
		'unit': 'hPA',
		'location': 'Hardroom',
	}
	hum = {
		'value': '%.2f' % (float(remote[2]['datapoints'][0][0])),
		'unit': '%',
		'location': 'Hardroom',
	}
	rad = {
		'value': '%.2f' % (float(remote[3]['datapoints'][0][0])),
		'unit': 'µSv/h',
		'location': 'Hardroom',
	}

	data['sensors']['temperature'].append(temp)
	data['sensors']['barometer'].append(pressure)
	data['sensors']['humidity'].append(hum)
	data['sensors']['radiation']['beta_gamma'].append(rad)

	return data
Exemple #4
0
def update_document(data):
	remote = urllib2.urlopen(config.get(CONFIG_KEY, 'url'), timeout=config.getint(CONFIG_KEY, 'timeout'))

	if not data.get('sensors'):
		data['sensors'] = {}

	if not data['sensors'].get('temperature'):
		data['sensors']['temperature'] = []

	sensor = {
		'value': float(remote.read()),
		'unit': '°C',
		'location': 'Inside',
	}

	data['sensors']['temperature'].append(sensor)

	return data
def update_document(data):
	remote = urllib2.urlopen(config.get(CONFIG_KEY, 'url'), timeout=config.getint(CONFIG_KEY, 'timeout')).read()
	remote = json.loads(remote)
	
	if not data.get('sensors'):
		data['sensors'] = {}

	lights_data = {}

	if config.get(CONFIG_KEY, 'update_open'):
		is_open = False

		if config.get(CONFIG_KEY, 'update_open_keys') == '*':
			keys_which_we_care_about = remote.keys()
		else:
			keys_which_we_care_about = config.get(CONFIG_KEY, 'update_open_keys').split(',')

		for key in keys_which_we_care_about:
			if remote[key]:
				is_open = True
				break

		if not data.get('state'):
			data['state'] = {}

		data['state']['open'] = is_open or data['state'].get('open', False)

	if not data['sensors'].get('ext_lights'):
		data['sensors']['ext_lights'] = []
	
	lights = {}
	for key, val in config.items(CONFIG_KEY):
		if key.startswith('name_'):
			lights[val] = remote[key[5:]]
	data['sensors']['ext_lights'].append(lights)
		
	return data
Exemple #6
0
def update_document(data):
	remote = urllib2.urlopen(config.get(CONFIG_KEY, 'url'), timeout=config.getint(CONFIG_KEY, 'timeout')).read()
	
	if not data.get('sensors'):
		data['sensors'] = {}

	lights_data = {}

	if config.get(CONFIG_KEY, 'update_open'):
		is_open = False

		i = 0
		for m in config.get(CONFIG_KEY, 'update_open_lightmask'):
			if m == '1' and remote[i] == '1':
				is_open = True

				break

			i += 1

		if not data.get('state'):
			data['state'] = {}

		data['state']['open'] = is_open or data['state'].get('open', False)


	if not data['sensors'].get('ext_lights'):
		data['sensors']['ext_lights'] = []
	
	lights = {}
	for key, val in config.items(CONFIG_KEY):
		if key.startswith('name_'):
			lights[val] = remote[int(key[5:])] == '1'
	data['sensors']['ext_lights'].append(lights)
		
	return data