-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcountries.py
158 lines (113 loc) · 3.73 KB
/
countries.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
#
from flask_restx import Namespace, Resource, inputs
from pycountry import countries
#
from commonFunctions import *
#
currentCountriesNamespace = Namespace('countries', description='Namespace to manipulate and get informations about all countries in the world...')
#
parser_gen = reqparse.RequestParser()
#
parser_gen.add_argument('order', type=str, required=True, choices=["desc", "asc"], help='')
#
@currentCountriesNamespace.route('')
@currentCountriesNamespace.expect(parser_gen)
class CountriesList(Resource):
#
def get(self):
"""
Get the list of all existing-at-present countries in the world...
"""
#
args = parser_gen.parse_args()
#
return getJSONOfCountries(order=args["order"]), 200
#
@currentCountriesNamespace.route('/historical')
class HistoricalCountriesList(Resource):
#
def get(self):
"""
Get the list of all ancient countries in the world...
"""
#
return getJSONOfHistoricalCountries(list(pycountry.historic_countries)), 200
#
parser_sort = reqparse.RequestParser()
#
parser_sort.add_argument('pattern', type=str, required=True, help='Fill in the pattern you want...')
parser_sort.add_argument('order', type=str, required=True, choices=["desc", "asc"], help='')
#
@currentCountriesNamespace.route('/sort/name')
@currentCountriesNamespace.expect(parser_sort)
class CountriesSortName(Resource):
#
def get(self):
"""
Get the list of all existing-at-present countries selected according a to pattern and sort according to an order...
"""
#
args = parser_sort.parse_args()
#
return getJSONofCountriesFromSort(field = "name", order = args.order, pattern = args["pattern"]), 200
#
@currentCountriesNamespace.route('/sort/alpha_2')
@currentCountriesNamespace.expect(parser_sort)
class CountriesSortAlpha2(Resource):
#
def get(self):
"""
Get the list of all existing-at-present countries selected according a to pattern and sort according to an order...
"""
#
args = parser_sort.parse_args()
#
return getJSONofCountriesFromSort(field = "alpha_2", order = args.order, pattern = args["pattern"]), 200
#
@currentCountriesNamespace.route('/sort/alpha_3')
@currentCountriesNamespace.expect(parser_sort)
class CountriesSortAlpha3(Resource):
#
def get(self):
"""
"""
#
args = parser_sort.parse_args()
#
return getJSONofHistoricalCountriesFromSort(field = "alpha_3", order = args.order, pattern = args["pattern"]), 200
#
@currentCountriesNamespace.route('/historical/sort/name')
@currentCountriesNamespace.expect(parser_sort)
class HistoricalCountriesSortName(Resource):
#
def get(self):
"""
"""
#
args = parser_sort.parse_args()
#
return getJSONofHistoricalCountriesFromSort(field = "name", order = args.order, pattern = args["pattern"]), 200
#
@currentCountriesNamespace.route('/historical/sort/alpha_2')
@currentCountriesNamespace.expect(parser_sort)
class HistoricalCountriesSortAlpha2(Resource):
#
def get(self):
"""
"""
#
args = parser_sort.parse_args()
#
return getJSONofHistoricalCountriesFromSort(field = "alpha_2", order = args.order, pattern = args["pattern"]), 200
#
@currentCountriesNamespace.route('/historical/sort/alpha_3')
@currentCountriesNamespace.expect(parser_sort)
class HistoricalCountriesSortAlpha3(Resource):
#
def get(self):
"""
"""
#
args = parser_sort.parse_args()
#
return getJSONofHistoricalCountriesFromSort(field = "alpha_3", order = args.order, pattern = args["pattern"]), 200