def newLog(user, args): now = ptime.now() val = schema.newLog(user, args, now) old = pdata.getLocal("Log") oldKey = old.keys()[0][0:10] if len(old.keys()) > 0 else now[0:10] old[now] = val pdata.updateLocal("Log", old)
def updateConfig(name, add): bod = pdata.getLocal("Config") if name in bod.keys(): bod[name] = add pdata.updateLocal("Config", bod) else: print name, "not found in configs"
def recordDay(log): print "Recording yesterday's log and resetting daily log" out = str( os.path.dirname(os.path.abspath(__file__)) + "/dlogs/" + ptime.yesterday() + ".txt") with open(out, 'w') as f: f.write(json.dumps(log, sort_keys=False, indent=2)) pdata.updateLocal("Log", schema.blankDict())
def editCL(words): user = panalyze.cleanString(words[0].lower()) cat = panalyze.cleanString( words[1]) if len(words) > 1 else panalyze.cleanString("String") adds = [] print "User: "******"cat:", cat for add in words[2::]: adds.append(panalyze.cleanString(add)) conts = pdata.getLocal("Contacts") for found in getID(user): cur = conts[found] print "Found match! Adding into ", cur["Name"] cur[cat] = cur[cat] + list(set(adds) - set(cur[cat])) pdata.updateLocal("Contacts", conts)
def removeCL(words): user = panalyze.cleanString(words[0].lower()) cat = panalyze.cleanString( words[1]) if len(words) > 1 else panalyze.cleanString("String") removes = [] for remove in words[2::]: removes.append(panalyze.cleanString(remove)) conts = pdata.getLocal("Contacts") for found in getID(user): cur = conts[found] for rem in removes: try: updated = cur[cat].remove(rem) print "Removed", cat except: print cat, "not present" pdata.updateLocal("Contacts", conts)
def addEntry(entries): print "Making new dict with: ", entries count = 0 final = schema.newDB() divs = pconfig.getConfig("dividers") while count < len(entries): cur = checkString(entries[count]) #print "AddEntry cur: ", cur if "::" in cur: cur = cleanString(cur) #Uses the closing position to determine full multi dict in entries closed = closeDict(entries, count) mdict = entries[count + 1:closed] #print "Closed dict: ", mdict, " Closed: ", closed ret = dictify(mdict) #print "Return: ", ret final[cur] = ret count = closed elif cur[-1] == ":": cur = cleanString(cur) if count + 1 < len(entries): #print "Single dict: ", cur, " Next: ", entries[count+1] final[cur] = {"Misc": [checkString(entries[count + 1])]} count = count + 1 else: print "Empty dict: ", cur final[cur] = pdata.newDB() else: misc = final["Misc"] misc.append(cur) final["Misc"] = misc count = count + 1 final = pdata.redAdd(pdata.getLocal("DB"), final) #print "AddEntry Final: ", final pdata.updateLocal("DB", final) return entries
for lib in pmods: globals()[lib] = __import__(lib) com = inspect.getmembers(globals()[lib], predicate=inspect.isfunction) """ globals().update(importlib.import_module(lib).__dict__) module = importlib.import_module(lib) globals().update( {n: getattr(module, n) for n in module.__all__} if hasattr(module, '__all__') else {k: v for (k, v) in module.__dict__.items() if not k.startswith('_') }) com = inspect.getmembers(lib, predicate=inspect.isfunction) print "Mod: ", lib print "Com: ", com """ #Adding functions to config and setting functions values in globals for c in com: #print "Appending to functions: ", str(mod+"."+c[0]) functions.append(str(lib + "." + c[0])) #fcalls.append({c[0]:mod.c[0]}) #print c[0] globals()[c[0]] = c[0] #diff = [x for x in loaded["functions"] if x not in functions] diff = set(loaded["functions"]).symmetric_difference(set(functions)) #print ("Editing functions: ", diff) if len(diff) > 0 else "" loaded["functions"] = functions pdata.updateLocal("Config", loaded)