-
Notifications
You must be signed in to change notification settings - Fork 0
/
indicator.py
103 lines (86 loc) · 2.24 KB
/
indicator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import string
"""
Clear Punctuations
@:param String
@:return Clear string from punctuations
"""
def noPunctuations(txt):
return txt.translate(str.maketrans('','',string.punctuation))
"""
This Function to names the countries in the msg,
@:param text string
@:return the name in the msg
"""
def isName(txt):
name = ""
clearTxt = noPunctuations(txt)
txtList = clearTxt.split()
with open("countries") as f:
countryList = f.read().splitlines()
for word in txtList:
if word[0].isupper() and word not in countryList:
name += word + " "
return "Name: " + name
"""
This Function to check the countries in the msg
@:param
@:return
"""
def isCountry(txt):
countryFound = ""
noPunTxt = (noPunctuations(txt))
txtList = noPunTxt.split()
with open("countries") as f:
countryList = f.read().splitlines()
for country in countryList:
if country in txtList:
countryFound += country
return "Country: " + countryFound
"""
Returns the Gender if mentioned
@:param String
@:return the Gender from the msg
"""
def gender(txt):
genders = ""
clearTxt = noPunctuations(txt)
lowerTxt = clearTxt.lower()
if "male" in lowerTxt:
genders += "Male"
if "female" in lowerTxt:
genders += "Female"
return "Gender: " + genders
"""
Returns the Age number as a string from text msg
numbers up to 3 boxes only
else it won't return that
@:param String
@:return numbers in it as List
"""
def age(txt):
numbersList = [int(s) for s in txt.split() if s.isdigit()]
for ele in numbersList:
if ele < 333:
return "Age: " + str(ele)
return "No Age In the Msg"
"""
Returns the phone number as a string from text msg
else it won't return that
@:param String
@:return numbers in it as List
"""
def phone(txt):
numbersList = [int(s) for s in txt.split() if s.isdigit()]
for ele in numbersList:
if ele > 999:
return "Phone no.: " + str(ele)
return "No Phone Number"
# text msg
msg = "hello, my name is Mustafa Jamal, male and lives in @Egypt!!! 21 yrs phone no. 123456789"
# functions Testing
print(noPunctuations(msg))
print(isName(msg))
print(isCountry(msg))
print(gender(msg))
print(age(msg))
print(phone(msg))