-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproject.py
53 lines (43 loc) · 1.22 KB
/
project.py
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
52
53
#!/usr/bin/python
import json
import sys
try:
import requests
except ImportError:
print "Please install the python-requests module."
sys.exit(-1)
AT_API = 'https://at.example.net/api/v2/'
USERNAME = "admin"
PASSWORD = "redhat"
SSL_VERIFY = False # Ignore SSL for now
def get_json(url):
# Performs a GET using the passed URL location
r = requests.get(url, auth=(USERNAME, PASSWORD), verify=SSL_VERIFY)
return r.json()
def get_results(url):
jsn = get_json(url)
if jsn.get('error'):
print "Error: " + jsn['error']['message']
else:
if jsn.get('results'):
return jsn['results']
elif 'results' not in jsn:
return jsn
else:
print "No results found"
return None
def display_all_results(url):
results = get_results(url)
if results:
print json.dumps(results, indent=4, sort_keys=True)
def grab_project_names(url):
project_name = []
j = get_json(url)
for proj in j['results']:
project_name.append(proj['name'])
print project_name
def main():
#display_all_results('https://at.example.net/api/v2/projects/')
grab_project_names(AT_API + 'projects/')
if __name__ == "__main__":
main()