started on tra-cli.py

modified tasks.py to work properly

Signed-off-by: Arthur Lu <learthurgo@gmail.com>
This commit is contained in:
Arthur Lu 2020-06-10 20:23:53 +00:00
parent 5d01d54852
commit d051cbd775
2 changed files with 54 additions and 31 deletions

View File

@ -18,62 +18,62 @@ class Tasker():
config = {} config = {}
def __init__(): def __init__(self):
config = su.load_config("config.json") self.config = su.load_config("config.json")
def match(): def match(self):
match_ = True self.match_ = True
apikey = config["key"]["database"] apikey = self.config["key"]["database"]
competition = config["competition"] competition = self.config["competition"]
tests = config["statistics"]["match"] tests = self.config["statistics"]["match"]
data = su.load_match(apikey, competition) data = su.load_match(apikey, competition)
su.matchloop(apikey, competition, data, tests) su.matchloop(apikey, competition, data, tests)
match_ = False self.match_ = False
if match_enable == True and match_ == False: if self.match_enable == True and self.match_ == False:
task = threading.Thread(name = "match", target = match) task = threading.Thread(name = "match", target = match)
task.start() task.start()
def metric(): def metric():
metric_ = True self.metric_ = True
apikey = config["key"]["database"] apikey = self.config["key"]["database"]
tbakey = config["key"]["tba"] tbakey = self.config["key"]["tba"]
competition = config["competition"] competition = self.config["competition"]
metric = config["statistics"]["metric"] metric = self.config["statistics"]["metric"]
timestamp = su.get_previous_time(apikey) timestamp = su.get_previous_time(apikey)
su.metricloop(tbakey, apikey, competition, timestamp, metric) su.metricloop(tbakey, apikey, competition, timestamp, metric)
metric_ = False self.metric_ = False
if metric_enable == True and metric_ == False: if self.metric_enable == True and self.metric_ == False:
task = threading.Thread(name = "match", target = metric) task = threading.Thread(name = "match", target = metric)
task.start() task.start()
def pit(): def pit():
pit_ = True self.pit_ = True
apikey = config["key"]["database"] apikey = self.config["key"]["database"]
competition = config["competition"] competition = self.config["competition"]
tests = config["statistics"]["pit"] tests = self.config["statistics"]["pit"]
data = su.load_pit(apikey, competition) data = su.load_pit(apikey, competition)
su.pitloop(apikey, competition, data, tests) su.pitloop(apikey, competition, data, tests)
pit_ = False self.pit_ = False
if pit_enable == True and pit_ == False: if self.pit_enable == True and self.pit_ == False:
task = threading.Thread(name = "pit", target = pit) task = threading.Thread(name = "pit", target = pit)
task.start() task.start()
@ -91,31 +91,31 @@ class Tasker():
task.start() task.start()
def stop_match(): def stop_match():
match_enable = False self.match_enable = False
def stop_metric(): def stop_metric():
metric_enable = False self.metric_enable = False
def stop_pit(): def stop_pit():
pit_enable = False self.pit_enable = False
def get_match(): def get_match():
return match_ return self.match_
def get_metric(): def get_metric():
return metric_ return self.metric_
def get_pit(): def get_pit():
return pit_ return self.pit_
def get_match_enable(): def get_match_enable():
return match_enable return self.match_enable
def get_metric_enable(): def get_metric_enable():
return metric_enable return self.metric_enable
def get_pit_enable(): def get_pit_enable():
return pit_enable return self.pit_enable
""" """
def main(): def main():

23
tra-cli.py Normal file
View File

@ -0,0 +1,23 @@
import argparse
from tasks import Tasker
t = Tasker()
task_map = {"match":None, "metric":None, "pit":None}
status_map = {"match":None, "metric":None, "pit":None}
status_map.update(task_map)
parser = argparse.ArgumentParser(prog = "TRA")
subparsers = parser.add_subparsers(title = "command", metavar = "C", help = "//commandhelp//")
parser_start = subparsers.add_parser("start", help = "//starthelp//")
parser_start.add_argument("target(s)", metavar = "T", nargs = "*", choices = task_map.keys())
parser_stop = subparsers.add_parser("stop", help = "//stophelp//")
parser_start.add_argument("target(s)", metavar = "T", nargs = "*", choices = task_map.keys())
parser_status = subparsers.add_parser("status", help = "//stophelp//")
parser_start.add_argument("target(s)", metavar = "T", nargs = "*", choices = status_map.keys())
args = parser.parse_args()
print(args)