def addEvent(words): print "Creating new calendar event" new = schema.newCal() key = ptime.today() count = 0 while count < len(words): cur = words[count] if cur in new.keys() and count < len(words) - 1: if isinstance(new[cur], list): new[cur] = new[cur] + [words[count + 1]] else: new[cur] = panalyze.cleanString(words[count + 1]) elif cur.lower() == "date" and count < len(words) - 1: key = words[count + 1].replace(".", "-") count = count + 1 if key == ptime.today(): print "Enter date (ex: 2018.02.14):" key = raw_input().replace(".", "-").split("-") while len(key) != 3: print "Re-enter date: " key = raw_input().split("-") key[1] = "0" + key[1] if len(key[1]) == 1 else key[1] key[2] = "0" + key[2] if len(key[2]) == 1 else key[2] key = "-".join(key) for item in ["Name", "Start"]: if len(new[item]) == 0: print "Event", item, ":" new[item] = panalyze.cleanString(raw_input()) if len(new["Notes"]) == 0: print "Any notes?" note = panalyze.cleanString(raw_input()) if note.lower() != "no": new["Notes"] = new["Notes"] + [note] print "Final new: ", {key: [new]} pdata.dictAdd("Calendar", {key: [new]})
def removeCat(words): if len(words) > 0: db = getLocal(words[0]) cat = panalyze.cleanString( words[1]) if len(words) > 1 else panalyze.cleanString("String") if cat in db["0"].keys(): #print "Removing", cat,"from", db for item in db: db[item].pop(cat) else: print cat, "is not in", words[0] updateLocal("Contacts", db)
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 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 addCat(words): if len(words) > 1: db = getLocal(words[0]) cat = panalyze.cleanString( words[1]) if len(words) > 1 else panalyze.cleanString("String") print "Adding", cat, "to", words[0] if cat not in db["0"].keys(): print "Did you wanna make this a list?" choice = raw_input() choice = [] if choice.lower() == "yes" else "" for key in db.keys(): db[key][cat] = choice updateLocal(words[0], db) #print "New", words[0],":", db else: print cat, "is already present in", words[0] else: print "Args: [branch,newCat]"
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 textMyself(words): account_sid = pdata.getConfig("twilID") auth_token = pdata.getConfig("twilAuth") print "Texting the main body: ", words client = Client(account_sid, auth_token) to = getNumber("myself") self = getNumber("sender") print "To: ", to, " From: ", self message = ''.join(panalyze.cleanString(str(e + " ")) for e in words) for recipient in to: message = client.messages.create(to=recipient, from_=self, body=message) print(message.sid)
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 textGroup(words): if words: account_sid = pdata.getConfig("twilID") auth_token = pdata.getConfig("twilAuth") client = Client(account_sid, auth_token) self = getNumber("sender") message = ''.join( panalyze.cleanString(str(e + " ")) for e in words[1::]) ids = getID(words[0]) print "To: ", ids print "Message: ", message for val in ids: print getNumber(val) message = client.messages.create(to=getNumber(val), from_=self, body=message) print(message.sid)
def getKey(local, search): local = getLocal(local) search = panalyze.cleanString(search) final = [] print "Searching for: ", search for key in local.keys(): cur = local[key] if isinstance(cur, dict): for k1 in cur.keys(): c1 = cur[k1] if search in c1 or search in k1 or search in key: final.append(key) break else: if search in cur or search in key: final.append(key) break return sorted(final)