Advertisement
Guest User

Untitled

a guest
Apr 24th, 2019
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. import sys
  2. import requests
  3.  
  4. try:
  5. restmethod = sys.argv[1]
  6. restarg = sys.argv[2]
  7. except:
  8. restmethod = "null"
  9. if restmethod == 'null':
  10. sys.exit("CLI.py <REST URL> <integer/string/key> <if kv-record, value> <if kv-record, identify PUT or POST")
  11. try:
  12. value = sys.argv[3]
  13. putpost = sys.argv[4]
  14. except IndexError:
  15. value = 'null'
  16. method = 'null'
  17.  
  18. if restmethod not in {"md5", "factorial", "fibonacci", "is-prime", "slack-alert", "kv-record", "kv-retrieve"}:
  19. (sys.exit("incorrect rest method/ url path"))
  20.  
  21. rest = "http://0.0.0.0:5000/"+restmethod+"/"+restarg
  22. kv = "http://0.0.0.0:5000/"+restmethod+"/"
  23.  
  24. if restmethod == "kv-record":
  25. data = {restarg:value}
  26. if putpost.lower() == 'post':
  27. resp = requests.post(kv, json=data)
  28. #print resp
  29. elif putpost.lower() == 'put':
  30. resp = requests.put(kv, json=data)
  31. else:
  32. sys.exit("<REST URL> <integer/string/key> <if kv-record, value> <if kv-record, identify PUT or POST")
  33.  
  34. else:
  35. resp = requests.get(rest)
  36.  
  37. print (resp.content)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement