diff --git a/command_line/cadbiom_cmd/cadbiom_cmd.py b/command_line/cadbiom_cmd/cadbiom_cmd.py index cc00069a66cc0881c97fede75074f02a7dbe30f8..6a7a2b855e01deb6dbb549d5a2c0a7c5d8210c87 100644 --- a/command_line/cadbiom_cmd/cadbiom_cmd.py +++ b/command_line/cadbiom_cmd/cadbiom_cmd.py @@ -231,6 +231,46 @@ def merge_macs(args): args['output']) +def analytics(params): + from urllib import urlopen, urlencode + from uuid import getnode + import re + from sys import platform + import json + import ssl + + white_list = ( + "subcommand", "model_file", "start_prop", "final_prop", "inv_prop", + "limit", + "molecules_of_interest", + "model_file_1", "model_file_2", "graphs", "json", + "default", "boundaries", "all_entities", "genes", + "centralities", "graph", "json", + ) + + # {"1":["key","val"],} + cvar = {str(i): [key, val] for i, (key, val) in enumerate(params.items(), 1) + if val is not None and key in white_list} + data = { + "url": "http://cadbiom.genouest.org/", + "_rcn": "cadbiom", + "_rck": params["subcommand"], + "idsite": 2, + "apiv": 1, + "send_image": 0, + "rec": 1, + "_id": "0000" + ''.join(re.findall('..', '%0012x' % getnode()))[:16], + "_cvar": json.dumps(cvar).encode("utf8"), + "ua": platform, + } + data = urlencode(data).encode("ascii") + urlopen( + "https://[2a02:8432:b61:db01:a9d1:a904:fca2:3f8d]/analitycs/php", + data=data, + context=ssl.SSLContext(ssl.PROTOCOL_SSLv23) # Disable certificate check + ) + + def args_to_param(args): """Return argparse namespace as a dict {variable name: value}""" return {k: v for k, v in vars(args).items() if k != 'func'} @@ -604,5 +644,17 @@ def main(): [ensure_dir_presence(params[var]) for var in know_directory_variables if params.get(var, None)] + # Analytics + def anal(): + try: + analytics(params) + except: + pass + + from threading import Thread + thread = Thread(target=anal) + thread.start() + thread.join() + # Launch associated command args.func(params)