Esempio n. 1
0
def check_validity(number):
    try:
        client = TwilioLookupsClient(account_sid, auth_token)
        response = client.phone_numbers.get(number)
        return True
    except TwilioRestException as e:
        return False
Esempio n. 2
0
def _twilio_lookup(phone_number):  # pragma: no cover
    client = TwilioLookupsClient(TWILIO_SID, TWILIO_AUTH_TOKEN)
    number = client.phone_numbers.get(phone_number, include_carrier_info=True)

    return {
        'phone_number': number.phone_number,
        'carrier_type': number.carrier.get('type', 'landline')
    }
Esempio n. 3
0
def valid_phone_number(num_str):
    client = TwilioLookupsClient(account=account_sid, token=auth_token)
    try:
        number = client.phone_numbers.get(num_str)
        number = number.phone_number
        return number
    except:
        return None
 def is_valid_number_twilio(self, number):
     client = TwilioLookupsClient(account_sid, auth_token)
     try:
         response = client.phone_numbers.get(number)
         response.phone_number  # If invalid, throws an exception.
         return True
     except TwilioRestException as e:
         if e.code == 20404:
             return False
         else:
             raise e
Esempio n. 5
0
def is_valid_number(number):
    """This is a helper function that will check to see that
    the given phone number is a valid phone number. This function
    utilizes Twilio's Lookup API Client."""
    client = TwilioLookupsClient(ACCOUNT_SID, AUTH_TOKEN)
    try:
        response = client.phone_numbers.get(number, include_carrier_info=True)
        response.phone_number  # If invalid, throws an exception.
        return True
    except TwilioRestException as error:
        if error.code == 20404:
            return False
        else:
            raise error
Esempio n. 6
0
    def _lookup_carrier(self, number):
        logging.info('Looking up number %s', number)

        try:
            client = TwilioLookupsClient(self.config['twilio_account_sid'],
                                         self.config['twilio_auth_token'])

            number_data = client.phone_numbers.get(number,
                                                   include_carrier_info=True)

            self._send_privmsg(
                self.config['channel'],
                '%s is %s, carrier: %s' % (number, number_data.carrier['type'],
                                           number_data.carrier['name']))
        except twilio.TwilioRestException as err:
            self._send_privmsg(self.config['channel'],
                               "Failed to lookup number: %s" % err)
Esempio n. 7
0
def send_sms():
    sid = os.environ.get('TWILIO_ACCOUNT_SID')
    auth = os.environ.get('TWILIO_AUTH_TOKEN')
    client = TwilioLookupsClient(account=sid, token=auth)
    send_client = TwilioRestClient(account=sid, token=auth)
    if request is not None:
        phone_num = request.json['number']
        resourceID = request.json['id']
        curr_res = Resource.query.get(resourceID)
        name = "Name: " + curr_res.name
        address = "Address: " + curr_res.address
        message = name + "\n" + address
        try:
            number = client.phone_numbers.get(phone_num,
                                              include_carrier_info=False)
            num = number.phone_number
            send_client.messages.create(to=num,
                                        from_="+17657692023",
                                        body=message)
            return jsonify(status='success')
        except:
            return jsonify(status='error')
Esempio n. 8
0
from twilio.rest.lookups import TwilioLookupsClient
from datetime import datetime
from tornado.wsgi import WSGIContainer
from tornado.httpserver import HTTPServer
from tornado.ioloop import IOLoop

app = Flask(__name__)

carrierPortalLookup = {
    "Verizon Wireless": "vtext.com",
    "Sprint Spectrum, L.P.": "messaging.sprintpcs.com",
    "AT&T Wireless": "txt.att.net",
}

# twilio
client = TwilioLookupsClient()
client = TwilioLookupsClient()

# database
#conn = pymysql.connect(host='127.0.0.1', user=config.DB_USER, passwd=config.DB_PASSWORD, db='alertme')
#cur = conn.cursor()


# subscribes a user by inserting their number into the database
@app.route("/api/subscribe/number/<number>/matchstr/<match>/site/<site>", methods=["POST"])
def subscribe(number, match, site):
    conn = pymysql.connect(host='127.0.0.1', user=config.DB_USER, passwd=config.DB_PASSWORD, db='alertme')
    cur = conn.cursor()
    try:
        if len(str(int(number))) > 15:
            cur.close()
from twilio.rest.lookups import TwilioLookupsClient
from urllib.parse import quote
import requests

# Your Account Sid and Auth Token from twilio.com/user/account
account_sid = input("Account SID?")
auth_token = input("Auth Token?")
addon = input("Addon? (leave blank for none)")

client = TwilioLookupsClient(account_sid, auth_token)

# Load the CSV file
CSVScanner = open("Input.csv", "r")

stack = []

for line in CSVScanner:
    if (line.startswith('+')):
        phoneNumber = line.rstrip()
    else:
        phoneNumber = str('+' + line).rstrip()
    #print(phoneNumber)
    try:
        if (addon):
            number = client.phone_numbers.get(
                quote(phoneNumber),
                include_carrier_info=True,
                addOns='whitepages_pro_caller_identity')
        else:
            number = requests.get(
                'https://lookups.twilio.com/v1/PhoneNumbers/' +
Esempio n. 10
0
import datetime
import csv
import os
import gc
from twilio.rest import TwilioRestClient
from twilio.rest.lookups import TwilioLookupsClient

ACCT = "" # Put your accountsid here
AUTH = "" # Put your authToken here

# Date Range input, we need to know what date range we are making this report for.
From_Date_Input = "2016-02-01" # Example 1st Feb
To_Date_Input = "2016-03-01" # Example 1st March - this will give us the month of Feb data

client = TwilioRestClient(ACCT, AUTH)
lookupclient = TwilioLookupsClient(ACCT, AUTH)

CalledStatistics = {}

with open("TwilioCallLog.csv", "w") as csvfile:
    csvfile.write("CallSID, CountryCode, NumberCalled, CallPrice, CallDuration\n")
    # If the to / From is blank or is a client we can skip the writing to
    # the file as we only want phone numbers.
                                      
    for call in client.calls.iter(page_size=1000, started_after=From_Date_Input, started_before=To_Date_Input):
        if call.direction == "outbound-dial":
            if call.to.startswith("+"):
                # if the row starts with a + it means its an E.164 number and that we need to use lookup to workout the country code, the end row will look like:
                # US,+1987654321,price
                try:
                    number = lookupclient.phone_numbers.get(call.to)
Esempio n. 11
0
import json
import yaml
from twilio.rest.exceptions import TwilioRestException
from twilio.rest.lookups import TwilioLookupsClient
from two1.wallet import Two1Wallet

# Load .env file for local use
dotenv_file = ".env"
if os.path.isfile(dotenv_file):
    dotenv.load_dotenv(dotenv_file)

client = TwilioRestClient(account=os.environ.get('TWILIO_ACCOUNT'),
                          token=os.environ.get('TWILIO_AUTH_TOKEN'))

validationclient = TwilioLookupsClient(
    account=os.environ.get('TWILIO_ACCOUNT'),
    token=os.environ.get('TWILIO_AUTH_TOKEN'))

app = Flask(__name__)

TWO1_WALLET_MNEMONIC = os.environ.get("TWO1_WALLET_MNEMONIC")
TWO1_USERNAME = os.environ.get("TWO1_USERNAME")
wallet = Two1Wallet.import_from_mnemonic(mnemonic=TWO1_WALLET_MNEMONIC)

payment = Payment(app, wallet, username=TWO1_USERNAME)


@app.route('/buy', methods=["POST"])
def start():
    to = ""
    post_data = request.get_json()
Esempio n. 12
0
from twilio.rest.exceptions import TwilioRestException

class Validator:
    def get_phone_no(self, row):
        phone_no = row['phone_no']
        return phone_no


val = Validator()
read()

# Your Account Sid and Auth Token from twilio.com/user/account
# Store them in the environment variables:
# "TWILIO_ACCOUNT_SID" and "TWILIO_AUTH_TOKEN"
# client = TwilioLookupsClient()
client = TwilioLookupsClient(account='Your Account ID',
                             token='Your secret token')


def is_valid_number(number):
    try:
        response = client.phone_numbers.get(number, include_carrier_info=True)
        response.phone_number  # If invalid, throws an exception.
        with open('valid_phone_no.csv', 'a') as fv:
            w = csv.DictWriter(fv, row.keys())
            w.writerow(row)
        return True
    except TwilioRestException as e:
        if e.code == 20404:
            return False
        else:
            raise e