-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresearch.py
367 lines (353 loc) · 12.2 KB
/
research.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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
import urllib3
from bs4 import BeautifulSoup
import re
import ddg
import topics
import countries
import foreign_ministries
#todo: https://support.discord.com/hc/en-us/articles/206342858--How-do-I-disable-auto-embed-
def give_committee_info(str):
ans = ''
if 'ga1' in str.lower():
ans += 'General Assembly First Committee (DISEC) considers all disarmament and international security matters: '
ans += '\nhttps://www.un.org/en/ga/first/'
if 'ga2' in str.lower():
ans += 'General Assembly Second Committee considers all global financial and sustainable development questions, and some other issues: '
ans += '\nhttps://www.un.org/en/ga/second/'
if 'ga3' in str.lower():
ans += 'GA3 (SOCHUM) considers social and humanitarian affairs: '
ans += '\nhttps://www.un.org/en/ga/third/index.shtml'
if 'ga4' in str.lower():
ans += 'GA4 deals with special decolonization, polticial issues, and outer space, and some other issues: '
ans += '\nhttps://www.un.org/en/ga/fourth/index.shtml'
if 'ga5' in str.lower():
ans += 'GA5 deals with the administration and budget of other UN bodies: '
ans += '\nhttps://www.un.org/en/ga/fifth/index.shtml'
if 'ga6' in str.lower():
ans += 'GA6 deals with legal questions: '
ans += '\nhttps://www.un.org/en/ga/sixth/index.shtml'
if 'security council' in str.lower() or 'unsc' in str.lower():
ans += 'The Security Council has primary responsibility for global peace and security. They may place sanctions and deploy peacekeepers: '
ans += '\nhttps://www.un.org/securitycouncil/'
ans += '\nSC containth altered rules and reg\'tions. Feast your eyes upon this resource: '
ans += '\nhttps://bestdelegate.com/five-tips-on-how-to-succeed-in-the-security-council/'
if 'iaea' in str.lower() or 'international atomi' in str.lower():
ans += 'The IAEA promotes the safe use of atomic energy and nuclear non-proliferation: '
ans += '\nhttps://www.iaea.org/about/overview/history'
return ans
def find_country(str):
countries = ['Afghanistan',
'Albania',
'Algeria',
'Andorra',
'Angola',
'Antigua and Barbuda',
'Argentina',
'Armenia',
'Australia',
'Austria',
'Azerbaijan',
'Bahamas',
'Bahrain',
'Bangladesh',
'Barbados',
'Belarus',
'Belgium',
'Belize',
'Benin',
'Bhutan',
'Bolivia',
'Bosnia and Herzegovina',
'Botswana',
'Brazil',
'Brunei',
'Bulgaria',
'Burkina Faso',
'Burundi',
'Cabo Verde',
'Cambodia',
'Cameroon',
'Canada',
'Central African Republic',
'Chad',
'Chile',
'China',
'Colombia',
'Comoros',
'Congo',
'Costa Rica',
'Cote d\'Ivoire',
'Croatia',
'Cuba',
'Cyprus',
'Czech Republic',
'Democratic People\'s Republic of Korea',
'Democratic Republic of the Congo',
'Denmark',
'DPRK',
'Korea',
'North Korea',
'South Korea',
'Djibouti',
'Dominica',
'Dominican Republic',
'Ecuador',
'Egypt',
'El Salvador',
'Equatorial Guinea',
'Eritrea',
'Estonia',
'Eswatini',
'Ethiopia',
'Fiji',
'Finland',
'France',
'Gabon',
'Gambia',
'Georgia',
'Germany',
'Ghana',
'Greece',
'Grenada',
'Guatemala',
'Guinea',
'Guinea-Bissau',
'Guyana',
'Haiti',
'Honduras',
'Hungary',
'Iceland',
'India',
'Indonesia',
'Iran (Islamic Republic of)',
'Iraq',
'Ireland',
'Israel',
'Italy',
'Jamaica',
'Japan',
'Jordan',
'Kazakhstan',
'Kenya',
'Kiribati',
'Kuwait',
'Kyrgyzstan',
'Lao People\'s Democratic Republic',
'Latvia',
'Lebanon',
'Lesotho',
'Liberia',
'Libya',
'Liechtenstein',
'Lithuania',
'Luxembourg',
'Madagascar',
'Malawi',
'Malaysia',
'Maldives',
'Mali',
'Malta',
'Marshall Islands',
'Mauritania',
'Mauritius',
'Mexico',
'Federated States of Micronesia',
'Monaco',
'Mongolia',
'Montenegro',
'Morocco',
'Mozambique',
'Myanmar',
'Namibia',
'Nauru',
'Nepal',
'Netherlands',
'New Zealand',
'Nicaragua',
'Niger',
'Nigeria',
'North Macedonia',
'Norway',
'Oman',
'Pakistan',
'Palau',
'Panama',
'Papua New Guinea',
'Paraguay',
'Peru',
'Philippines',
'Poland',
'Portugal',
'Qatar',
'Republic of Korea',
'Republic of Moldova',
'Romania',
'Russian Federation',
'Rwanda',
'Samoa',
'San Marino',
'Sao Tome and Príncipe',
'Saudi Arabia',
'Senegal',
'Serbia',
'Seychelles',
'Sierra Leone',
'Singapore',
'Slovakia',
'Slovenia',
'Solomon Islands',
'Somalia',
'South Africa',
'South Sudan',
'Spain',
'Sri Lanka',
'St. Kitts and Nevis',
'St. Lucia',
'St. Vincent and the Grenadines',
'Sudan',
'Suriname',
'Sweden',
'Switzerland',
'Syria',
'Tajikistan',
'Tanzania',
'Thailand',
'Timor-Leste',
'Togo',
'Tonga',
'Trinidad and Tobago',
'Tunisia',
'Turkey',
'Turkmenistan',
'Tuvalu',
'Uganda',
'Ukraine',
'United Arab Emirates',
'United Kingdom',
'United States of America',
'Uruguay',
'Uzbekistan',
'Vanuatu',
'Venezuela',
'Vietnam',
'Yemen',
'Zambia',
'Zimbabwe']
for country in countries:
if country.lower() in str.lower():
return country
def foreign_wiki(nation):
url = 'https://en.wikipedia.org/w/api.php?action=opensearch&profile=fuzzy&format=xml&search=foreign+relations+' + nation.lower()
xml = urllib3.PoolManager()
try:
data = xml.request('GET', url).data
soup = BeautifulSoup(data, 'xml')
return soup.find('Url').get_text() + '\n'
except:
return ''
def country_wiki(nation):
url = 'https://en.wikipedia.org/w/api.php?action=opensearch&format=xml&search=' + nation.lower()
xml = urllib3.PoolManager()
try:
data = xml.request('GET', url).data
soup = BeautifulSoup(data, 'xml')
return soup.find('Url').get_text() + '\n'
except:
return ''
def un_news_stories(nation): #das macht nicht
url = 'https://news.un.org/en/search/' + nation.lower()
http = urllib3.PoolManager()
answer = ''
try:
data = http.request('GET', url).data
soup = BeautifulSoup(data, features='lxml')
for link in soup.find_all('a'):
if 'story' in str(link.get('href')):
answer += 'https://news.un.org' + link.get('href') + ' (' + link.get_text().strip() + ')\n'
except:
return answer
return answer
def sanitize_nation(nation):
return ('+'.join(nation.split())).lower()
def research(question):
answer = 'Let us embark on some research together:\n\n'
answer += give_committee_info(question) + '\n'
question = componetize(question)
print(question)
for country in question['countries']:
answer += get_country_links(country)
if question['countries'] is not []:
answer += 'ultimate background guide: \n'
answer += 'https://docs.google.com/document/d/1_33AteI8TpO2aypneuyNo0VWxopc801GAOI7Tspy5TE/edit?usp=sharing\n\n'
answer += get_topic_links(question['topics'])
return answer
def get_country_links(nation):
answer = 'about ' + nation + ':\n'
answer += foreign_wiki(nation)
answer += country_wiki(nation)
answer += foreign_ministry(nation)
answer += '\n' + nation + ' news:\n'
answer += un_news_stories(nation)
return answer + '\n'
def foreign_ministry(nation):
ministries = foreign_ministries.ministries
for country in ministries:
p = re.compile('(?<!\w)'+country[1].lower()+'(?!\w)', re.IGNORECASE)
if re.search(p, nation) is not None:
return country[0] + '\n'
return ''
def get_topic_links(topic_list):
answer = ''
for topic in topic_list:
answer += '\nnews about '+ topic.lower() + ':\n'
answer += un_news_stories(topic)
return answer
def componetize(question):
components = {
'countries': [],
'topics': [],
'committees': []
}
question = ddg.sanitize_phrases(question)
components['countries'] = find_all_countries(question)
components['topics'] = find_all_topics(question)
return components
def find_all_countries(str):
found_countries = []
all_countries = countries.countries
for country in all_countries:
p = re.compile('(?<!\w)'+country.lower()+'(?!\w)', re.IGNORECASE)
if re.search(p, str) is not None:
if country == 'US' or country == 'USA':
found_countries.append('United States of America')
elif country == 'UK':
found_countries.append('United Kingdom')
else:
found_countries.append(country)
return found_countries
def find_all_topics(str):
all_topics = topics.topics
found_topics =[]
for topic in all_topics:
p = re.compile('(?<!\w)'+topic+'(?!\w)', re.IGNORECASE)
if re.search(p, str) is not None:
found_topics.append(topic)
return sorted(found_topics, reverse=True, key=len)
def research_worse(str):
print('looking for research request...', end = ' ')
answer = give_committee_info(str)
if 'research' not in str.lower():
print('not found!')
return answer
print('found!', end = ' ')
str = ddg.sanitize_phrases(str)
country = find_country(str)
if country is not None:
answer = 'Thou shalst use the following links to guide thou:\n\n' + answer + '\n'
country = sanitize_nation(country)
print('\ncountry:', country)
answer += 'https://docs.google.com/document/d/1_33AteI8TpO2aypneuyNo0VWxopc801GAOI7Tspy5TE/edit?usp=sharing\n'
answer += foreign_wiki(country) + '\n' + country_wiki(country)
else:
print('no country found!')
return answer