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)

[((8, 0, 8, 39), 'logging.basicConfig', 'logging.basicConfig', (), '', False, 'import logging\n'), ((14, 0, 15, 42), 'logging.info', 'logging.info', ({(14, 13, 15, 41): "('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))", False, 'import logging\n'), ((10, 61, 11, 45), 'os.getenv', 'os.getenv', ({(11, 20, 11, 36): '"""DAPR_HTTP_PORT"""', (11, 38, 11, 44): '"""3500"""'}, {}), "('DAPR_HTTP_PORT', '3500')", False, 'import os\n'), ((21, 13, 24, 5), 'requests.post', 'requests.post', (), '', False, 'import requests\n'), ((27, 4, 27, 17), 'time.sleep', 'time.sleep', ({(27, 15, 27, 16): '(1)'}, {}), '(1)', False, 'import time\n'), ((10, 11, 10, 52), 'os.getenv', 'os.getenv', ({(10, 21, 10, 31): '"""BASE_URL"""', (10, 33, 10, 51): '"""http://localhost"""'}, {}), "('BASE_URL', 'http://localhost')", False, 'import os\n'), ((25, 38, 25, 55), 'json.dumps', 'json.dumps', ({(25, 49, 25, 54): 'order'}, {}), '(order)', False, 'import json\n')]