-
Notifications
You must be signed in to change notification settings - Fork 0
/
stats_extractor.py
52 lines (37 loc) · 1.71 KB
/
stats_extractor.py
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# -*- coding: utf-8 -*-
import os
import sys
import re
import settings
from auth.connector import TrelloConnector
from stats import summary
from stats.trelloboardconfiguration import TrelloBoardConfiguration
def extract_stats(configuration_file_path):
"""
Extract stats for a given configuration file that defines a trello board and other settings.
:param configuration_file_path: file path where the configuration file is.
"""
configuration = TrelloBoardConfiguration.load_from_file(configuration_file_path)
summary.make(trello_connector, configuration)
def file_is_configuration_file(_file_name):
return re.match(r"^[^\.]+\.conf\.txt", _file_name)
if __name__ == "__main__":
api_key = settings.TRELLO_API_KEY
api_secret = settings.TRELLO_API_SECRET
token = settings.TRELLO_TOKEN
token_secret = settings.TRELLO_TOKEN_SECRET
trello_connector = TrelloConnector(api_key, api_secret, token, token_secret)
if len(sys.argv) < 2:
raise ValueError(u"Error. Use python stats_extractor.py <configuration_file_path>")
# Configuration file path
configuration_path = sys.argv[1]
# If configuration path is a file, extract stats of the board written in this file
if os.path.isfile(configuration_path):
extract_stats(configuration_path)
# Otherwise, if configuration path is a directory, loop through directory files and extract stats
# for each of these files
elif os.path.isdir(configuration_path):
for file_name in os.listdir(configuration_path):
if file_is_configuration_file(file_name):
print(u"Processing {0}".format(file_name))
extract_stats(u"{0}/{1}".format(configuration_path, file_name))