MCPcopy Create free account
hub / github.com/decodableco/examples / make_json

Function make_json

masking/loader.py:11–36  ·  view source on GitHub ↗
(csv_file, token, ep)

Source from the content-addressed store, hash-verified

9# Function to convert a CSV to JSON
10# Takes the file paths as arguments
11def make_json(csv_file, token, ep):
12
13 # Open a csv reader called DictReader
14 with open(csv_file, encoding='utf-8') as csvf:
15 csvReader = csv.DictReader(csvf)
16
17 # Convert each row into a dictionary
18 # and add it to data
19 for row in csvReader:
20 message = json.dumps({
21 "events": [ row ]
22 })
23
24 print(message)
25
26 headers = {
27 "Accept": "application/json",
28 "Content-Type": "application/json",
29 "Authorization": "Bearer {0}".format(token)
30 }
31
32 url = "https://{0}.api.decodable.co{1}".format(os.getenv("ACCOUNT"), ep)
33
34 response = requests.post(url, headers=headers, data=message)
35
36 print(response.text)
37
38if __name__ == "__main__":
39

Callers 1

loader.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected