import json
import time
import random
import logging
import requests
import os

logging.basicConfig(level=logging.INFO)

base_url = os.getenv('BASE_URL', 'http://localhost') + ':' + os.getenv(
                    'DAPR_HTTP_PORT', '3500')
PUBSUB_NAME = 'order_pub_sub'
TOPIC = 'orders'
logging.info('Publishing to baseURL: %s, Pubsub Name: %s, Topic: %s' % (
            base_url, PUBSUB_NAME, TOPIC))

for i in range(1, 10):
    order = {'orderId': i}

    # Publish an event/message using Dapr PubSub via HTTP Post
    result = requests.post(
        url='%s/v1.0/publish/%s/%s' % (base_url, PUBSUB_NAME, TOPIC),
        json=order
    )
    logging.info('Published data: ' + json.dumps(order))

    time.sleep(1)

[((80, 119), 'logging.basicConfig', 'logging.basicConfig', ([], {'level': 'logging.INFO'}), '(level=logging.INFO)\n', (99, 119), False, 'import logging\n'), ((286, 393), 'logging.info', 'logging.info', (["('Publishing to baseURL: %s, Pubsub Name: %s, Topic: %s' % (base_url,\n    PUBSUB_NAME, TOPIC))"], {}), "('Publishing to baseURL: %s, Pubsub Name: %s, Topic: %s' % (\n    base_url, PUBSUB_NAME, TOPIC))\n", (298, 393), False, 'import logging\n'), ((182, 217), 'os.getenv', 'os.getenv', (['"""DAPR_HTTP_PORT"""', '"""3500"""'], {}), "('DAPR_HTTP_PORT', '3500')\n", (191, 217), False, 'import os\n'), ((530, 621), 'requests.post', 'requests.post', ([], {'url': "('%s/v1.0/publish/%s/%s' % (base_url, PUBSUB_NAME, TOPIC))", 'json': 'order'}), "(url='%s/v1.0/publish/%s/%s' % (base_url, PUBSUB_NAME, TOPIC),\n    json=order)\n", (543, 621), False, 'import requests\n'), ((702, 715), 'time.sleep', 'time.sleep', (['(1)'], {}), '(1)\n', (712, 715), False, 'import time\n'), ((132, 173), 'os.getenv', 'os.getenv', (['"""BASE_URL"""', '"""http://localhost"""'], {}), "('BASE_URL', 'http://localhost')\n", (141, 173), False, 'import os\n'), ((678, 695), 'json.dumps', 'json.dumps', (['order'], {}), '(order)\n', (688, 695), False, 'import json\n')]