forked from hishamhm/usercount
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcommon.py
More file actions
26 lines (20 loc) · 708 Bytes
/
common.py
File metadata and controls
26 lines (20 loc) · 708 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
import json
import csv
import os
def get_json(filename, default_value=None):
if os.path.isfile(filename):
with open(filename) as f:
return json.load(f)
return default_value
def save_json(filename, values):
with open(filename, 'w') as outfile:
json.dump(values, outfile, indent=4, sort_keys=True)
def get_mastostats():
mastostats_csv = "mastostats.csv"
masto_array = [['timestamp', 'usercount', 'instancecount', 'tootscount']]
if os.path.isfile(mastostats_csv):
with open(mastostats_csv, 'r') as csvfile:
reader = csv.reader(csvfile)
masto_array = [row for row in reader]
csvfile.close()
return masto_array