|
1 | | -from elex.api import Elections |
2 | | -from elex.api import DelegateReport |
3 | | -from elex import __version__ as VERSION |
| 1 | +from cement.core.controller import CementBaseController, expose |
4 | 2 | from cement.core.foundation import CementApp |
5 | | -from elex.cli.hooks import add_election_hook |
6 | 3 | from cement.ext.ext_logging import LoggingLogHandler |
7 | | -from cement.core.controller import CementBaseController, expose |
| 4 | +from elex.api import DelegateReport |
| 5 | +from elex.api import Elections |
| 6 | +from elex.cli.constants import BANNER, LOG_FORMAT |
8 | 7 | from elex.cli.decorators import require_date_argument, require_ap_api_key |
9 | | - |
10 | | -LOG_FORMAT = '%(asctime)s (%(levelname)s) %(namespace)s (v{0}) : \ |
11 | | -%(message)s'.format(VERSION) |
12 | | -BANNER = """ |
13 | | -NYT AP Elections version {0} |
14 | | -""".format(VERSION) |
| 8 | +from elex.cli.hooks import add_election_hook, cachecontrol_logging_hook |
15 | 9 |
|
16 | 10 |
|
17 | 11 | class ElexBaseController(CementBaseController): |
@@ -131,6 +125,12 @@ def races(self): |
131 | 125 | self.app.log.debug( |
132 | 126 | 'Elex API URL: {0}'.format(self.app.election._response.url) |
133 | 127 | ) |
| 128 | + self.app.log.debug( |
| 129 | + 'ELAPI cache hit: {0}'.format(self.app.election._response.from_cache) |
| 130 | + ) |
| 131 | + if self.app.election._response.from_cache: |
| 132 | + self.app.exit_code = 64 |
| 133 | + |
134 | 134 | self.app.render(data) |
135 | 135 |
|
136 | 136 | @expose(help="Get reporting units") |
@@ -171,6 +171,12 @@ def reporting_units(self): |
171 | 171 | self.app.log.debug( |
172 | 172 | 'Elex API URL: {0}'.format(self.app.election._response.url) |
173 | 173 | ) |
| 174 | + self.app.log.debug( |
| 175 | + 'ELAPI cache hit: {0}'.format(self.app.election._response.from_cache) |
| 176 | + ) |
| 177 | + if self.app.election._response.from_cache: |
| 178 | + self.app.exit_code = 64 |
| 179 | + |
174 | 180 | self.app.render(data) |
175 | 181 |
|
176 | 182 | @expose(help="Get candidate reporting units (without results)") |
@@ -233,6 +239,12 @@ def candidate_reporting_units(self): |
233 | 239 | self.app.log.debug( |
234 | 240 | 'Elex API URL: {0}'.format(self.app.election._response.url) |
235 | 241 | ) |
| 242 | + self.app.log.debug( |
| 243 | + 'ELAPI cache hit: {0}'.format(self.app.election._response.from_cache) |
| 244 | + ) |
| 245 | + if self.app.election._response.from_cache: |
| 246 | + self.app.exit_code = 64 |
| 247 | + |
236 | 248 | self.app.render(data) |
237 | 249 |
|
238 | 250 | @expose(help="Get candidates") |
@@ -269,6 +281,12 @@ def candidates(self): |
269 | 281 | self.app.log.debug( |
270 | 282 | 'Elex API URL: {0}'.format(self.app.election._response.url) |
271 | 283 | ) |
| 284 | + self.app.log.debug( |
| 285 | + 'ELAPI cache hit: {0}'.format(self.app.election._response.from_cache) |
| 286 | + ) |
| 287 | + if self.app.election._response.from_cache: |
| 288 | + self.app.exit_code = 64 |
| 289 | + |
272 | 290 | self.app.render(data) |
273 | 291 |
|
274 | 292 | @expose(help="Get ballot measures") |
@@ -305,6 +323,12 @@ def ballot_measures(self): |
305 | 323 | self.app.log.debug( |
306 | 324 | 'Elex API URL: {0}'.format(self.app.election._response.url) |
307 | 325 | ) |
| 326 | + self.app.log.debug( |
| 327 | + 'ELAPI cache hit: {0}'.format(self.app.election._response.from_cache) |
| 328 | + ) |
| 329 | + if self.app.election._response.from_cache: |
| 330 | + self.app.exit_code = 64 |
| 331 | + |
308 | 332 | self.app.render(data) |
309 | 333 |
|
310 | 334 | @expose(help="Get results") |
@@ -343,6 +367,12 @@ def results(self): |
343 | 367 | self.app.log.debug( |
344 | 368 | 'Elex API URL: {0}'.format(self.app.election._response.url) |
345 | 369 | ) |
| 370 | + self.app.log.debug( |
| 371 | + 'ELAPI cache hit: {0}'.format(self.app.election._response.from_cache) |
| 372 | + ) |
| 373 | + if self.app.election._response.from_cache: |
| 374 | + self.app.exit_code = 64 |
| 375 | + |
346 | 376 | self.app.render(data) |
347 | 377 |
|
348 | 378 | @expose(help="Get list of available elections") |
@@ -462,6 +492,7 @@ class Meta: |
462 | 492 | label = 'elex' |
463 | 493 | base_controller = ElexBaseController |
464 | 494 | hooks = [ |
| 495 | + ('post_setup', cachecontrol_logging_hook), |
465 | 496 | ('post_argument_parsing', add_election_hook), |
466 | 497 | ] |
467 | 498 | extensions = [ |
|
0 commit comments