Пример #1
0
def configure(old_profile=None):
    profile = []

    print "I can check news for you."
    if old_profile is None:
        old_profile = []
    else:
        print "I have found news feeds."
        if yn_input("Do you want to change them", default=False):
            for feed in old_profile:
                print "%d entries from %s" % (feed['entries'], feed['url'])
                if yn_input("Do you want to change this line", default=False):
                    t = queryFeed(
                        URL=feed['url'],
                        entries=feed['entries']
                    )
                    if t:
                        profile.append(t)
                    else:
                        print "This input is not valid"
                else:
                    profile.append(feed)

    while True:
        if yn_input("Do you want to add a news feed", default=True):
            t = queryFeed()
            if t:
                profile.append(t)
            else:
                print "This input is not valid"
        else:
            break

    return profile
Пример #2
0
def configure(old_profile=None):
    if old_profile is None:
        old_profile = {"name": "", "id": ""}

    weather_client = yweather.Client()

    print "For weather requests please enter your location"
    location = user_input("Location", default=old_profile["name"])

    while location:
        woeid = weather_client.fetch_woeid(location)
        if not woeid:
            print ("Weather not found. Please try another location.")
            location = raw_input("Location: ")
            continue

        weather = weather_client.fetch_weather(woeid)
        print "I have found %s, %s in %s (%s, %s)" % (
            weather["location"]["city"],
            weather["location"]["region"],
            weather["location"]["country"],
            weather["geo"]["lat"],
            weather["geo"]["long"],
        )
        if yn_input("Is this correct", default=True):
            return {"name": location, "id": woeid}
        else:
            location = raw_input("Location: ")

    return {"name": "", "id": ""}
Пример #3
0
def configure(old_profile):
    if not old_profile:
        old_profile = {'host': '', 'guid': ''}
    else:
        print "Host: %s\nGUID: %s" % (old_profile['host'], old_profile['guid'])
        if yn_input("Is this information correct"):
            return old_profile

    print "Open iTunes and choose IRIS as a remote. Enter any passcode"
    host, guid = DACP.pair()
    return {'host': host, 'guid': guid}
Пример #4
0
def configure(old_profile=None):
    profile = {"lights": [], "status_endpoint": "", "thermometer_key": "", "lock_key": ""}

    def add_light(name="", on_endpoint="", off_endpoint=""):
        name = user_input("Light's name", default=name).lower()
        on_endpoint = user_input("Light's ON endpoint", default=on_endpoint)
        off_endpoint = user_input("Light's OFF endpoint", default=off_endpoint)

        if name and on_endpoint and off_endpoint:
            profile["lights"].append({"name": name, "on_endpoint": on_endpoint, "off_endpoint": off_endpoint})
            return True
        else:
            return False

    print "I can control your home."
    if old_profile is None:
        old_profile = {"lights": [], "status_endpoint": "", "thermometer_key": "", "lock_key": ""}
    else:
        print "I have found light endpoints."
        if yn_input("Do you want to change them", default=False):
            for light in old_profile["lights"]:
                print "%s with endpoints (%s, %s)" % (light["name"], light["on_endpoint"], light["off_endpoint"])
                add_light(light["name"], light["on_endpoint"], light["off_endpoint"])
        else:
            profile["lights"] = old_profile["lights"]
    while True:
        if yn_input("Do you want to add a light", default=True):
            if not add_light():
                break
        else:
            break

    print "To get status information I need a JSON formatted URL endpoint"
    profile["status_endpoint"] = user_input("Status endpoint", default=old_profile["status_endpoint"])
    if profile["status_endpoint"]:
        profile["thermometer_key"] = user_input("Thermometer key", default=old_profile["thermometer_key"])
        profile["lock_key"] = user_input("Lock key", default=old_profile["lock_key"])

    return profile
Пример #5
0
def configure(old_profile=None):
    profile = []

    print "I can check emails for you."
    if old_profile is None:
        old_profile = []
    else:
        print "I have found email addresses."
        if yn_input("Do you want to change them", default=False):
            for account in old_profile:
                print "Server: %s\nUsername: %s" % (
                    account['server'], account['user']
                )
                if yn_input("Do you want to change this line", default=False):
                    t = queryAccount(
                        user=account['user'],
                        server=account['server']
                    )
                    if t:
                        profile.append(t)
                    else:
                        print "These credentials are not valid"
                else:
                    profile.append(account)

    while True:
        if yn_input("Do you want to add an account", default=True):
            t = queryAccount()
            if t:
                profile.append(t)
            else:
                print "These credentials are not valid"
        else:
            break

    return profile
Пример #6
0
def get_mail(old_profile=None, first_name="", last_name=""):
    if not old_profile:
        old_profile = {
            'address': '',
            'user': '',
            'server': '',
            'password': '',
            'recipient': ''
        }

    print "IRIS uses your Gmail to send notifications"

    success = False

    mp = {}

    mp['address'] = user_input("Email address", default=old_profile['address'])
    default_user = mp['address']
    if re.findall("(g(oogle)?mail)", mp['address']):
        user, host = tuple(mp['address'].split('@'))
        sug = user + "+IRIS@" + host
        print """You have a gmail account. I can change your address to %s.
This won't stop you from receiving emails but allow you to
filter for my notifications easily!""" % sug
        if yn_input(query="Do you want me to do that", default=False):
            mp['address'] = sug

    while not success:
        mp['user'] = user_input(
            "SMTP User",
            default=old_profile['user'] or default_user
        )

        pw = user_input(password=True)
        mp['server'] = user_input(
            "SMTP Server",
            default=old_profile['server'] or "smtp.gmail.com"
        )

        if mp['user']:
            print("\nI will now connect to SMTP...")
            try:
                session = app_utils.smtp_login(mp['server'], mp['user'], pw)
                session.quit()
                success = True
            except app_utils.SMTPAuthenticationError:
                print("\nYour credentials are wrong. Please check them")
        else:
            print("\nYou will not be able to use SMTP")
            success = True
            return {}

    mp['password'] = base64.b64encode(pw)

    if first_name and last_name:
        mp['recipient'] = "%s %s <%s>" % (first_name, last_name, mp['address'])
    else:
        mp['recipient'] = mp['address']

    if yn_input("Do you want me to send a test mail", default=False):
        app_utils.emailUser(
            {'mail': mp},
            subject="IRIS TEST MAIL",
            body="Test"
        )
    return mp