#!/usr/bin/python

import json
import sys
import requests
import logging

host = sys.argv[2]
input_file = sys.argv[1]
taxonomy = sys.argv[3]
with open(input_file) as f:
    for line in f:
        topic = json.loads(line)
        topic['taxonomyId'] = taxonomy
        headers = {'Content-Type': 'application/json'}
        url = host + '/taxonomies/' + taxonomy + '/topics'
        post_resp = requests.post(url, data=json.dumps(topic), headers=headers)
        if post_resp.status_code != 201:
            logging.error("[POST_TOPIC] Received non 200 response. Got {}".format(post_resp.status_code))
