-
Notifications
You must be signed in to change notification settings - Fork 12.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
829624d
commit d4ebaae
Showing
3 changed files
with
207 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
import os | ||
import sys | ||
from pprint import pprint | ||
|
||
import sys | ||
|
||
sys.path.append(os.path.realpath(".")) | ||
import inquirer # noqa | ||
|
||
# Take authentication input from the user | ||
questions = [ | ||
inquirer.List( | ||
"authentication", # This is the key | ||
message="Choose an option", | ||
choices=["Login", "Sign up", "Exit"], | ||
), | ||
] | ||
answers = inquirer.prompt(questions) | ||
|
||
|
||
# Just making pipelines | ||
class Validation: | ||
def phone_validation(): | ||
# Think over how to make a validation for phone number? | ||
pass | ||
|
||
def email_validation(): | ||
pass | ||
|
||
def password_validation(): | ||
pass | ||
|
||
def username_validation(): | ||
pass | ||
|
||
def country_validation(): | ||
# All the countries in the world??? | ||
# JSON can be used. | ||
# Download the file | ||
|
||
def state_validation(): | ||
# All the states in the world?? | ||
# The state of the selected country only. | ||
pass | ||
|
||
def city_validation(): | ||
# All the cities in the world?? | ||
# JSON can be used. | ||
pass | ||
|
||
|
||
# Have an option to go back. | ||
# How can I do it? | ||
if answers["authentication"] == "Login": | ||
print("Login") | ||
questions = [ | ||
inquirer.Text( | ||
"username", | ||
message="What's your username?", | ||
validate=Validation.login_username, | ||
), | ||
inquirer.Text( | ||
"password", | ||
message="What's your password?", | ||
validate=Validation.login_password, | ||
), | ||
] | ||
|
||
|
||
elif answers["authentication"] == "Sign up": | ||
print("Sign up") | ||
|
||
questions = [ | ||
inquirer.Text( | ||
"name", | ||
message="What's your first name?", | ||
validate=Validation.fname_validation, | ||
), | ||
inquirer.Text( | ||
"surname", | ||
message="What's your last name(surname)?, validate=Validation.lname), {name}?", | ||
), | ||
inquirer.Text( | ||
"phone", | ||
message="What's your phone number", | ||
validate=Validation.phone_validation, | ||
), | ||
inquirer.Text( | ||
"email", | ||
message="What's your email", | ||
validate=Validation.email_validation, | ||
), | ||
inquirer.Text( | ||
"password", | ||
message="What's your password", | ||
validate=Validation.password_validation, | ||
), | ||
inquirer.Text( | ||
"password", | ||
message="Confirm your password", | ||
validate=Validation.password_confirmation, | ||
), | ||
inquirer.Text( | ||
"username", | ||
message="What's your username", | ||
validate=Validation.username_validation, | ||
), | ||
inquirer.Text( | ||
"country", | ||
message="What's your country", | ||
validate=Validation.country_validation, | ||
), | ||
inquirer.Text( | ||
"state", | ||
message="What's your state", | ||
validate=Validation.state_validation, | ||
), | ||
inquirer.Text( | ||
"city", | ||
message="What's your city", | ||
validate=Validation.city_validation, | ||
), | ||
inquirer.Text( | ||
"address", | ||
message="What's your address", | ||
validate=Validation.address_validation, | ||
), | ||
] | ||
# Also add optional in the above thing. | ||
# Have string manipulation for the above thing. | ||
# How to add authentication of google to command line? | ||
elif answers["authentication"] == "Exit": | ||
print("Exit") | ||
sys.exit() | ||
|
||
pprint(answers) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import requests | ||
|
||
url = "https://api.countrystatecity.in/v1/countries" | ||
|
||
headers = {"X-CSCAPI-KEY": "API_KEY"} | ||
|
||
response = requests.request("GET", url, headers=headers) | ||
|
||
print(response.text) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import re | ||
|
||
def phone_validation(phone_number): | ||
# Match a typical US phone number format (xxx) xxx-xxxx | ||
pattern = re.compile(r'^\(\d{3}\) \d{3}-\d{4}$') | ||
return bool(pattern.match(phone_number)) | ||
|
||
# Example usage: | ||
phone_number_input = input("Enter phone number: ") | ||
if phone_validation(phone_number_input): | ||
print("Phone number is valid.") | ||
else: | ||
print("Invalid phone number.") | ||
|
||
def email_validation(email): | ||
# Basic email format validation | ||
pattern = re.compile(r'^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$') | ||
return bool(pattern.match(email)) | ||
|
||
# Example usage: | ||
email_input = input("Enter email address: ") | ||
if email_validation(email_input): | ||
print("Email address is valid.") | ||
else: | ||
print("Invalid email address.") | ||
|
||
|
||
def password_validation(password): | ||
# Password must be at least 8 characters long and contain at least one digit | ||
return len(password) >= 8 and any(char.isdigit() for char in password) | ||
|
||
# Example usage: | ||
password_input = input("Enter password: ") | ||
if password_validation(password_input): | ||
print("Password is valid.") | ||
else: | ||
print("Invalid password.") | ||
|
||
|
||
def username_validation(username): | ||
# Allow only alphanumeric characters and underscores | ||
return bool(re.match('^[a-zA-Z0-9_]+$', username)) | ||
|
||
# Example usage: | ||
username_input = input("Enter username: ") | ||
if username_validation(username_input): | ||
print("Username is valid.") | ||
else: | ||
print("Invalid username.") | ||
|
||
|
||
def country_validation(country): | ||
# Example: Allow only alphabetical characters and spaces | ||
return bool(re.match('^[a-zA-Z ]+$', country)) | ||
|
||
# Example usage: | ||
country_input = input("Enter country name: ") | ||
if country_validation(country_input): | ||
print("Country name is valid.") | ||
else: | ||
print("Invalid country name.") | ||
|