Example #1
0
def delete_mail_gmail(user):
    if "last_mail_id" in user:
        base_service.authorized_curl(
            "https://www.googleapis.com/gmail/v1/users/me/messages/{}/trash".
            format(user["last_mail_id"]["S"]), user)
        return utils.send_message(
            "Following mail has been trashed\n" +
            format_gmail_message(get_message(user["last_mail_id"]["S"])))
    else:
        return utils.send_message("No mail present to delete")
Example #2
0
def get_fares(user, **args):
    s = {}
    if "start_place_id" in args:
        s["start_place_id"] = args["start_place_id"]
        if "end_place_id" in args:
            s["end_place_id"] = args["end_place_id"]
        else:
            s["end_latitude"] = args["end_latitude"]
            s["end_longitude"] = args["end_longitude"]
    else:
        if "end_place_id" in args:
            s = {
                "start_latitude": args['start_latitude'],
                "start_longitude": args["start_longitude"],
                "end_place_id": args["end_place_id"]
            }
        else:
            s = {
                "start_latitude": args['start_latitude'],
                "start_longitude": args["start_longitude"],
                "end_latitude": args["end_latitude"],
                "end_longitude": args["end_longitude"]
            }
    if "product" in args:
        s["product_id"] = args["product"]["product_id"]
        res = base_service.authorized_curl(
            "-X POST -H 'Content-Type: application/json' 'https://sandbox-api.uber.com/v1.2/requests/estimate' -d '{}'"
            .format(json.dumps(s)), user)
        res["product"] = args["product"]
        fares = [res]
    else:
        res_array = []
        if "start_place_id" in args:
            place_details = get_place(user, args["start_place_id"])
            products = get_products(user, place_details["lat"],
                                    place_details["lng"])
        else:
            products = get_products(user, args["start_latitude"],
                                    args["start_longitude"])
        for product in products["products"][:2]:
            s["product_id"] = product["product_id"]
            res = base_service.authorized_curl(
                "-X POST -H 'Content-Type: application/json' 'https://sandbox-api.uber.com/v1.2/requests/estimate' -d '{}'"
                .format(json.dumps(s)), user)
            res["product"] = product
            res_array.append(res)
        fares = res_array
    result = {"fares": fares, "args": args}
    return result
Example #3
0
def send_email(user, **args):
    reply = False
    if "message_id" in args:
        reply = True
        message = get_message(args["message_id"], user)
        args["to_email"] = get_from(message)
        args["subject"] = "Re: " + get_subject(message)
    draft_message = "To: " + args["to_email"] + "\r\n" + "From: <" + get_user_email(
        user
    ) + ">\r\n" + "Subject: " + args[
        "subject"] + "\r\n" + "Content-Type: text/html; charset=UTF-8\r\nContent-Transfer-Encoding: quoted-printable\r\n\r\n" + args[
            "body"] + "\r\n"
    print("=====")
    print(draft_message)
    print("=====")
    encodedMail = base64.b64encode(draft_message).replace("+", "-").replace(
        "//", "_")
    url = "https://www.googleapis.com/gmail/v1/users/me/messages/send"
    res = base_service.authorized_curl(
        "'{}' --data '{}' -H 'Content-Type: application/json'".format(
            url, json.dumps({"raw": encodedMail})), user)

    if "id" in res:
        return utils.send_message("{}!\n{}".format(
            "Replied" if reply else "Message sent",
            format_gmail_message(get_message(res["id"], user))))
    else:
        return utils.send_message("Email sending failed")
Example #4
0
def book_uber(user, fare_id, **args):
    s = {}
    if "start_place_id" in args:
        s["start_place_id"] = args["start_place_id"]
        if "end_place_id" in args:
            s["end_place_id"] = args["end_place_id"]
        else:
            s["end_latitude"] = args["end_latitude"]
            s["end_longitude"] = args["end_longitude"]
    else:
        if "end_place_id" in args:
            s = {
                "start_latitude": args['start_latitude'],
                "start_longitude": args["start_longitude"],
                "end_place_id": args["end_place_id"]
            }
        else:
            s = {
                "start_latitude": args['start_latitude'],
                "start_longitude": args["start_longitude"],
                "end_latitude": args["end_latitude"],
                "end_longitude": args["end_longitude"]
            }
    s["fare_id"] = fare_id
    res = base_service.authorized_curl(
        "-X POST -H 'Content-Type: application/json' 'https://sandbox-api.uber.com/v1.2/requests' -d '{}'"
        .format(json.dumps(s)), user)
    if "status" in res:
        return utils.send_message(
            "Uber booked!\nStatus:{}\nDriver:{}\nVehicle:{}".format(
                res['status'], res["driver"], res["vehicle"]))
    elif "errors" in res:
        return utils.send_message("Title:{}".format(res["errors"][0]["title"]))
Example #5
0
def get_place(user, place_id):
    res = base_service.authorized_curl(
        "-X GET -H 'Content-Type: application/json' 'https://sandbox-api.uber.com/v1.2/places/{}'"
        .format(place_id), user)
    latlong = utils.get_latlng(res["address"])
    res["lat"] = latlong["lat"]
    res["lng"] = latlong["lng"]
    return res
Example #6
0
def get_email_gmail(user, event):
    url = "https://www.googleapis.com/gmail/v1/users/me/messages?maxResults=1"
    q = get_search_query_from_event(event)
    if q:
        url = url + "&q=" + quote(q)
    res = base_service.authorized_curl("'{}'".format(url), user)
    print(res)
    if "messages" in res and len(res["messages"]) > 0:
        message_id = res["messages"][0]["id"]
        message = get_message(message_id, user)
        dynamodb.update_user(base_service.get_user_id(user), "last_mail_id",
                             message_id)
        return utils.send_message(format_gmail_message(message))
    else:
        return utils.send_message("No messages found")
Example #7
0
def search_item(user, q, q_type):
    # Valid types are: album, artist, playlist, and track.
    q = q.replace(" ", "%20")
    q_type = q_type.replace(" ", "+")
    url = "https://api.spotify.com/v1/search?q={}&type={}&limit=10".format(
        q, q_type)
    command = "-X GET '{}'".format(url)
    res = base_service.authorized_curl(command, user)
    return res


# curl -X PUT "https://api.spotify.com/v1/me/player/play" -H "Authorization: Bearer BQCF5bnU0EY0uTpkoC3HUl-66YJjZXu5ULt503BHEP-9WkMcro2xJcO4atyxl04hIdW4z_aLdHwslDX40oJSAsmX2h6e99Dvv4EOAl7Xj4dM_utbPJf9Adk0fuD0yas_vfPTjpjgfdmQYkE"

# https://accounts.spotify.com/authorize/?client_id=a7ed7ac582c4421397e4336a9339d849&response_type=code&redirect_uri=https%3A%2F%2Fmamam.com&scope=user-modify-playback-state

# \curl -d grant_type=authorization_code -d code=AQBpjD88SGOBw7k5G1C64tC-6qEZnwSSQl56t-9EPKZ58ZvaD4xdY9GO_xQbHBM5M0bEuKFqCkNlFtlTOf_NQFVi1K_YhAWuL_xKTRcmN3Oym62qFv-f-JTL2IRFkH6b0eFMuigb9X-toElrDV3gBLTAlX8UNkoo4voGNPxJAAOlp_nulVJh-gJkNWG4Qvjvp3tGxg6pA7_kd5UrLxB6G5_W2w -d redirect_uri=https%3A%2F%2Fmamam.com -H "Authorization: Basic YTdlZDdhYzU4MmM0NDIxMzk3ZTQzMzZhOTMzOWQ4NDk6NmRkNTQ4MGY2NzNkNGZlZThmN2QyMjU3MzdhOWViN2E=" "https://accounts.spotify.com/api/token"

# {"access_token":"BQCF5bnU0EY0uTpkoC3HUl-66YJjZXu5ULt503BHEP-9WkMcro2xJcO4atyxl04hIdW4z_aLdHwslDX40oJSAsmX2h6e99Dvv4EOAl7Xj4dM_utbPJf9Adk0fuD0yas_vfPTjpjgfdmQYkE","token_type":"Bearer","expires_in":3600,"refresh_token":"AQAWdn2eyEmmM8e1-QpSkrQjcrCoA7YS2srYsV_G5enD6CSazPm8kDRi8hYrbmrqQjG8cO_QvcxM0THV2leLEpcOKGFzdc37zjSLzbJ0MFS0IjGZZakk99yvrdfScTwE1hA","scope":"user-modify-playback-state"}
Example #8
0
def get_message(message_id, user):
    url = "https://www.googleapis.com/gmail/v1/users/me/messages/{0}?format=metadata".format(
        message_id)
    res = base_service.authorized_curl(url, user)
    return res
Example #9
0
def get_album_songs(album_id, user):
    command = "-X GET https://api.spotify.com/v1/albums/{}/tracks".format(
        album_id)
    res = base_service.authorized_curl(command, user)
    return res
Example #10
0
def play_context_intent(user, context_uri, message):
    data = {"context_uri": context_uri}
    command = "-X PUT 'https://api.spotify.com/v1/me/player/play' -H 'Content-Type: application/json' --data '{}'".format(
        json.dumps(data))
    res = base_service.authorized_curl(command, user)
    return utils.send_message(message)
Example #11
0
def stop_spotify_intent(user):
    command = "-X PUT 'https://api.spotify.com/v1/me/player/pause'"
    res = base_service.authorized_curl(command, user)
    return utils.send_message("Stopping spotify...")
Example #12
0
def shuffle_off_intent_spotify(user):
    command = "-X PUT 'https://api.spotify.com/v1/me/player/shuffle?state=false'"
    res = base_service.authorized_curl(command, user)
    return utils.send_message("Shuffle off..")
Example #13
0
def previous_intent_spotify(user):
    command = "-X POST 'https://api.spotify.com/v1/me/player/previous'"
    res = base_service.authorized_curl(command, user)
    return utils.send_message("Playing Previous Song..")
Example #14
0
def play_intent_spotify(user):
    command = "-X PUT 'https://api.spotify.com/v1/me/player/play'"
    res = base_service.authorized_curl(command, user)
    return utils.send_message("Resuming playback on spotify")
Example #15
0
def get_current(user):
    res = base_service.authorized_curl(
        "-X GET -H 'Content-Type: application/json' 'https://sandbox-api.uber.com/v1.2/requests/current'",
        user)
    return res
Example #16
0
def get_products(user, latitude, longitude):
    res = base_service.authorized_curl(
        "-X GET -H 'Content-Type: application/json' 'https://sandbox-api.uber.com/v1.2/products?latitude={}&longitude={}'"
        .format(latitude, longitude), user)
    return res