from __future__ import print_function import os import sys import json from config import * def eprint(*args, **kwargs): print(*args, file=sys.stderr, **kwargs) # #from typing import Iterable # > py38 # from collections import Iterable # < py38 # def flatten(items): # """Yield items from any nested iterable; see Reference.""" # for x in items: # if isinstance(x, Iterable) and not isinstance(x, (str, bytes)): # for sub_x in flatten(x): # yield sub_x # else: # yield x def jlog( obj ): print( json.dumps(obj, indent=4) ) #"\t") ) def ensure_dir(d): if not os.path.exists(d): os.makedirs(d) def args2domains( list ): domains = [] while len(list) > 0: str = list[0] if str == '&' or str == '|' or str == '!': domains.append( str ) list = list[1:] else: domains.append( (list[0], list[1], list[2]) ) list = list[3:] return domains # eprint( args2domains(sys.argv[3:]) ) def file_path( muid, format ): return "%s/%s.%s" % ( DATADIR, muid, format ) def json_path( model, id ): return "%s/%s.json" % ( DATADIR, Muid(model, id) ) def Muid( model, id ): return "%s/%s" % ( model, id ) def uniq( arr ): return list(set(arr)) def groupby_model( arr ): res = {} for muid in arr: model, id = muid.split('/') if not model in res: res[model] = [] res[model].append( int(id) ) return res