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 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 editContact(words): conts = pdata.getLocal("Contacts") user = words[0] cat = words[1] add = words[2] newID = getID(user)[0] user = conts[newID] if newID else conts["0"] user[cat] = panalyze.cleanString(add) if cat in user.keys() else user[cat] conts[newID] = user pdata.updateContacts(conts)
def getNumber(search): conts = pdata.getLocal("Contacts") if search not in conts.keys(): ids = getID(search) final = [] for item in ids: final.append(str("+" + conts[item]["Mobile"])) return final else: #Received input ID, returning matching number return str("+" + conts[search]["Mobile"])
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 checkCal(*args): local = pdata.getLocal("Calendar") if len(local) > 0: for key in sorted(local): later = ptime.compare(key) if later: cur = local[key] print key if isinstance(cur, list): for item in cur: print item else: print cur else: print "Empty calendar"
def getID(search): search = panalyze.cleanString(search[0]) if isinstance( search, list) else panalyze.cleanString(search) conts = pdata.getLocal("Contacts") final = [] for key in conts.keys(): cur = conts[key] for k1 in cur.keys(): c1 = cur[k1].lower() if isinstance(cur[k1], (str, unicode)) else cur[k1] #print "C1: ", c1 if search in c1: #print "Found match" final.append(key) break return final
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 checkConfig(self, **kwargs): #Implement multi-level searching if "data" in kwargs: print kwargs["key"], ": ", kwargs["data"] else: bod = pdata.getLocal("Config") #print "Bod: ", bod print "Config: ", bod.keys() select = "" print "Would you like to lookup further?" select = raw_input() if select.lower() != "no": try: temp = bod[select] kwargs = {"data": temp, "key": select} checkConfig(self, **kwargs) except KeyError as e: print "Key not found =["
def dailyEvents(): print "Hmm.. Let's see if we're doing anything today.." cal = pdata.getLocal("Calendar") today = ptime.today() #print ptime.time() show = 1 if today in cal.keys(): print "You have an event today! Would you like to see it?" show = raw_input().lower() if show == "yes": temp = cal[today] for event in temp: for item in ["Name", "Start", "Notes"]: print item, ":", event[item] else: show = 0 else: print "No events today! You're free to do whatever you'd like!" show = 0 return show
def addContact(add): print "Add: ", add new = schema.newContact() count = 0 while count < len(add): if add[count] in new.keys(): if add[count] == "Relation": t1 = panalyze.cleanString(add[count + 1]).lower() for t2 in t1.split(): new[add[count]].append(t2) else: new[add[count]] = panalyze.cleanString(add[count + 1]) count = count + 1 count = count + 1 conts = pdata.getLocal("Contacts") temp = getID(new["Name"].lower()) if len(temp) == 0: print "Adding new contact!" conts[str(len(conts) - 1)] = new pdata.updateContacts(conts) return 1 else: print "Contact already present. Please call editContact to edit the contact" return 0
def listContacts(*args): conts = pdata.getLocal("Contacts") #print "Args:", args if len(conts) == 0: print "No contacts... loser." else: search = [] for item in [e for e in args if e]: if isinstance(item, str): search.append(item) elif isinstance(item, list): search = search + item if search: ids = [] for criteria in search: ids = ids + getID(search) for item in sorted(ids): print "User ID: ", item default = ["Name", "Mobile", "Email", "Relation"] for t1 in default: print t1, ":", conts[item][t1] if len(conts[item].keys()) > 4: #print "Extras!" extras = [ e for e in conts[item].keys() if e not in default ] for t2 in extras: print t2, ":", conts[item][t2] else: count = 1 while count < len( conts.keys()) - 1: #-1 because of Contact -1: Twilio Bot print "ID : ", count for default in ["Name", "Mobile", "Email", "Relation"]: print conts[str(count)][default] count = count + 1
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
def getConfig(name): bod = pdata.getLocal("Config") return bod[name] if name in bod.keys() else bod