-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi_data_extraction.py
More file actions
52 lines (46 loc) · 1.98 KB
/
api_data_extraction.py
File metadata and controls
52 lines (46 loc) · 1.98 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
52
"""
Created on Sat Dec 10 12:34:24 2022
@author: Suganthi
"""
# -*- coding: utf-8 -*-
import requests
import pandas as pd
import json
API_DOMAIN="xxxx"
API_BASE_PATH="xxxx"
with requests.Session() as session:
# provide authentication data to session, will be sent automatically
session.auth = ('caddok', '')
identifier_key = list()
# Use the first request, which uses basic authentication,
# to set the language using the cookie
header_response = session.get(API_DOMAIN,
cookies={'contact.language': 'en'})
#If the connection request is successful, perform below operations
if header_response.status_code == 200:
token_response = session.get(f"{API_DOMAIN}/{API_BASE_PATH}")
token = token_response.json()
identifier_key = list()
requirement_df = list()
for item in token["objects"]:
responses=list()
identifier_key.append(item["spec_id"])
#print(item["spec_id"])
print(item['system:relships']['relships']['Requirements'])
data_response=session.get(item['system:relships']
['relships']['Requirements'],
headers={'Accept':
'multipart/form-data'})
data=data_response.json()
data_target=data.get('targets')
for item in data_target:
data_from_api=json.loads(session.get(item).text)
responses.append(data_from_api)
requirement_df.append(pd.DataFrame(responses))
#print(requirement_df[-1].head())
df = pd.concat(requirement_df, keys=identifier_key).reset_index().drop(
['level_1'], axis=1).rename(columns = {'level_0':'SPEC_ID_KEY'})
#print(df.head())
print(df.shape)
df
session.get('http://localhost/server/__quit__')