aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/vk
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2016-06-18 00:43:21 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2016-06-18 00:43:21 +0300
commit6cc5aa35937038fdbd7fab1dfcd56feba319567a (patch)
treeabdb7d6517ff21365fe390fe27245106ff2c31d1 /vk
parenthow_much_online.py: CSV/JSON/bar chart output (diff)
downloadvk-scripts-6cc5aa35937038fdbd7fab1dfcd56feba319567a.tar.gz
vk-scripts-6cc5aa35937038fdbd7fab1dfcd56feba319567a.zip
refactoring
Diffstat (limited to 'vk')
-rw-r--r--vk/utils/tracking/db/reader/csv.py3
-rw-r--r--vk/utils/tracking/db/record.py32
-rw-r--r--vk/utils/tracking/db/timestamp.py34
3 files changed, 38 insertions, 31 deletions
diff --git a/vk/utils/tracking/db/reader/csv.py b/vk/utils/tracking/db/reader/csv.py
index e9c9407..9d4e7dc 100644
--- a/vk/utils/tracking/db/reader/csv.py
+++ b/vk/utils/tracking/db/reader/csv.py
@@ -5,7 +5,8 @@
from collections.abc import Iterable
import csv
-from ..record import Record, Timestamp
+from ..record import Record
+from ..timestamp import Timestamp
class Reader(Iterable):
def __init__(self, path):
diff --git a/vk/utils/tracking/db/record.py b/vk/utils/tracking/db/record.py
index fd276fc..93be97c 100644
--- a/vk/utils/tracking/db/record.py
+++ b/vk/utils/tracking/db/record.py
@@ -4,39 +4,11 @@
from collections import OrderedDict
from collections.abc import MutableMapping
-from datetime import datetime, timezone
+from datetime import datetime
+from .timestamp import Timestamp
from vk.user import LastSeen, LastSeenField, User, UserField
-class Timestamp:
- @staticmethod
- def _new():
- return datetime.utcnow()
-
- @staticmethod
- def _is_timezone_aware(dt):
- return dt.tzinfo is not None and dt.tzinfo.utcoffset(dt) is not None
-
- @staticmethod
- def _lose_timezone(dt):
- if Timestamp._is_timezone_aware(dt):
- return dt.astimezone(timezone.utc).replace(tzinfo=None)
- return dt
-
- def __init__(self, dt=None):
- if dt is None:
- dt = self._new()
- dt = dt.replace(microsecond=0)
- dt = self._lose_timezone(dt)
- self.dt = dt
-
- @staticmethod
- def from_string(s):
- return Timestamp(datetime.strptime(s, '%Y-%m-%dT%H:%M:%SZ'))
-
- def __str__(self):
- return self.dt.isoformat() + 'Z'
-
class Record(MutableMapping):
FIELDS = (
UserField.UID,
diff --git a/vk/utils/tracking/db/timestamp.py b/vk/utils/tracking/db/timestamp.py
new file mode 100644
index 0000000..35cf5b3
--- /dev/null
+++ b/vk/utils/tracking/db/timestamp.py
@@ -0,0 +1,34 @@
+# Copyright 2016 Egor Tensin <Egor.Tensin@gmail.com>
+# This file is licensed under the terms of the MIT License.
+# See LICENSE.txt for details.
+
+from datetime import datetime, timezone
+
+class Timestamp:
+ @staticmethod
+ def _new():
+ return datetime.utcnow()
+
+ @staticmethod
+ def _is_timezone_aware(dt):
+ return dt.tzinfo is not None and dt.tzinfo.utcoffset(dt) is not None
+
+ @staticmethod
+ def _lose_timezone(dt):
+ if Timestamp._is_timezone_aware(dt):
+ return dt.astimezone(timezone.utc).replace(tzinfo=None)
+ return dt
+
+ def __init__(self, dt=None):
+ if dt is None:
+ dt = self._new()
+ dt = dt.replace(microsecond=0)
+ dt = self._lose_timezone(dt)
+ self.dt = dt
+
+ @staticmethod
+ def from_string(s):
+ return Timestamp(datetime.strptime(s, '%Y-%m-%dT%H:%M:%SZ'))
+
+ def __str__(self):
+ return self.dt.isoformat() + 'Z'