Skip to content

Commit d4ebaae

Browse files
add: Prototype
1 parent 829624d commit d4ebaae

File tree

3 files changed

+207
-0
lines changed

3 files changed

+207
-0
lines changed

cli_master/cli_master.py

+136
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
import os
2+
import sys
3+
from pprint import pprint
4+
5+
import sys
6+
7+
sys.path.append(os.path.realpath("."))
8+
import inquirer # noqa
9+
10+
# Take authentication input from the user
11+
questions = [
12+
inquirer.List(
13+
"authentication", # This is the key
14+
message="Choose an option",
15+
choices=["Login", "Sign up", "Exit"],
16+
),
17+
]
18+
answers = inquirer.prompt(questions)
19+
20+
21+
# Just making pipelines
22+
class Validation:
23+
def phone_validation():
24+
# Think over how to make a validation for phone number?
25+
pass
26+
27+
def email_validation():
28+
pass
29+
30+
def password_validation():
31+
pass
32+
33+
def username_validation():
34+
pass
35+
36+
def country_validation():
37+
# All the countries in the world???
38+
# JSON can be used.
39+
# Download the file
40+
41+
def state_validation():
42+
# All the states in the world??
43+
# The state of the selected country only.
44+
pass
45+
46+
def city_validation():
47+
# All the cities in the world??
48+
# JSON can be used.
49+
pass
50+
51+
52+
# Have an option to go back.
53+
# How can I do it?
54+
if answers["authentication"] == "Login":
55+
print("Login")
56+
questions = [
57+
inquirer.Text(
58+
"username",
59+
message="What's your username?",
60+
validate=Validation.login_username,
61+
),
62+
inquirer.Text(
63+
"password",
64+
message="What's your password?",
65+
validate=Validation.login_password,
66+
),
67+
]
68+
69+
70+
elif answers["authentication"] == "Sign up":
71+
print("Sign up")
72+
73+
questions = [
74+
inquirer.Text(
75+
"name",
76+
message="What's your first name?",
77+
validate=Validation.fname_validation,
78+
),
79+
inquirer.Text(
80+
"surname",
81+
message="What's your last name(surname)?, validate=Validation.lname), {name}?",
82+
),
83+
inquirer.Text(
84+
"phone",
85+
message="What's your phone number",
86+
validate=Validation.phone_validation,
87+
),
88+
inquirer.Text(
89+
"email",
90+
message="What's your email",
91+
validate=Validation.email_validation,
92+
),
93+
inquirer.Text(
94+
"password",
95+
message="What's your password",
96+
validate=Validation.password_validation,
97+
),
98+
inquirer.Text(
99+
"password",
100+
message="Confirm your password",
101+
validate=Validation.password_confirmation,
102+
),
103+
inquirer.Text(
104+
"username",
105+
message="What's your username",
106+
validate=Validation.username_validation,
107+
),
108+
inquirer.Text(
109+
"country",
110+
message="What's your country",
111+
validate=Validation.country_validation,
112+
),
113+
inquirer.Text(
114+
"state",
115+
message="What's your state",
116+
validate=Validation.state_validation,
117+
),
118+
inquirer.Text(
119+
"city",
120+
message="What's your city",
121+
validate=Validation.city_validation,
122+
),
123+
inquirer.Text(
124+
"address",
125+
message="What's your address",
126+
validate=Validation.address_validation,
127+
),
128+
]
129+
# Also add optional in the above thing.
130+
# Have string manipulation for the above thing.
131+
# How to add authentication of google to command line?
132+
elif answers["authentication"] == "Exit":
133+
print("Exit")
134+
sys.exit()
135+
136+
pprint(answers)
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import requests
2+
3+
url = "https://api.countrystatecity.in/v1/countries"
4+
5+
headers = {"X-CSCAPI-KEY": "API_KEY"}
6+
7+
response = requests.request("GET", url, headers=headers)
8+
9+
print(response.text)

cli_master/validation_page.py

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import re
2+
3+
def phone_validation(phone_number):
4+
# Match a typical US phone number format (xxx) xxx-xxxx
5+
pattern = re.compile(r'^\(\d{3}\) \d{3}-\d{4}$')
6+
return bool(pattern.match(phone_number))
7+
8+
# Example usage:
9+
phone_number_input = input("Enter phone number: ")
10+
if phone_validation(phone_number_input):
11+
print("Phone number is valid.")
12+
else:
13+
print("Invalid phone number.")
14+
15+
def email_validation(email):
16+
# Basic email format validation
17+
pattern = re.compile(r'^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$')
18+
return bool(pattern.match(email))
19+
20+
# Example usage:
21+
email_input = input("Enter email address: ")
22+
if email_validation(email_input):
23+
print("Email address is valid.")
24+
else:
25+
print("Invalid email address.")
26+
27+
28+
def password_validation(password):
29+
# Password must be at least 8 characters long and contain at least one digit
30+
return len(password) >= 8 and any(char.isdigit() for char in password)
31+
32+
# Example usage:
33+
password_input = input("Enter password: ")
34+
if password_validation(password_input):
35+
print("Password is valid.")
36+
else:
37+
print("Invalid password.")
38+
39+
40+
def username_validation(username):
41+
# Allow only alphanumeric characters and underscores
42+
return bool(re.match('^[a-zA-Z0-9_]+$', username))
43+
44+
# Example usage:
45+
username_input = input("Enter username: ")
46+
if username_validation(username_input):
47+
print("Username is valid.")
48+
else:
49+
print("Invalid username.")
50+
51+
52+
def country_validation(country):
53+
# Example: Allow only alphabetical characters and spaces
54+
return bool(re.match('^[a-zA-Z ]+$', country))
55+
56+
# Example usage:
57+
country_input = input("Enter country name: ")
58+
if country_validation(country_input):
59+
print("Country name is valid.")
60+
else:
61+
print("Invalid country name.")
62+

0 commit comments

Comments
 (0)