forked from CodecoolBase/ask-mate-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.py
More file actions
37 lines (22 loc) · 849 Bytes
/
util.py
File metadata and controls
37 lines (22 loc) · 849 Bytes
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
import connection
from datetime import datetime
import time
import data_manager
import csv
def get_current_time():
timestamp = time.time()
timestamp = round(timestamp)
return timestamp
def sort_questions_by_timestamp():
data = connection.read_data_from_file(connection.QUESTIONS_PATH)
sorted_data = sorted(data, key=lambda k: k["submission_time"], reverse=True)
return sorted_data
def sort_answers_by_timestamp():
data = connection.read_data_from_file(connection.ANSWERS_PATH)
sorted_data = sorted(data, key=lambda k: k["submission_time"], reverse=True)
return sorted_data
def get_date_format_for_sorted_data(data):
for row in data:
timestamp = int(row["submission_time"])
row["submission_time"] = datetime.utcfromtimestamp(timestamp).strftime("%Y-%m-%d %H:%M")
return data