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, 'logging.basicConfig', 'logging.basicConfig', False, 'import logging\n'), (14, 'logging.info', 'logging.info', False, 'import logging\n'), (10, 'os.getenv', 'os.getenv', False, 'import os\n'), (21, 'requests.post', 'requests.post', False, 'import requests\n'), (27, 'time.sleep', 'time.sleep', False, 'import time\n'), (10, 'os.getenv', 'os.getenv', False, 'import os\n'), (25, 'json.dumps', 'json.dumps', False, 'import json\n')]