-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathargument-parser-argparser.py
More file actions
51 lines (47 loc) · 1.44 KB
/
argument-parser-argparser.py
File metadata and controls
51 lines (47 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import requests
import sys
import argparse
import json
parser = argparse.ArgumentParser()
# parser.add_argument('arguments', nargs="+", help="Give the arguments")
parser.add_argument('arguments', nargs="*", help="Give the arguments")
parser.add_argument("--category", "--category", help="Give the category")
parser.add_argument("--filetype", "--filetype", help="Give the file name with type")
args = parser.parse_args()
URL = "http://tomcat01.production2.telyportal.com:9080/"
fileList = []
if args.arguments:
if args.arguments[0] == "list":
reqType = "GET"
URL = URL + "dataset"
if args.category:
URL = URL + "?category=" + args.category
elif args.arguments[0] == "search":
reqType = "GET"
URL = URL + "dataset/?q=" + args.arguments[1].replace(' ','+')
elif args.arguments[0] == "add":
reqType = "POST"
URL = URL + "filetype/"
if args.filetype:
fileList.append(args.filetype)
elif len(args.arguments) > 1:
fileList = args.arguments[1:]
else:
print("Please provide filetype")
exit()
else:
print ("Please provide right command")
exit()
else:
print ("No command provided")
exit()
if reqType == "GET":
response = requests.get(url = URL).json()
print(response)
elif reqType == "POST":
for file in fileList:
f = open(file, 'r')
data = f.read()
f.close()
response = requests.post(url = URL, data = data, headers = {"Content-Type": "application/json"})
print(response.status_code, response.reason, response.json())