Skip to content

Commit a2b2861

Browse files
committed
ranks, geos, techonologies endpoints added
1 parent 30dbad8 commit a2b2861

File tree

15 files changed

+3839
-0
lines changed

15 files changed

+3839
-0
lines changed

functions/geos/libs/__init__.py

Whitespace-only changes.

functions/geos/libs/result.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
class Result():
3+
def __init__(self, status=None, result=None, errors=[]):
4+
self._status = status
5+
self.result = result
6+
self.errors = errors
7+
8+
def success(self) -> bool:
9+
return not self.failure()
10+
11+
def failure(self) -> bool:
12+
return len(self.errors) > 0
13+
14+
@property
15+
def status(self):
16+
if self._status != None:
17+
return self._status
18+
19+
return "ok" if self.success else "error"
20+

functions/geos/libs/utils.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import json
2+
3+
COUNTRIES = ["ALL", "Afghanistan", "Albania", "Algeria", "American Samoa", "Andorra", "Angola", "Anguilla", "Antigua and Barbuda", "Argentina", "Armenia", "Aruba", "Australia", "Austria", "Azerbaijan", "Bahamas", "Bahrain", "Bangladesh", "Barbados", "Belarus", "Belgium", "Belize", "Benin", "Bermuda", "Bhutan", "Bolivia (Plurinational State of)", "Bonaire, Sint Eustatius and Saba", "Bosnia and Herzegovina", "Botswana", "Brazil", "British Indian Ocean Territory", "Brunei Darussalam", "Bulgaria", "Burkina Faso", "Burundi", "Cabo Verde", "Cambodia", "Cameroon", "Canada", "Cayman Islands", "Central African Republic", "Chad", "Chile", "China", "Christmas Island", "Colombia", "Comoros", "Congo", "Congo, Democratic Republic of the", "Cook Islands", "Costa Rica", "Croatia", "Cuba", "Curaçao", "Cyprus", "Czechia", "Côte d\u0027Ivoire", "Denmark", "Djibouti", "Dominica", "Dominican Republic", "Ecuador", "Egypt", "El Salvador", "Equatorial Guinea", "Eritrea", "Estonia", "Eswatini", "Ethiopia", "Falkland Islands (Malvinas)", "Faroe Islands", "Fiji", "Finland", "France", "French Guiana", "French Polynesia", "Gabon", "Gambia", "Georgia", "Germany", "Ghana", "Gibraltar", "Greece", "Greenland", "Grenada", "Guadeloupe", "Guam", "Guatemala", "Guernsey", "Guinea", "Guinea-Bissau", "Guyana", "Haiti", "Honduras", "Hong Kong", "Hungary", "Iceland", "India", "Indonesia", "Iran (Islamic Republic of)", "Iraq", "Ireland", "Isle of Man", "Israel", "Italy", "Jamaica", "Japan", "Jersey", "Jordan", "Kazakhstan", "Kenya", "Kiribati", "Korea (Democratic People\u0027s Republic of)", "Korea, Republic of", "Kosovo", "Kuwait", "Kyrgyzstan", "Lao People\u0027s Democratic Republic", "Latvia", "Lebanon", "Lesotho", "Liberia", "Libya", "Liechtenstein", "Lithuania", "Luxembourg", "Macao", "Madagascar", "Malawi", "Malaysia", "Maldives", "Mali", "Malta", "Marshall Islands", "Martinique", "Mauritania", "Mauritius", "Mayotte", "Mexico", "Micronesia (Federated States of)", "Moldova, Republic of", "Monaco", "Mongolia", "Montenegro", "Montserrat", "Morocco", "Mozambique", "Myanmar", "Namibia", "Nauru", "Nepal", "Netherlands", "New Caledonia", "New Zealand", "Nicaragua", "Niger", "Nigeria", "Norfolk Island", "North Macedonia", "Northern Mariana Islands", "Norway", "Oman", "Pakistan", "Palau", "Palestine, State of", "Panama", "Papua New Guinea", "Paraguay", "Peru", "Philippines", "Poland", "Portugal", "Puerto Rico", "Qatar", "Romania", "Russian Federation", "Rwanda", "Réunion", "Saint Barthélemy", "Saint Helena, Ascension and Tristan da Cunha", "Saint Kitts and Nevis", "Saint Lucia", "Saint Martin (French part)", "Saint Pierre and Miquelon", "Saint Vincent and the Grenadines", "Samoa", "San Marino", "Sao Tome and Principe", "Saudi Arabia", "Senegal", "Serbia", "Seychelles", "Sierra Leone", "Singapore", "Sint Maarten (Dutch part)", "Slovakia", "Slovenia", "Solomon Islands", "Somalia", "South Africa", "South Sudan", "Spain", "Sri Lanka", "Sudan", "Suriname", "Svalbard and Jan Mayen", "Sweden", "Switzerland", "Syrian Arab Republic", "Taiwan, Province of China", "Tajikistan", "Tanzania, United Republic of", "Thailand", "Timor-Leste", "Togo", "Tonga", "Trinidad and Tobago", "Tunisia", "Turkey", "Turkmenistan", "Turks and Caicos Islands", "Tuvalu", "Uganda", "Ukraine", "United Arab Emirates", "United Kingdom of Great Britain and Northern Ireland", "United States of America", "Uruguay", "Uzbekistan", "Vanuatu", "Venezuela (Bolivarian Republic of)", "Viet Nam", "Virgin Islands (British)", "Virgin Islands (U.S.)", "Western Sahara", "Yemen", "Zambia", "Zimbabwe", "Åland Islands"]
4+
5+
def output(result):
6+
status = 200 if result.success() else 400
7+
payload = result.result if result.success() else convert_to_hashes(result.errors)
8+
return (json.dumps(payload), status)
9+
10+
def convert_to_hashes(arr):
11+
hashes_arr = []
12+
for inner_arr in arr:
13+
hash_dict = {inner_arr[0]: inner_arr[1]}
14+
hashes_arr.append(hash_dict)
15+
return hashes_arr

functions/geos/main.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import functions_framework
2+
3+
from .libs.utils import output
4+
from .libs.utils import ( COUNTRIES )
5+
from .libs.result import Result
6+
7+
@functions_framework.http
8+
def dispatcher(request):
9+
10+
response = Result(result=COUNTRIES)
11+
12+
return output(response)

functions/geos/requirements.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
functions-framework
2+
google-cloud-firestore
3+
pytest

functions/ranks/libs/__init__.py

Whitespace-only changes.

functions/ranks/libs/result.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
class Result():
3+
def __init__(self, status=None, result=None, errors=[]):
4+
self._status = status
5+
self.result = result
6+
self.errors = errors
7+
8+
def success(self) -> bool:
9+
return not self.failure()
10+
11+
def failure(self) -> bool:
12+
return len(self.errors) > 0
13+
14+
@property
15+
def status(self):
16+
if self._status != None:
17+
return self._status
18+
19+
return "ok" if self.success else "error"
20+

functions/ranks/libs/utils.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import json
2+
3+
RANKS = ["ALL", "Top 100k", "Top 10M", "Top 10k", "Top 1M", "Top 1k"]
4+
5+
def output(result):
6+
status = 200 if result.success() else 400
7+
payload = result.result if result.success() else convert_to_hashes(result.errors)
8+
return (json.dumps(payload), status)
9+
10+
def convert_to_hashes(arr):
11+
hashes_arr = []
12+
for inner_arr in arr:
13+
hash_dict = {inner_arr[0]: inner_arr[1]}
14+
hashes_arr.append(hash_dict)
15+
return hashes_arr

functions/ranks/main.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import functions_framework
2+
3+
from .libs.utils import output
4+
from .libs.utils import ( RANKS )
5+
from .libs.result import Result
6+
7+
@functions_framework.http
8+
def dispatcher(request):
9+
10+
response = Result(result=RANKS)
11+
12+
return output(response)

functions/ranks/requirements.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
functions-framework
2+
google-cloud-firestore
3+
pytest

0 commit comments

Comments
 (0)