-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmodifyingMessages.py
199 lines (163 loc) · 6.2 KB
/
modifyingMessages.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
from binary_search import binary_search
from testingDataset import testing_data_country_wise
import casesDataSet
import HospitalLocation
import pycountry
import news
import state_list
import indianData
# when info is not found
alternate_text = "Didn't get your text, please try again later"
def textDecider(text):
textReturn = getCases(text)
if textReturn:
return textReturn
textReturn = getCities(text)
if textReturn:
return textReturn
textReturn = getStates(text)
if textReturn:
print(len(textReturn))
return textReturn
textReturn = getHospitals(text)
if textReturn:
return textReturn
textReturn = getNews(text)
if textReturn:
return textReturn
return alternate_text
def getCases(country):
# return selected item to the user
object_country = pycountry.countries.get(name=country)
if object_country:
try:
numberOfCases, deaths, recovered, newConfirmed, newRecovered, newDeaths \
= casesDataSet.numberOfCasesInCountry(country)
except ValueError:
return "Too many values"
else:
return False
testing_list = testing_data_country_wise(object_country.alpha_3, country)
random_message = 'Stats for {} are\nCases: {}\nDeaths: {}\nRecovered: {}' \
'\nNew Confirmed: {}\nNew Recovered: {}\nNew Deaths: {}\n'.format(country, numberOfCases, deaths
, recovered, newConfirmed,
newRecovered, newDeaths)
print(str(testing_list) + " this is printed")
for testing_stat in testing_list:
message = f"{testing_stat[0]} are\nCumulative tests: {testing_stat[1]}\n" \
f"Daily Count of test: {testing_stat[2]}\n"
random_message += message
return random_message
def getHospitals(locality):
if 'news' in locality:
return False
listOfHospitals = HospitalLocation.hospitalLocationsOnCoordinates(locality)
if listOfHospitals:
stringOfHospitals = ''
for hospitals in listOfHospitals:
stringOfHospitals += str(hospitals) + '\n'
return stringOfHospitals
else:
return False
def getNews(text):
if 'news' not in text:
return False
listOfText = text.split()
listOfArticles = []
newsTexts = ''
for word in listOfText:
if pycountry.countries.get(name=word):
listOfArticles = news.return_news(word)
break
if listOfArticles:
return listOfArticles
else:
return False
def getCities(text):
if 'hospitals' not in text:
return False
listOfText = text.split()
list_of_tuples = []
for word in listOfText:
index = binary_search(state_list.city_list, word, 0)
if index is not '':
tuple_of_city = state_list.city_list[index]
list_of_tuples.append(tuple_of_city)
if not list_of_tuples:
return False
list_of_hospitals = []
for city in list_of_tuples:
hospitalData = indianData.beds_city_wise(city)
message = hospitalDataOutput(city[0], hospitalData)
list_of_hospitals.append(message)
return list_of_hospitals
def getStates(text):
kashmir = ''
if 'Jammu & Kashmir' in text:
print('entered jmammu')
kashmir = 'Jammu and Kashmir'
text.replace('Jammu & Kashmir', '')
print(text)
elif 'Jammu and Kashmir' in text:
kashmir = 'Jammu and Kashmir'
text.replace('Jammu and Kashmir', '')
listOfText = text.split()
listOfText.append(kashmir)
if not len(listOfText) < 2:
listOfText = findingTwoWordedStates(listOfText)
stateInText = intersection(listOfText, state_list.state_list)
if not stateInText:
return False
if len(stateInText) > 1:
returningItem = []
for state in stateInText:
stateData = indianData.state_wise_numbers(state)
# stateHospitals = indianData.beds_state_wise(state)
random_message = initialDataOutput(state, stateData)
returningItem.append(random_message)
return returningItem
else:
stateData = indianData.state_wise_numbers(stateInText[0])
# stateHospitals = indianData.beds_state_wise(stateInText[0])
# if not stateHospitals:
# return False
return initialDataOutput(stateInText[0], stateData)
def intersection(lst1, lst2):
return list(set(lst1) & set(lst2))
def changeJson(number):
return "{:,}".format(number)
def messageGeneration(stateName, stateData, stateHospitals):
random_message = initialDataOutput(stateName, stateData)
random_message += hospitalDataOutput(stateName, stateHospitals)
return random_message
def initialDataOutput(stateName, stateData):
random_message = 'Stats for {} are\n' \
'Cases: ' \
'{}\nDeaths: {}' \
'\nDischarged: {}\n\n' \
.format(stateName, changeJson(stateData['totalConfirmed']), changeJson(stateData['deaths']),
changeJson(stateData['discharged']))
return random_message
def hospitalDataOutput(stateName, stateHospitals):
random_message = ''
for hospital in stateHospitals:
random_message += 'Hospitals in ' + stateName + ' are \n' \
'Name: {}' \
'\nCity: {}' \
'\nAdmission Capacity: {}' \
'\nHospital beds: {}' \
'\nOwner: {}\n\n'.format(hospital['name'], hospital['city'],
hospital['admissionCapacity'], hospital['hospitalBeds'],
hospital['ownership'])
return random_message
def findingTwoWordedStates(list_of_words):
i = 1
while i < len(list_of_words):
possible_state = list_of_words[i - 1] + ' ' + list_of_words[i]
if possible_state in state_list.state_list:
list_of_words[i] = possible_state
list_of_words.pop(i-1)
i = i + 1
return list_of_words
x = getCases('India')
print(x)