예제 #1
0
#!/usr/bin/env python3

import os, sys, time, random, threading, queue, json
from housepy import osc, config, log, process

process.secure_pid(os.path.abspath(os.path.join(os.path.dirname(__file__), "run")))

osc.verbose = False
SIGDIR = os.path.abspath(os.path.join(os.path.dirname(__file__), "conversations"))

def retrieve_convo(filename):
    try:        
        if filename is None:
            signal_files = [f for f in os.listdir(SIGDIR) if f[-4:] == "json"]
            path = os.path.join(SIGDIR, random.choice(signal_files))
        else:
            path = os.path.join(SIGDIR, filename)
        log.info("Loading conversation data from %s..." % path)
        with open(path, 'r') as handle:
            content = handle.read()
            signal = json.loads(content)
    except Exception as e:
        log.error(log.exc(e))
        exit()
    return signal    


def main():

    try:
예제 #2
0
#!/usr/bin/env python3

import os, json, model, random, visualizer, base64, zlib
from housepy import config, log, strings, server, util
from housepy import process as pc
from process import process_walk

pc.secure_pid(os.path.join(os.path.dirname(__file__), "run"))


class Home(server.Handler):
    def get(self, page=None, walk_id=None):
        log.info("Home.get %s" % page)
        if not len(page):
            return self.render("home.html")
        if page == "walk":
            if len(walk_id) and walk_id == "c":
                walks = model.fetch_walks()
                if len(walks):
                    walk_id = random.choice(walks)['id']
                else:
                    walk_id = None
            elif not type(walk_id) == int and not len(walk_id):
                walk_id = None
            return self.render("walk.html",
                               sequence=json.dumps(
                                   model.fetch_sequence(walk_id)),
                               ref_id=walk_id)
        if page == "walks":
            return self.render("walks.html",
                               walks=model.fetch_walks(hidden=True))
예제 #3
0
#!/usr/bin/env python3

import requests, json, time, os
from housepy import config, log, util, process

process.secure_pid(os.path.abspath(os.path.join(os.path.dirname(__file__), "run")))

while True:

    # current conditions
    try:
        url = "http://api.wunderground.com/api/%s/conditions/q/MA/North_Adams.json" % config['wunderground']
        response = requests.get(url)
        data = response.json()['current_observation']
        # log.info(json.dumps(data, indent=4))
        entry = {'t_utc': util.timestamp(), 'type': 'weather', 'temp_f': data['temp_f'], 'wind_mph': data['wind_mph']}
        log.info(json.dumps(entry, indent=4))
        response = requests.post(config['server'], json=entry)
        log.info(response)
    except Exception as e:
        log.error(log.exc(e))

    time.sleep(60)




# # hourly
# url = "http://api.wunderground.com/api/%s/hourly/q/MA/North_Adams.json" % config['wunderground']
# response = requests.get(url)
# data = response.json()
예제 #4
0
#!/usr/bin/env python3

import os, json, model, random, visualizer, base64, zlib
from housepy import config, log, strings, server, util
from housepy import process as pc
from process import process_walk

pc.secure_pid(os.path.join(os.path.dirname(__file__), "run"))


class Home(server.Handler):

    def get(self, page=None, walk_id=None):
        log.info("Home.get %s" % page)
        if not len(page):
            return self.render("home.html")        
        if page == "walk":            
            if len(walk_id) and walk_id == "c":
                walks = model.fetch_walks()
                if len(walks):
                    walk_id = random.choice(walks)['id']
                else:
                    walk_id = None
            elif not type(walk_id) == int and not len(walk_id):
                walk_id = None
            return self.render("walk.html", sequence=json.dumps(model.fetch_sequence(walk_id)), ref_id=walk_id) 
        if page == "walks":
            return self.render("walks.html", walks=model.fetch_walks(hidden=True))
        if page == "choose":
            return self.render("choose.html", walks=model.fetch_walks()) 
        if page in ["prepare", "route", "map", "thanks", "orientation", "background"]: