Commit 8c465c942e6e957649ce1e9acc585b92c407956c
1 parent
e9a989e0
Exists in
master
Implement methods for the visits counter.
Showing
1 changed file
with
33 additions
and
5 deletions
Show diff stats
flaskr/core.py
1 | 1 | import abc |
2 | 2 | import importlib |
3 | +from os.path import isfile | |
3 | 4 | from datetime import datetime |
4 | 5 | from uuid import uuid4 |
5 | 6 | |
6 | 7 | from .content import content |
7 | 8 | |
8 | 9 | |
10 | +hit_count_path = "../VISITS" | |
11 | + | |
12 | + | |
9 | 13 | def generate_unique_id(): |
10 | 14 | """ |
11 | 15 | :return: a unique identifier that can be sorted chronologically. |
... | ... | @@ -32,8 +36,32 @@ def get_emission_models(): |
32 | 36 | models = get_emission_models() |
33 | 37 | |
34 | 38 | |
35 | -# unused | |
36 | -class FootprintEstimatorDriver(abc.ABCMeta): | |
37 | - @abc.abstractmethod | |
38 | - def get_travel_footprint(self, from_location, to_location): # TBD | |
39 | - pass | |
39 | +def get_hit_counter(): | |
40 | + hit_count = 1 | |
41 | + if isfile(hit_count_path): | |
42 | + with open(hit_count_path) as hcf: | |
43 | + hit_count = int(hcf.read().strip()) | |
44 | + | |
45 | + return hit_count | |
46 | + | |
47 | + | |
48 | +def increment_hit_counter(): | |
49 | + if isfile(hit_count_path): | |
50 | + hit_count = int(open(hit_count_path).read()) | |
51 | + hit_count += 1 | |
52 | + else: | |
53 | + hit_count = 1 | |
54 | + | |
55 | + hit_counter_file = open(hit_count_path, 'w') | |
56 | + hit_counter_file.write(str(hit_count)) | |
57 | + hit_counter_file.close() | |
58 | + | |
59 | + return hit_count | |
60 | + | |
61 | + | |
62 | + | |
63 | +# # unused | |
64 | +# class FootprintEstimatorDriver(abc.ABCMeta): | |
65 | +# @abc.abstractmethod | |
66 | +# def get_travel_footprint(self, from_location, to_location): # TBD | |
67 | +# pass | ... | ... |