Skip to content

Commit

Permalink
Latest Python standards, refactoring. More room for annotation. (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
Montana authored Sep 21, 2023
1 parent fc21a6d commit 9c356a8
Showing 1 changed file with 16 additions and 19 deletions.
35 changes: 16 additions & 19 deletions scenarios/industrial/inputProcessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@

if __name__ == "__main__":
parser = argparse.ArgumentParser(
description='Processes the given inputs as part of a test scenario.')
parser.add_argument('-i', '--inputdir',
help="The input directory.", required=True)
description="Processes the given inputs as part of a test scenario."
)
parser.add_argument("-i", "--inputdir", help="The input directory.", required=True)

args = parser.parse_args()

inputMap = None

with open(os.path.join(args.inputdir, "map.json"), 'r') as f:
with open(os.path.join(args.inputdir, "map.json"), "r") as f:
inputMap = json.load(f)

apiRoot = "http://localhost:8080/v1"
Expand All @@ -25,18 +25,15 @@
responseMap = {}

for file in inputMap.keys():
print(f"Uploading artifact \"{file}\" to {artifactUrl}.")
print(f'Uploading artifact "{file}" to {artifactUrl}.')

session = requests.session()
with open(os.path.join(args.inputdir, file), 'rb') as f:
form = encoder.MultipartEncoder({
"upfile": (file, f, "application/octet-stream"),
"friendlyname": file
})
headers = {"Prefer": "respond-async",
"Content-Type": form.content_type}
response = session.post(
artifactUrl, headers=headers, data=form.to_string())
with open(os.path.join(args.inputdir, file), "rb") as f:
form = encoder.MultipartEncoder(
{"upfile": (file, f, "application/octet-stream"), "friendlyname": file}
)
headers = {"Prefer": "respond-async", "Content-Type": form.content_type}
response = session.post(artifactUrl, headers=headers, data=form.to_string())

data = json.loads(response.text)["result"]
if data is None:
Expand All @@ -54,11 +51,11 @@
print(f"{sourceName}: {responseMap[relation]}")
targetName = responseMap[relation]["result"]["IPFSName"]
print(
f"Submitting relationship between \"{file}\" (\"{sourceName}\") and \"{relation}\" (\"{targetName}\") to {relationshipUrl}.")
f'Submitting relationship between "{file}" ("{sourceName}") and "{relation}" ("{targetName}") to {relationshipUrl}.'
)

response = requests.post(relationshipUrl, json={
"nodeida": sourceName,
"nodeidb": targetName
})
response = requests.post(
relationshipUrl, json={"nodeida": sourceName, "nodeidb": targetName}
)

print(f"Code: {response.status_code} - {response.text}")

0 comments on commit 9c356a8

Please sign in to comment.