Exemple #1
0
def get_senadores_metadata_atual():
	# Gets attributes from parlamentares and saves into Firebase 
	# --> still needs to put right below 'senadores URL', now it's using FB id there...

	url = 'http://legis.senado.gov.br/dadosabertos/senador/lista/atual'
	uh = urllib.urlopen(url)
	data = uh.read()
	tree = ET.fromstring(data)
	senadores_tree = tree.findall('.//IdentificacaoParlamentar')
	
	senadores_dict = {}
	for sen in senadores_tree:
		
		codigo = sen.find('CodigoParlamentar').text
		# creates object with id 'codigo' and all data nested into that
		senadores_dict[codigo] = {}
		senadores_dict[codigo]['NomeParlamentar'] 			= sen.find('NomeParlamentar').text
		senadores_dict[codigo]['SexoParlamentar'] 			= sen.find('SexoParlamentar').text
		senadores_dict[codigo]['FormaTratamento'] 			= sen.find('FormaTratamento').text
		senadores_dict[codigo]['UrlPaginaParlamentar']		= sen.find('UrlPaginaParlamentar').text
		senadores_dict[codigo]['UrlFotoParlamentar']		= sen.find('UrlFotoParlamentar').text
		senadores_dict[codigo]['EmailParlamentar'] 			= sen.find('EmailParlamentar').text
		senadores_dict[codigo]['SiglaPartidoParlamentar'] 	= sen.find('SiglaPartidoParlamentar').text
		senadores_dict[codigo]['UfParlamentar'] 			= sen.find('UfParlamentar').text

	#firebase.post('/senadores', senadores_dict) # Substituir posteriormente por método genérico para salvar os dados
	f = Firebase(FBURL + '/senadores')
	f.put(senadores_dict)
Exemple #2
0
def set_temp(request):
    # Virtual DEvice
    f = Firebase(
        'https://developer-api.nest.com/devices/thermostats/N96fw5MnBnmwH4ZBZVOgvMwgbVqewXOS',
        auth_token=
        "c.9tKvASa4R9fG9hx8kFb9QeUMzxo5OalPNFY9YswzKzENRKn51hNdnx6ctVVjQgRUiCbumqTgFZtWnBDtJFzXLFM8QgdlwtRjWtB3rgfDog5juDNHXdpON9XtNyzulgjMJnPYIbgS74bQ8cUc"
    )
    # ACL Device
    #f=Firebase('https://developer-api.nest.com/devices/thermostats/Q3Vcf1OhcRbUfcweDwMdCkNGApfAG1NY',auth_token="c.Q2DQ3IxfJwtrqg6vMRDjQHx4DBF30BoAwv8kOmV5wSCsTmFPTZR8gLxURcomK3tvWgvJAzpCFNfnZt7b56Va1YkxUaGwpgOXjBpX1gg7vPUj6ayinv8DCGSIzsx5Klz58xRVEtaS1ZBVlTyG")
    tar_temp = request.GET['a']
    tar_temp = int(tar_temp)
    f.put({"target_temperature_f": tar_temp})
    return HttpResponse(str(tar_temp))
Exemple #3
0
def put_point_firebase(key, point):
    # initiate the connexion to Firebase
    token = create_token(FIREBASE_SECRET, AUTH_PAYLOAD)
    firebase_project = FIREBASE_PROJECT + '/' + ROOT_OBJECT + '/' + key + '/.json'
    firebase = Firebase(firebase_project, token)
    firebase.put(point)
Exemple #4
0
destinated_location = 0  # Destinated location
firebase_URL = str(
    'https://ece158final.firebaseio.com/') + locations[destinated_location]
firebase_obj = Firebase(
    firebase_URL)  # Firebase object for sending HTTP requests
date = time.strftime('%m/%d/%Y')  # Initialize time variable
data = None  # Declare data variable

try:
    while True:
        # Let Arduino know that Raspberry Pi has connected to Firebase and is ready
        GPIO.output(RPi_status_output, GPIO.HIGH)

        if date is not time.strftime('%m/%d/%Y'):
            # Push data to Firebase before resetting counters
            result = firebase_obj.put(data)
            # Reset occupancy every day
            # occupancy_enter = 0
            # occupancy_exit = 0

        # Increment enter counter if PIR_enter sensor sends digital HIGH (person detected)
        if GPIO.event_detected(PIR_enter_input):
            occupancy_enter += 1
            GPIO.output(
                PIR_enter_output,
                GPIO.HIGH)  # Let Arduino know PIR_enter sensor triggered
        else:
            GPIO.output(
                PIR_enter_output,
                GPIO.LOW)  # Let Arduino know PIR_enter sensor detected nothing
Exemple #5
0
import subprocess, StringIO, csv
from simplejson import dumps
from firebase import Firebase
from time import sleep, time

firebase = Firebase('https://<your_app>.firebaseio.com/stations')

def fetch_data():
        # get the newest capture.csv file, then use awk to get only Station data
        cmd = r"cat /tmp/`ls -Art /tmp | grep capture | tail -n 1` | awk '/Station/{y=1;next}y'"
        data = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE).stdout.read()
        f = StringIO.StringIO(data)
        # convert the data to a list of dict() objects
        conv = lambda row: {'station_mac':row[0], 'first_time_seen':row[1], 'last_time_seen':row[2], 'power':row[3]}
        data = [row for row in csv.reader(f, delimiter=',') if len(row) != 0]
        return [conv(row) for row in data] 

while True:
        print firebase.put(fetch_data())
        sleep(1)
def put_point_firebase(key, point):
    # initiate the connexion to Firebase
    token = create_token(FIREBASE_SECRET , AUTH_PAYLOAD)
    firebase_project = FIREBASE_PROJECT + '/' + ROOT_OBJECT + '/' + key +'/.json'
    firebase = Firebase(firebase_project, token)
    firebase.put(point)
Exemple #7
0
import subprocess, StringIO, csv
from simplejson import dumps
from firebase import Firebase
from time import sleep, time

firebase = Firebase('https://<your_app>.firebaseio.com/stations')


def fetch_data():
    # get the newest capture.csv file, then use awk to get only Station data
    cmd = r"cat /tmp/`ls -Art /tmp | grep capture | tail -n 1` | awk '/Station/{y=1;next}y'"
    data = subprocess.Popen(cmd, shell=True,
                            stdout=subprocess.PIPE).stdout.read()
    f = StringIO.StringIO(data)
    # convert the data to a list of dict() objects
    conv = lambda row: {
        'station_mac': row[0],
        'first_time_seen': row[1],
        'last_time_seen': row[2],
        'power': row[3]
    }
    data = [row for row in csv.reader(f, delimiter=',') if len(row) != 0]
    return [conv(row) for row in data]


while True:
    print firebase.put(fetch_data())
    sleep(1)
Exemple #8
0
#!/usr/bin/python

from __future__ import print_function
import serial
#firebase python wrapper: https://github.com/mikexstudios/python-firebase
from firebase import Firebase

f = Firebase('https://leon-first-firebase.firebaseio.com/data/force_array')

force_arr = []
with serial.Serial('/dev/ttyACM0', 9600, timeout=5) as ser:
    while True:
        line = ser.readline().strip()
        print("line:" + line)
        if len(force_arr) > 20:
            force_arr.pop(0)
        force_arr.append(line)
        f.put(force_arr)

print("finished!")