def test_phone_country_dk():
    assert phone_country(45) == 'DK'
    assert phone_country(4566118311) == 'DK'
    assert phone_country('+4566118311') == 'DK'
    assert phone_country('+38640118311') == 'SI'
    assert phone_country('+38340118311') == 'XK'
    assert phone_country('+37740118311') == 'MC'
    assert phone_country('+77401183119') == 'KZ'
    assert phone_country('+79901185311') == 'RU'
    assert phone_country('+97040118311') == 'PS'
Exemple #2
0
    def try_resolve_location_by_name(cls, name: str, phonenumber: str):
        from phone_iso3166.country import phone_country
        country = Country.objects.filter(alpha2=phone_country(phonenumber)).first()
        location = Location.objects.in_country(country).filter(name__icontains=name).first()
        if location is not None:
            return location

        gmaps = googlemaps.Client(key=settings.GOOGLE_API_KEY)
        try:
            name += ", " + country.name
            geocode_result = gmaps.geocode(name)
            result = geocode_result[0]
            geometry = result["geometry"]
            location = geometry["location"]
            bounds = geometry["bounds"]
            address_components = result["address_components"]
            address = address_components[0]

            location_obj = Location()
            location_obj.name = address["long_name"]
            location_obj.country = country
            location_obj.latitude = location["lat"]
            location_obj.longitude = location["lng"]
            location_obj.bounds_northeast_longitude = bounds["northeast"]["lng"]
            location_obj.bounds_southwest_longitude = bounds["southwest"]["lng"]
            location_obj.bounds_northeast_latitude = bounds["northeast"]["lat"]
            location_obj.bounds_southwest_latitude = bounds["southwest"]["lat"]

            location_obj.googlemaps_place_id = result["place_id"]

            location_obj.save()
            return location_obj
        except Exception as e:
            logging.error(str(e))
            return None
Exemple #3
0
def get_country_name_and_flag(phone):
  try:
    country = phone_country(phone)
    return flag.flag(country) + country
  except:
    None
  return flag.flagize(":MX: MX")
Exemple #4
0
 def Track_location(self, event):
     phone_number = self.phone_number.get()
     country = "Country is Unknown"
     if phone_number:
         tracked = pycountry.countries.get(alpha_2=phone_country(phone_number))
         print(tracked)
         if tracked:
             country = tracked.official_name
     self.country_label.configure(text=country)
Exemple #5
0
def send_sms(to_number, text):
    cc = phone_country(to_number)

    src = {'US': '17077776191', 'CA': '13433441234'}.get(cc, '17077776191')

    p = plivo.RestAPI(current_app.config['PLIVO_AUTH_ID'],
                      current_app.config['PLIVO_AUTH_TOKEN'])
    params = {'src': src, 'dst': str(to_number), 'text': text}
    res = p.send_message(params)
    return '', 200
Exemple #6
0
def put_user(username):
    """
    PUT:
        Changes an attribute of the user.
    """
    if username != g.user.username:
        return authenticate()

    json = request.get_json(force=True, silent=True)
    if not json:
        return jsonify({
            'error': 'Request is not valid JSON'
        }), 400

    try:
        userSchema(json)
    except Exception as e:
        return jsonify({
            'error': 'Improper request. Check documentation and try again.'
        }), 400

    try:
        for i in list(json):
            if i == 'password':
                g.user.change_password(json[i])
            elif i == 'email':
                if json['email'] != g.user.email:
                    setattr(g.user, 'email', json['email'])
                    setattr(g.user, 'email_verified', False)
                    setattr(g.user, 'email_verified_on', None)
            elif i == 'sms_number':
                if json['sms_number'] != g.user.sms_number:
                    setattr(g.user, 'sms_number', json['sms_number'])
                    setattr(g.user, 'sms_verified', False)
                    setattr(g.user, 'sms_verified_on', None)
            else:
                setattr(g.user, i, json[i])
        db.session.commit()

        res = dict(
            username = g.user.username,
            email = g.user.email,
            sms_number = g.user.sms_number,
            sms_country_code = phone_country(g.user.sms_number),
            sms_verified = g.user.sms_verified,
            email_verified = g.user.email_verified,
            api_key = g.user.api_key
        )
        return jsonify({'profile': res}), 200

    except Exception as e:
        return jsonify({
            'error': 'unknown error'
        }), 400
Exemple #7
0
def test_phone_country_dk():
    assert phone_country(45) == 'DK'
    assert phone_country(4566118311) == 'DK'
    assert phone_country('+4566118311') == 'DK'
    assert phone_country('+38640118311') == 'SI'
    assert phone_country('+38340118311') == 'XK'
    assert phone_country('+37740118311') == 'MC'
Exemple #8
0
def put_user(username):
    """
    PUT:
        Changes an attribute of the user.
    """
    if username != g.user.username:
        return authenticate()

    json = request.get_json(force=True, silent=True)
    if not json:
        return jsonify({'error': 'Request is not valid JSON'}), 400

    try:
        userSchema(json)
    except Exception as e:
        return jsonify(
            {'error':
             'Improper request. Check documentation and try again.'}), 400

    try:
        for i in list(json):
            if i == 'password':
                g.user.change_password(json[i])
            elif i == 'email':
                if json['email'] != g.user.email:
                    setattr(g.user, 'email', json['email'])
                    setattr(g.user, 'email_verified', False)
                    setattr(g.user, 'email_verified_on', None)
            elif i == 'sms_number':
                if json['sms_number'] != g.user.sms_number:
                    setattr(g.user, 'sms_number', json['sms_number'])
                    setattr(g.user, 'sms_verified', False)
                    setattr(g.user, 'sms_verified_on', None)
            else:
                setattr(g.user, i, json[i])
        db.session.commit()

        res = dict(username=g.user.username,
                   email=g.user.email,
                   sms_number=g.user.sms_number,
                   sms_country_code=phone_country(g.user.sms_number),
                   sms_verified=g.user.sms_verified,
                   email_verified=g.user.email_verified,
                   api_key=g.user.api_key)
        return jsonify({'profile': res}), 200

    except Exception as e:
        return jsonify({'error': 'unknown error'}), 400
Exemple #9
0
def get_user(username):
    """
    GET:
        Fetches a user's profile.
    """
    if username != g.user.username:
        return authenticate()

    res = dict(username=g.user.username,
               email=g.user.email,
               sms_number=g.user.sms_number,
               sms_country_code=phone_country(g.user.sms_number),
               sms_verified=g.user.sms_verified,
               email_verified=g.user.email_verified,
               api_key=g.user.api_key)
    return jsonify({'profile': res}), 200
Exemple #10
0
def send_sms(to_number, text):
    cc = phone_country(to_number)

    src = {
        'US': '17077776191',
        'CA': '13433441234'
    }.get(cc, '17077776191')

    p = plivo.RestAPI(
            current_app.config['PLIVO_AUTH_ID'],
            current_app.config['PLIVO_AUTH_TOKEN'])
    params = {
        'src': src,
        'dst': str(to_number),
        'text': text
    }
    res = p.send_message(params)
    return '', 200
Exemple #11
0
def get_user(username):
    """
    GET:
        Fetches a user's profile.
    """
    if username != g.user.username:
        return authenticate()

    res = dict(
        username = g.user.username,
        email = g.user.email,
        sms_number = g.user.sms_number,
        sms_country_code = phone_country(g.user.sms_number),
        sms_verified = g.user.sms_verified,
        email_verified = g.user.email_verified,
        api_key = g.user.api_key
    )
    return jsonify({'profile': res}), 200
Exemple #12
0
def test_whitehouse():
    # White house comment line
    assert phone_country('+1 202-456-1111') == 'US'
Exemple #13
0
def test_missing():
    with pytest.raises(InvalidPhone):
        phone_country(999)
    with pytest.raises(InvalidPhone):
        phone_country('999')
Exemple #14
0
def test_invalid():
    with pytest.raises(InvalidPhone):
        phone_country(0)
def test_invalid():
    with pytest.raises(InvalidPhone):
        phone_country(0)
Exemple #16
0
def reserveSeatFunction():
    os.system("cls");
    print('\033[1;33;40m\nRESERVE SEAT MENU:');
    
    # INserting the user ID into the database;
    print('ID');    
    number_of_IDs = 0;
    userID = 0;
    cur.execute("SELECT (user_id) FROM passengers");
    for rows in cur:
        number_of_IDs += 1;
        
    if (number_of_IDs == 0):
        userID = 0;
        print('Your ID: 0');
    else:
        userID = number_of_IDs;
        print("Your ID: ", userID);
    userInformation.append(userID);

    # username confirmation;
    os.system("cls");
    sleep(1)
    print('-'*40);
    print('NAME');
    print('-'*40);
    while True:
        userFullName = str(input('Name: ')).strip().split();

        if (len(userFullName) > 2):
            first_name = userFullName[0].capitalize();
            second_name = userFullName[1].capitalize();
            last_name = userFullName[2].capitalize();
            userInformation.append(first_name);
            userInformation.append(second_name);
            userInformation.append(last_name);
            break;
        else:
            print('Please, you nedd inser a valid username! Try again.');
    
    # user birthdate confirmation;
    os.system("cls");
    sleep(1)
    print("\n", '-'*40);
    print('BIRTHDATE');
    print('-'*40);
    while True:
        # Asking user birthday (DD);
        userBirthday = str(input("DAY (DD): ")).strip();
        if len(userBirthday) == 2:
            if "01" <= userBirthday <= "31":

                while True:
                    # asking user birth month (MM);
                    userBirthmonth = str(input("Month (MM): ")).strip();

                    if len(userBirthmonth) == 2:
                        if "0" <= userBirthmonth <= "12":
                            
                            while True:
                                # Asking user birth year (YYYY);
                                userBirthyear = str(input("Year (YYYY): ")).strip();

                                if len(userBirthyear) == 4:
                                    if userBirthyear < str(actual_year):
                                        DATE = datetime(int(userBirthyear), int(userBirthmonth), int(userBirthday))
                                        # Formating to data before insert into mySQL database;
                                        userBirthDATE = DATE.date().isoformat();
                                        userAge = actual_year - int(userBirthyear);
                                        break;
                                    else:
                                        print("Please, the year inserted is invalid! Try again.")
                                else:
                                    print("Please, the year is invalid! Try again.")
                            break;
                        else:
                            print("Please, the month inserted is invalid! Try again.")
                    else:
                        print("Please, you need insert a month! Try again.")
                break;
            else:
                print("Please, the day inserted is invalid! Try again.")
        else:
            print("Please you need insert a day! Try again.")

    # user email address confirmation;
    os.system("cls");
    sleep(1)
    print("\n", '-'*40);
    print('EMAIL ADDRESS');
    print('-'*40);
    while True:
        userEmailAddress = str(input('Email address: ')).strip();

        if (len(userEmailAddress) != 0 and userEmailAddress.find('@') != -1 and userEmailAddress.find('.') != -1):
            userInformation.append(userEmailAddress);
            break;
        else:
            print("Please, you need insert a valid email address! Try again.")

     # user phone number confirmation;
    os.system("cls");
    sleep(1)
    print("\n", '-'*40);
    print('PHONE');
    print('-'*40);
    while True:
        userPhoneNo = str(input('Phone: '));

        if (len(userPhoneNo) != 0):
            userPhoneNo = "+" + userPhoneNo;

            # checking user country since phone number inseted;
            country = pycountry.countries.get(alpha_2=phone_country(userPhoneNo));
            userCountry = country.name;
            userOfficialCountryName = country.official_name;
            break;
        else:
            print('Please, you need insert a phone number valid! Try again.');

    # user country confirmation;
    '''os.system("cls");
    sleep(1)
    print("\n", '-'*40);
    print('COUNTRY');
    print('-'*40);
    while True:
        userCountry = str(input('Country: ')).upper().strip().capitalize();
        
        if (len(userCountry) != 0):
            userInformation.append(userCountry);
            break;
        else:
            print('Please, you need insert a country valid! Try again.');'''
        
    # user city confirmation;
    os.system("cls");
    sleep(1)
    print("\n", '-'*40);
    print('CITY')
    print('-'*40)
    while True:
        userCity = str(input('City: ')).upper().strip().capitalize();
        
        if (len(userCity) != 0):
            userInformation.append(userCity);
            break;
        else:
            print('Please, you need insert a valid city! Try again.');

    # user passport confirmation;
    os.system("cls");
    sleep(1)
    print("\n", '-'*40);
    print('PASSPORT');
    print('-'*40);
    while True:
        userPassport = str(input('Passport: '))

        if (len(userPassport) != 0):
            userInformation.append(userPassport);
            break;
        else:
            print('Please, you need insert a passport number valid! Try again.');

    # user ticket confirmation;
    os.system("cls");
    sleep(1);
    print("\n", '-'*40);
    print('TICKET');
    print('-'*40);
    while True:
        userTicket = str(input('Ticket: '))
        
        if (len(userTicket) != 0):
            userInformation.append(userTicket);
            break;
        else:
            print('Please, you need insert a ticket number valid! Try again.');

    os.system("cls");
    print("INSERTING USER TO DATABASE")
    print('-\033[m'*30)
    # Function inside the database package where the user will be inserted into the database;
    databaseconnection.insertUserToDatabase(userID, first_name, second_name, last_name, userAge, userBirthDATE, userEmailAddress, userOfficialCountryName, userCountry, userCity, userPhoneNo, userPassport, userTicket);
def test_missing():
    with pytest.raises(InvalidPhone):
        phone_country(999)
    with pytest.raises(InvalidPhone):
        phone_country('999')
Exemple #18
0
#0645632754
#import phone_iso3166
import pycountry
import tkinter
from phone_iso3166.country import phone_country
import phonenumbers
from phonenumbers import geocoder, carrier

number = "33645632754"
code = phone_country(number)
print("code=" + code)
C = pycountry.countries.get(alpha_2=code)
print("C={}".format(C))

print("getitng continent")
ch_number = phonenumbers.parse(number, "CH")  #country name
print("ch_number={}".format(ch_number))
print("geocoder={}".format(geocoder.description_for_number(ch_number, "en")))

print("getting operator")
service_number = phonenumbers.parse(number, "RO")
print("carrier={}".format(carrier.name_for_number(service_number, "en")))
Exemple #19
0
def test_bermuda():
    # Bermuda city hall
    assert phone_country(14412921234) == 'BM'
def test_whitehouse():
    # White house comment line
    assert phone_country('+1 202-456-1111') == 'US'
def test_bermuda():
    # Bermuda city hall
    assert phone_country(14412921234) == 'BM'
def test_phone_country_dk():
    assert phone_country(45) == 'DK'
    assert phone_country(4566118311) == 'DK'
    assert phone_country('+4566118311') == 'DK'
Exemple #23
0
def test_phone_country_dk():
    assert phone_country(45) == 'DK'
    assert phone_country(4566118311) == 'DK'
    assert phone_country('+4566118311') == 'DK'
Exemple #24
0
def get_country_code():
    code = phone_country(settings.PHONE_NUMBER)
    print(code)