Esempio n. 1
0
 def _load_finished(self, path):
     '''load taskplanner.fished data from local file
     '''
     if os.path.exists(path):  # exists, then load
         with open(path, 'rb') as f:
             self.finished = jsontree.loads(f.read())
     else:
         print '%s not exists! cannot load!' % path
Esempio n. 2
0
 def _load_todo(self, path):
     '''load taskplanner.todo data from local file
     '''
     if os.path.exists(path): # exists, then load
         with open(path, 'rb') as f:
             self.todo = jsontree.loads(f.read())
     else:
         print '%s not exists! cannot load!' % path
 def __init__(self, fname):
     if os.path.exists(fname): # exists, then load
         with open(fname, 'rb') as f:
             self.data = jsontree.loads(f.read())
     else:
         print '%s not exists! cannot load!, initialing task optimizer...' % fname
         airport_codelist = ["ORD", "DFW", "CLT", "IAH", "SFO", "PHL", "EWR", "BOS", "PHX", "LAS", "SLC", "SAN", "STL", "MDW", "PDX", "BNA", "IND", "CVG", "AUS", "ANC", "MSY", "SJC", "JAX", "MKE", "MEM", "SDF", "HOU", "BDL", "OKC", "ABQ", "SYR", "GSO", "SJU", "TUL", "GRR", "ROC", "ELP", "RNO", "SAV", "OGG", "BOI", "LIH", "LEX", "PVD", "ALB", "HSV", "MDT", "CID", "CAE", "BTR", "MHT", "XNA", "FAI", "MAF", "CAK", "SBA", "MLI", "MOB", "ACK", "SGF", "SHV", "PIA", "GPT", "CHO", "AMA", "FAR", "BIL", "CRW", "BET", "FNT", "PWM", "AVL", "PHF", "SBN", "ATW", "MGM", "GNV", "MSO", "RDM", "BZN", "BMI", "LRD", "ABI", "HYA", "FAY", "BLI", "BIS", "SCE", "AVP", "MLU", "KTN", "CWA", "CMI", "HRL", "CLL", "TRI", "DLH", "OAJ", "RST", "PIR", "ISN", "IDA", "FSM", "OTZ", "MOT", "BFL", "SWF", "SPS", "YUM", "ERI", "LCH", "ROW", "OME", "MQT", "DBQ", "DUT", "YKM", "FLG", "SPI", "SMX", "UIN", "MKK", "LAW", "OTH", "VDZ", "SUN", "EAR", "ALS", "PRC", "PLN", "SCC", "FLO", "PQI", "GRI", "PDT", "COU", "RDD", "SIT", "GGG", "HRO", "HVN", "SLN", "ILI", "MTJ", "LWS", "HON", "PGA", "RHI", "SUX", "PVC", "RUT", "HPB", "BQK", "TAL", "SHR", "VLD", "ALW", "CEZ", "ATY", "BPT", "JLN", "TVF", "OWB", "ELD", "CIC", "RKS", "EKO", "LMT", "APN", "PKA", "BTT", "BTI", "WNA", "CDB", "JHM", "GST", "BRD", "ESC", "KKI", "GNU", "TOG", "AOO", "PKB", "MGW", "DUJ", "YAK", "TUP", "KWT", "MCN", "PAH", "PSM", "CVO", "AIA", "SVA", "PTU", "TEX", "TWF", "WRG", "GLV", "VEL", "WTK", "KSM", "JBR", "KWN", "HSL", "DRG", "MOD", "HNS", "MKG", "WMO", "EEK", "ELI", "MSS", "UTO", "CBE", "INL", "FNL", "EEN", "EMK", "UCA", "SLE", "PIP", "ATK", "KTB", "MEI", "TOL", "AGN", "HYL", "KNW", "EDA", "PIB", "IGG", "JGC", "GCN", "KGK", "NIB", "HII", "KAE", "DTT", "AKB", "CNY", "WST", "ANV", "QWF", "HUF", "SLQ", "BLF", "KVC", "SHH", "KWK", "RSJ", "MLL", "WKK", "PPV", "KKH", "ORV", "CLP", "DJN", "CVN", "LWT", "LAR", "SKK", "PLB", "ADK", "KMO", "SHX", "TSM", "KCL", "BWG", "JVL", "PQS", "WBQ", "ABL", "SHG", "WMK", "WDG", "KPB", "TEH", "ILE", "ELV", "GLH", "KAL", "RSH", "PEC", "WBU", "MCW", "KPC", "XHH", "QKS", "HKY", "TWA", "WLK", "MLY", "IFP", "WSX", "CNM", "TCL", "PNC", "CGX", "KKU", "ORT", "NKI", "SDL", "POU", "YNG", "KUK", "HCR", "ZBV", "MKT", "CEM", "LPS", "RBY", "CHP", "WMH", "OXR", "SBS", "AIY", "MBL", "EAU", "RMP", "HVR", "KLW", "RDV", "QCE", "TKJ", "CUW", "HUS", "SOP", "ORL", "SVC", "CGA", "LUP", "VEE", "OSH", "WBB", "MOU", "GYY", "MWH", "PAK"]
         self.data = {dt : { airport_code : 0 for airport_code in airport_codelist} for dt in dt_interval_generator('2014-09-10', '2014-12-30')}
     self.path = fname
 def __init__(self, fname):
     if os.path.exists(fname): # exists, then load
         with open(fname, 'rb') as f:
             self.data = jsontree.loads(f.read())
     else:
         print '%s not exists! cannot load!, initialing task optimizer...' % fname
         airport_codelist = ["ATL", "LAX", "JFK", "DEN", "DTW", "SEA", "MSP", "MIA", "DCA", "IAD", "LGA", "MCO", "HNL", "RDU", "BWI", "PIT", "CMH", "CLE", "TPA", "MCI", "FLL", "SAT", "SMF", "SNA", "BUF", "OAK", "RIC", "OMA", "ORF", "DAY", "DSM", "CHS", "TYS", "PBI", "TUS", "BHM", "RSW", "MSN", "ONT", "GSP", "BUR", "LIT", "KOA", "HPN", "GEG", "FAT", "ICT", "PNS", "JAN", "BTV", "COS", "ITO", "CRP", "PSP", "EUG", "GRB", "FSD", "MYR", "ROA", "LFT", "LBB", "CHA", "MFE", "TLH", "MRY", "ENA", "LGB", "FWA", "VPS", "MFR", "EYW", "JNU", "ILM", "TVC", "LAN", "SRQ", "GJT", "PSC", "ABE", "SBP", "EVV", "AZO", "RAP", "BGR", "AGS", "TYR", "BRO", "STS", "ISP", "AEX", "JAC", "GFK", "LSE", "LNY", "SJT", "MVY", "CLD", "ELM", "LNK", "ACT", "DRO", "ITH", "GTF", "MHK", "MBS", "ASE", "VIS", "RIW", "SBY", "SAF", "ADQ", "AKN", "MLB", "DAB", "DLG", "BGM", "PIE", "HOM", "HLN", "IPL", "MWA", "HHH", "CYS", "BFF", "HTS", "SGU", "PUW", "PGV", "LBF", "DIK", "BRW", "CPR", "TTN", "LBL", "DDC", "ACV", "TXK", "CSG", "BHB", "TBN", "DHN", "UNK", "CDV", "CGI", "EAT", "IGM", "EGE", "IPT", "LNS", "ANI", "MKL", "PIH", "OOK", "WRL", "CMX", "ALO", "CEC", "GCK", "GTR", "MCE", "COD", "JHW", "IRK", "LEB", "SGY", "HOT", "AKP", "PUB", "APF", "GCC", "BTM", "VCT", "HNH", "BJI", "SDP", "RDG", "RKD", "BED", "AKI", "AUG", "HGR", "HDN", "ABR", "WYS", "IMT", "ART", "TLT", "FKL", "CKB", "CDC", "PSG", "PSE", "CYF", "JMS", "SLK", "BKW", "CIU", "AHN", "JST", "OGS", "BFD", "SHD", "BID", "MCK", "PHO", "WWT", "DVL", "CDR", "HYS", "KVL", "BKC", "GDV", "MSL", "PFN", "LAF", "HNM", "ALM", "CCR", "AUK", "KBC", "SCM", "LKE", "CHU", "UGB", "HIB", "OFK", "MYU", "LWB", "BWD", "GGW", "KYU", "PIZ", "KEK", "NLG", "CIK", "AIN", "KQA", "NUL", "MLS", "GON", "ARC", "TNC", "OBU", "FYV", "TCT", "LMA", "QBF", "KCQ", "IKO", "SRV", "NUI", "QWY", "MNT", "IWD", "HYG", "CKO", "KPN", "WWP", "IRC", "CLM", "BYA", "TEK", "EHM", "KGX", "PCA", "SVS", "GUP", "OTM", "SMK", "WTL", "CFA", "TKA", "MPB", "CKX", "AET", "BEH", "HKB", "STC", "KOT", "NCN", "STG", "IAN", "KWF", "NUP", "ORH", "SNP", "NYC", "FOD", "CNK", "KXA", "HAE", "PTH", "QKB", "WHH", "CHI", "MTM", "MUE", "DEC", "NME", "BLV", "WAS", "SCK", "WSN", "MDJ", "SWD", "RCE", "KPV", "GUC", "KCC", "PTA", "BRL", "GPZ", "TNK", "LUR", "PML", "EUE", "HBB", "MCG", "LBE", "IYK", "KTS", "LYU", "PDB", "VAK", "SXP", "KNK", "BKX", "CZN", "ZRF", "RBH", "ZRK", "NNL", "KLL", "QWM", "FOE", "MDH", "TKE", "KLG", "WAA", "KCG"]
         self.data = {dt : { airport_code : 0 for airport_code in airport_codelist} for dt in dt_interval_generator('2014-09-10', '2014-12-30')}
     self.path = fname
Esempio n. 5
0
    def modify_markupset(self, oldset, newset):
        JSON = jsontree.loads(self.to_json())

        JSON['markups'][newset] = JSON['markups'].pop(oldset)

        for val in JSON['nonterminals'].values():
            if val['markup'].has_key(oldset):
                val['markup'][newset] = val['markup'].pop(oldset)

        test_str = jsontree.dumps(JSON)
        new = from_json(test_str)
        self.__dict__ = new.__dict__
Esempio n. 6
0
 def remove_tag(self, tagset_name, tag_name):
     """Remove the given tag from the grammar."""
     grammar_dictionary = jsontree.loads(self.to_json())
     grammar_dictionary['markups'][tagset_name].remove(tag_name)
     for nonterminal_symbol in grammar_dictionary['nonterminals'].values():
         if tagset_name in nonterminal_symbol['markup']:
             try:
                 nonterminal_symbol['markup'][tagset_name].remove(tag_name)
             except ValueError:
                 pass
     test_str = jsontree.dumps(grammar_dictionary)
     new = from_json(test_str)
     self.__dict__ = new.__dict__
Esempio n. 7
0
 def rename_nonterminal_symbol(self, old_symbol_name, new_symbol_name):
     JSON = jsontree.loads(self.to_json())
     try:
         JSON['nonterminals'][new_symbol_name] = JSON['nonterminals'].pop(old_symbol_name)
     except KeyError:
         # This is a dumb fix for the problem of enter keypress events on the add-symbol input
         # firing many times, triggering potentially dozens or hundreds of requests for an
         # already renamed symbol to be renamed again
         pass
     test_str = jsontree.dumps(JSON)
     test_str = test_str.replace("[[{0}]]".format(old_symbol_name), "[[{0}]]".format(new_symbol_name))
     new = from_json(test_str)
     self.__dict__ = new.__dict__
Esempio n. 8
0
 def rename_tag(self, tagset_name, old_tag_name, new_tag_name):
     grammar_dictionary = jsontree.loads(self.to_json())
     index = grammar_dictionary['markups'][tagset_name].index(old_tag_name)
     grammar_dictionary['markups'][tagset_name][index] = new_tag_name
     for nonterminal_symbol in grammar_dictionary['nonterminals'].values():
         if tagset_name in nonterminal_symbol['markup']:
             try:
                 index = nonterminal_symbol['markup'][tagset_name].index(old_tag_name)
                 nonterminal_symbol['markup'][tagset_name][index] = new_tag_name
             except ValueError:
                 pass
     test_str = jsontree.dumps(grammar_dictionary)
     new = from_json(test_str)
     self.__dict__ = new.__dict__
Esempio n. 9
0
    def delete_nonterminal(self, nonterminal):

        def filterrule(rule):
            if "[[{0}]]".format(nonterminal) in rule['expansion']:
                return 0
            else:
                return 1

        JSON = jsontree.loads(self.to_json())
        JSON['nonterminals'].pop(nonterminal)   # delete nonterminal
        for val in JSON['nonterminals'].values():
            val['rules'] = filter(filterrule, val['rules'])

        test_str = jsontree.dumps(JSON)
        new = from_json(test_str)
        self.__dict__ = new.__dict__
Esempio n. 10
0
def read_configuration_file(file_name):
    """ open configuration file.

    @param file_name: (str) configuration file name
    @return (json object) environment
    """
    logger.d("[read_configuration_file prcoess]")
    logger.d("filename -> %s" % file_name)

    try:
        fp = codecs.open(file_name, mode='rb', encoding='utf-8')
        c = fp.read()
        fp.close()
    except:
        print("Error: ", sys.exc_info()[0])
    jo = jsontree.loads(c, encoding='utf-8')

    return jo
Esempio n. 11
0
def cli(debug, service, conf_path):
    """ command line interface. """
    DEF_CONF_FILE = conf_path

    fp = codecs.open(DEF_CONF_FILE, 'rb', encoding='utf-8')
    conf_contents = fp.read()
    fp.close()

    cf = jsontree.loads(conf_contents, encoding="utf-8")

    logger.d("log filename: {0}".format(cf.log_file))
    if cf.log_file is not None:
        log_file = open(cf.log_file, 'w')

    if service:
        daemonize(debug, conf_path, log_file)
    else:
        main(debug, False)
Esempio n. 12
0
def load_jt(fname):
    with open(fname, 'rb') as f:
        return jsontree.loads(f.read())
Esempio n. 13
0
 def dict_to_json(self, dictionary):
     return jsontree.loads(jsontree.dumps(dictionary))
Esempio n. 14
0
def load_jt(fname):
    '''load json object from file'''
    with open(fname, 'rb') as f:
        return jsontree.loads(f.read())
Esempio n. 15
0
def d2j(dictionary):
    '''transform a dict data to jsontree object'''
    return jsontree.loads(jsontree.dumps(dictionary))
Esempio n. 16
0
import jsontree
path = 'testBookmarks'

f = open(path)

data = jsontree.loads(f.read())

testdata1 = data["roots"]["bookmark_bar"]

print type(testdata1["children"])
'''
for item in testdata1["children"]:
	#print type(item)
	type = item['type']
	if type == 'folder':
		print "its a folder with name : ",item['name']
		print "the folder contents are - \n"
		for each in item["children"]:
			print each['type']
'''
#print testdata1

#print dir(testdata1["children"][0])

#print jsontree.dumps(testdata1, indent=4)

def parser(data, depth, path):
	print "CURRENT PATH = ", path
	for item in data["children"]:	# check for all the item in booknark bar
		type = item['type']
		if type == 'folder':      # if a folder is found do folder job
Esempio n. 17
0
def load_jt(fname):
    with open(fname, 'rb') as f:
        return jsontree.loads(f.read())
Esempio n. 18
0
                    yield d
            elif isinstance(value, list) or isinstance(value, tuple):
                for v in value:
                    for d in dict_generator(v, pre + [key]):
                        yield d
            else:
                yield pre + [key, value]
    else:
        yield indict


print type(json1_data)
#print json.dumps(json1_data, sort_keys=True, indent=4, separators=(',', ': '))


#for i in dict_generator(json1_data):
#    print i

dib_tree = jsontree.loads(json1_str)
for i in dib_tree['temperature_sensors']:
    print "id={0}".format(i.id)
    for s in i.play:
        print "t={0}".format(s.temperature)
        for f in s.funcs:
            # print "func.name={0}".format(f.name)
            f_name = "{0}".format(f.name)
            loc_args = []
            for kwa in f.args:
                loc_args.append("{}='{}'".format(kwa, f.args[kwa].encode('utf-8')))
            print "  {}({})".format(f_name, ','.join(loc_args))
Esempio n. 19
0
 def __init__(self, url, alias=None):
     self.r = requests.get(url)
     self.plainjson = self.r.content
     self.data = jsontree.loads(self.plainjson)
     self.name = alias
Esempio n. 20
0
 def dict_to_json(self, dictionary):
     return jsontree.loads(jsontree.dumps(dictionary))