<reponame>floriancaro/Putting-It-All-Together
#!/usr/bin/env python3

import os
import requests

source_dir = "supplier-data/descriptions/"
external_ip = "http://172.16.31.10/fruits/"
fruit = {}

def main():
  """Process the description data and upload it as JSON file."""
  for description in os.listdir(source_dir):
    with open(os.path.join(source_dir,description)) as txt:
      content = txt.read().splitlines() 
      fruit["name"] = content[0]
      fruit["weight"] = int(content[1].split()[0])
      fruit["description"] = content[2]
      fruit["image_name"] = os.path.splitext(description)[0] + ".jpeg"

    # post information
    response = requests.post(external_ip, json=fruit)

    # check for HTTP error messages
    response.raise_for_status()

    print(fruit)

if __name__ == "__main__":
  main()

#!/usr/bin/env python3

import os
import requests

source_dir = "supplier-data/descriptions/"
external_ip = "http://172.16.31.10/fruits/"
fruit = {}

def main():
  """Process the description data and upload it as JSON file."""
  for description in os.listdir(source_dir):
    with open(os.path.join(source_dir,description)) as txt:
      content = txt.read().splitlines() 
      fruit["name"] = content[0]
      fruit["weight"] = int(content[1].split()[0])
      fruit["description"] = content[2]
      fruit["image_name"] = os.path.splitext(description)[0] + ".jpeg"

    # post information
    response = requests.post(external_ip, json=fruit)

    # check for HTTP error messages
    response.raise_for_status()

    print(fruit)

if __name__ == "__main__":
  main()
#!/usr/bin/env python3 Process the description data and upload it as JSON file. # post information # check for HTTP error messages