Skip to content

Commit

Permalink
update method implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
josprachi committed Dec 23, 2018
1 parent ccc2f30 commit a8e8b83
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions lpcli.py
Expand Up @@ -22,8 +22,19 @@ def AddNewPaste(pasteName, pasteContent):
print("error")


def UpdateAPaste(pasteId, pasteContent):
print(pasteId, pasteContent)
def UpdateAPaste(pasteId, pasteContent,append):
req = requests.get(url+"api/get/"+pasteId)
details=req.json()


if pasteContent:
if append != True:
contentToUpdate=pasteContent
else:
contentToUpdate=details['Content']+" "+pasteContent
pasteDetails = {'name': details['Name'], 'content': contentToUpdate}
r=requests.put(url+"/api/update/"+pasteId,json=pasteDetails)



def DeleteAPaste(pasteId):
Expand Down Expand Up @@ -51,7 +62,7 @@ def ShowAllPastes():
if __name__ == '__main__':
parser.add_argument("action", nargs='?',
help="\
Action: [get, new, search, createDb, delete, showAll]")
Action: [get, new, search, createDb, delete, showAll,update]")
parser.add_argument("--pasteId", default="1",
help="sets the pasteId for operation", required=False)
parser.add_argument("--port", help="server port", default="8000")
Expand All @@ -62,6 +73,7 @@ def ShowAllPastes():
required=False)
parser.add_argument("--content", help="PasteContent", type=str,
required=False)
parser.add_argument("--append",required=False)

arg = parser.parse_args()

Expand All @@ -84,6 +96,14 @@ def ShowAllPastes():
if arg.pasteId:
DeleteAPaste(arg.pasteId)

elif arg.action == 'update':
print("inside update")
if arg.pasteId!="1":
print("there is some pasteid "+arg.pasteId)
UpdateAPaste(arg.pasteId,arg.content,arg.append)
else:
print("Please provide paste id to update")

if arg.action == 'new':
if arg.name and arg.content:
AddNewPaste(arg.name, arg.content)
Expand Down

0 comments on commit a8e8b83

Please sign in to comment.