Exemplo n.º 1
0
 def check_price(self, symbol):
     """ Checks current ticker symbol price to see if price is outside 
         user-defined range
     """
     current_price = lookup(symbol)['price']
     db = create_connection('tickers.db')
     cursor = db.cursor()
     cursor.execute(
         """SELECT price, price_low, price_high FROM symbols 
                    WHERE ticker=?""", (symbol, ))
     price, price_low, price_high = cursor.fetchone()
     if current_price < price_low:
         # send user a notification that lower bound has been exceeded
         pct = abs(current_price - price) / price * 100
         message = symbol + ' is down ' + str(round(pct, 2)) + '% to $' + \
                     str(round(current_price, 2)) + ' from your watch ' + \
                     'price of $' + str(round(price, 2)) + '.'
         send_sms(message)
     elif current_price > price_high:
         # send user a notification that upper bound has been exceeded
         pct = abs(current_price - price) / price * 100
         message = symbol + ' is up ' + str(round(pct, 2)) + '% to $' + \
                     str(round(current_price, 2)) + ' from your watch ' + \
                     'price of $' + str(round(price, 2)) + '.'
         send_sms(message)
Exemplo n.º 2
0
def test_send_sms():
    email = get_random_email()
    create_user(email, 'pass')
    token = login_user(email, 'pass')
    verify_user(token)
    send_sms(token, '+123', 'text', 'god')
    last_message = query_last_message('+123')
    assert last_message['text'] == 'text'
    assert last_message['from'] == 'god'
Exemplo n.º 3
0
def send_text():
    try:
        email, name = request.json.get('email'), request.json.get('email')
        user = User.query.filter_by(email=email).all()[0]
    except IndexError:
        abort(404) # user doesn't exist
    body: str = request.json.get('body')
    phoneTo = request.json.get('number_to_send_to')
    helpers.send_sms(phoneTo, name + '\n' + body)
    return jsonify({})
Exemplo n.º 4
0
def test_balance_sms_send_balance_depleted():
    email = get_random_email()
    create_user(email, 'pass')
    token = login_user(email, 'pass')
    verify_user(token)
    for dummy in xrange(5):
        send_sms(token, '+123', 'text', 'god')

    with pytest.raises(requests.HTTPError):
        send_sms(token, '+123', 'text', 'god')
Exemplo n.º 5
0
def handler(event, context):
    # Run all the configured jobs and alerts
    helpers.run_jobs(JOBS)
    # Run a custom set of alerts with the provided helpers
    my_url = 'https://www.tickets.com/event/123123'  # This isn't a real check
    my_message = 'That ticket you wanted is now on sale! https://www.tickets.com/event/123123'
    if helpers.contains_text('On sale now', my_url):
        helpers.send_email('*****@*****.**',
                           'Your tickets are on sale!', my_message)
        helpers.send_sms('+1555777888#', my_message)
Exemplo n.º 6
0
def sms(request):
# TODO: secure this
    user_id = request.REQUEST['id'] if request.REQUEST.has_key('id') else 0
    msg = request.REQUEST['msg'] if request.REQUEST.has_key('msg') else ''
    
    users = User.objects.filter(id=int(user_id))
    if len(users) > 0:
        phone = users[0].get_profile().phone
        send_sms(phone, msg)
        return JsonResponse({'success' : True})
    
    return JsonResponse({'success' : False})
Exemplo n.º 7
0
def tell(medium, friend, msg):
    if medium not in VALID_MEDIUMS:
        return "Medium '%s' not recognized" % (medium,)

    config = CONFIG[friend]
    if medium == "cloakcast":
        # TODO: Add cloakcast support
        print "Clandestinely messaging %s via Cloakcast" % (friend,)
    elif medium == "email":
        return send_email(EMAIL_USERNAME, EMAIL_PASSWORD, [config[medium]], msg)
    elif medium == "gtalk":
        return send_im(EMAIL_USERNAME, EMAIL_PASSWORD, config[medium], msg)
    elif medium == "sms":
        return send_sms(config[medium], msg)
    elif medium == "twitter":
        tokens = twitter_tokens(creds["twitter_consumer_key"], creds["twitter_consumer_secret"])
        if len(tokens) != 2:
            return "Problem getting twitter tokens: %s" % tokens
        # twitter_oauth_token, twitter_oauth_token_secret = tokens
        twitter_oauth_token = creds["twitter_oauth_token"]
        twitter_oauth_token_secret = creds["twitter_oauth_token_secret"]
        return send_tweet(
            creds["twitter_consumer_key"],
            creds["twitter_consumer_secret"],
            "https://api.twitter.com/1.1/statuses/update.json",
            twitter_oauth_token,
            twitter_oauth_token_secret,
            http_method="POST",
            post_body=urllib.urlencode({"status": msg}),
        )
    return ""
Exemplo n.º 8
0
def tell(medium, friend, msg):
    if medium not in VALID_MEDIUMS:
        return "Medium '%s' not recognized" % (medium, )

    config = CONFIG[friend]
    if medium == "cloakcast":
        # TODO: Add cloakcast support
        print "Clandestinely messaging %s via Cloakcast" % (friend, )
    elif medium == "email":
        return send_email(EMAIL_USERNAME, EMAIL_PASSWORD, [config[medium]],
                          msg)
    elif medium == "gtalk":
        return send_im(EMAIL_USERNAME, EMAIL_PASSWORD, config[medium], msg)
    elif medium == "sms":
        return send_sms(config[medium], msg)
    elif medium == "twitter":
        tokens = twitter_tokens(creds["twitter_consumer_key"],
                                creds["twitter_consumer_secret"])
        if len(tokens) != 2:
            return "Problem getting twitter tokens: %s" % tokens
        # twitter_oauth_token, twitter_oauth_token_secret = tokens
        twitter_oauth_token = creds["twitter_oauth_token"]
        twitter_oauth_token_secret = creds["twitter_oauth_token_secret"]
        return send_tweet(creds["twitter_consumer_key"],
                          creds["twitter_consumer_secret"],
                          'https://api.twitter.com/1.1/statuses/update.json',
                          twitter_oauth_token,
                          twitter_oauth_token_secret,
                          http_method="POST",
                          post_body=urllib.urlencode({'status': msg}))
    return ""
Exemplo n.º 9
0
def tell(medium, friend, msg):
    if medium not in VALID_MEDIUMS:
        return "Medium '%s' not recognized" % (medium,)

    config = CONFIG[friend]
    if medium == "cloakcast":
        # TODO: Add cloakcast support
        print "Clandestinely messaging %s via Cloakcast" % (friend,)
    elif medium == "email":
        return send_email(EMAIL_USERNAME, EMAIL_PASSWORD, [config[medium]], msg)
    elif medium == "gtalk":
        return send_im(EMAIL_USERNAME, EMAIL_PASSWORD, config[medium], msg)
    elif medium == "sms":
        return send_sms(config[medium], msg)
    return ""
Exemplo n.º 10
0
def tell(medium, friend, msg):
    if medium not in VALID_MEDIUMS:
        return "Medium '%s' not recognized" % (medium, )

    config = CONFIG[friend]
    if medium == "cloakcast":
        # TODO: Add cloakcast support
        print "Clandestinely messaging %s via Cloakcast" % (friend, )
    elif medium == "email":
        return send_email(EMAIL_USERNAME, EMAIL_PASSWORD, [config[medium]],
                          msg)
    elif medium == "gtalk":
        return send_im(EMAIL_USERNAME, EMAIL_PASSWORD, config[medium], msg)
    elif medium == "sms":
        return send_sms(config[medium], msg)
    return ""
Exemplo n.º 11
0
def test_send_sms_without_verify_throws_exception():
    email = get_random_email()
    create_user(email, 'pass')
    token = login_user(email, 'pass')
    with pytest.raises(requests.HTTPError):
        send_sms(token, '+123', 'text', 'god')