def reminderHandler(data): if "add" in data: data = data.replace("add", "", 1) skip, time = parseDate(data) if skip: addReminder(name=" ".join(data.split()[skip:]), time=time, hidden=False, uuid=uuid4().hex) elif "remove" in data: data = data.replace("remove", "", 1) skip, number = parseNumber(data) if skip: index = number - 1 if index >= 0 and index < len(reminderList['items']): removeReminder(reminderList['items'][index]['uuid']) elif "print" in data or "list" in data: count = 0 for index, e in enumerate(reminderList['items']): if not e['hidden']: print("<{0}> {2}: {1}".format(index + 1, e['time'], e['name'])) count += 1 if count == 0: print( "Reminder list is empty, add a new entry with 'remind add <time>'" ) elif "clear" in data: reminderList['items'] = [] writeFile("reminderlist.txt", reminderList)
def downloadFile(filename): print "Downloading File" global commSock rxpSend("get") gotRequest = rxpRecv() rxpSend(filename) packetExists = rxpRecv() if (packetExists == "bad"): print "Error Retrieving File!" sendBad() return sendGood() numPacks = int(rxpRecv()) sendGood() out = "" i = 0 while i < numPacks: c = rxpRecv() sendGood() out += str(c) i += 1 #print out fileHandler.writeFile("clientFiles/"+filename, out) print "File Successfully Downloaded!" return out
def addReminder(name, time, uuid, body='', urgency=Notify.Urgency.LOW, hidden=True): """ Queue reminder. Show notification at the specified time. With the given name as title and an optional body for further information. The mandatory is used to identify the reminder and remove it with removeReminder(). If the reminder should show up in the list printed by 'remind print' hidden (default: True) should be set to false. In this case the reminder is requeued at startup. If reminders are used e.g. with a todo list for due dates, hidden should probably be set to true so that the list is not cluttered with automatically created data. If the reminder needs a different priority, it can be set with urgency to critical (=2), high (=1) or normal (=0, default). """ waitTime = time - dt.now() n = Notify.Notification.new(name, body) n.set_urgency(urgency) timerList[uuid] = Timer(waitTime.total_seconds(), showAlarm, [n, name]) timerList[uuid].start() newItem = {'name': name, 'time': time, 'hidden': hidden, 'uuid': uuid} reminderList['items'].append(newItem) reminderList['items'] = sort(reminderList['items']) writeFile("reminderlist.txt", reminderList)
def handlerPriority(data): words = data.split() names = ["normal", "high", "critical"] score = 100 index = 0 indexList = list() for i, key in enumerate(names): newScore, newList = scoreSentence(data, key) if newScore < score: score = newScore index = i indexList = newList if score < 1: words.pop(indexList[0]) priority = index * 50 elif len(words) > 2: skip, priority = parseNumber(" ".join(words[1:])) else: priority = 0 try: index = getItem(words[0], todoList) except ValueError: error("The Index must be composed of numbers. Subitems are separated by a dot.") return except IndexError: error("The Index for this item is out of range.") return item = todoList for i in index: item = item['items'][i] item['priority'] = priority writeFile("todolist.txt", todoList)
def main(): # get contents of input file fileContent = fileHandler.parseFile(filePath) for lst in fileContent: stoogeSort(lst, 0, len(lst) - 1) # write sorted data to output file fileHandler.writeFile(savePath, fileContent) cleanup.pyc()
def removeReminder(uuid): """ Remove and cancel previously added reminder identified by the given uuid. """ if uuid in timerList: timerList[uuid].cancel() timerList.pop(uuid) for index, e in enumerate(reminderList['items']): if uuid == e['uuid']: reminderList['items'].remove(reminderList['items'][index]) break writeFile("reminderlist.txt", reminderList)
def handlerRemove(data): try: index = getItem(data.split()[0], todoList) deleteIndex = index.pop() except ValueError: error("The Index must be composed of numbers. Subitems are separated by a dot.") return except IndexError: error("The Index for this item is out of range.") return item = todoList for i in index: item = item['items'][i] item['items'].remove(item['items'][deleteIndex]) writeFile("todolist.txt", todoList)
def handlerAddComment(data): words = data.split() try: index = getItem(words[0], todoList) except ValueError: error("The Index must be composed of numbers. Subitems are separated by a dot.") return except IndexError: error("The Index for this item is out of range.") return item = todoList for i in index: item = item['items'][i] item['comment'] = " ".join(words[1:]) writeFile("todolist.txt", todoList)
def putFileHere(): global commSock sendGood() filename = rxpRecv() sendGood() numPacks = int(rxpRecv()) sendGood() out = "" i = 0 while i < numPacks: c = rxpRecv() sendGood() out += str(c) i += 1 fileHandler.writeFile("serverFiles/"+filename, out)
def handlerAdd(data): try: index = getItem(data.split()[0], todoList) item = todoList for i in index: item = item['items'][i] data = " ".join(data.split()[1:]) except ValueError: item = todoList except IndexError: error("The Index for this item is out of range.") return newItem = {'complete':0, 'uuid':uuid4().hex, 'comment':""} parts = data.split(" - ") newItem['name'] = parts[0] if " - " in data: newItem['comment'] = parts[1] if not 'items' in item: item['items'] = [] item['items'].append(newItem) writeFile("todolist.txt", todoList)
def handlerComplete(data): words = data.split() try: index = getItem(words[0], todoList) except ValueError: error("The Index must be composed of numbers. Subitems are separated by a dot.") return except IndexError: error("The Index for this item is out of range.") return item = todoList for i in index: item = item['items'][i] complete = 100 if len(words) > 1: try: complete = min(max(0, int(words[1])), 100) except ValueError: error("The completion level must be an integer between 0 and 100.") return item['complete'] = complete writeFile("todolist.txt", todoList)
def handlerAddDue(data): words = data.split() try: index = getItem(words[0], todoList) except ValueError: error("The Index must be composed of numbers. Subitems are separated by a dot.") return except IndexError: error("The Index for this item is out of range.") return item = todoList for i in index: item = item['items'][i] removeReminder(item['uuid']) skip, item['due'] = parseDate(" ".join(words[1:])) urgency = 0 if 'priority' in item: if item['priority'] >= 100: urgency = 2 elif item['priority'] >= 50: urgency = 1 addReminder(name=item['name'], body=item['comment'], uuid=item['uuid'], time=item['due'], urgency=urgency) writeFile("todolist.txt", todoList)
def handlerClear(data): reminderList['items'] = [k for k in reminderList['items'] if k['hidden']] writeFile("reminderlist.txt", reminderList)