# -*- coding: utf-8 -*-
"""
Created on Mon Oct 21 08:47:08 2019

@author: dordoloy
"""

import os
import pika
import config
import getpass


def publish_fanout():
    
    amqp_url=config.amqp_url
    
    # Parse CLODUAMQP_URL (fallback to localhost)
    url = os.environ.get('CLOUDAMQP_URL',amqp_url)
    params = pika.URLParameters(url)
    params.socket_timeout = 5
    
    connection = pika.BlockingConnection(params) # Connect to CloudAMQP
    
    properties = pika.BasicProperties()
    
    channel = connection.channel()
    channel.exchange_declare(exchange='posts',
                             exchange_type='fanout')
    channel.basic_publish(exchange='posts',
                          routing_key='',
                          body='message')
    print("send")

publish_fanout()
[((19, 10, 19, 50), 'os.environ.get', 'os.environ.get', ({(19, 25, 19, 40): '"""CLOUDAMQP_URL"""', (19, 41, 19, 49): 'amqp_url'}, {}), "('CLOUDAMQP_URL', amqp_url)", False, 'import os\n'), ((20, 13, 20, 36), 'pika.URLParameters', 'pika.URLParameters', ({(20, 32, 20, 35): 'url'}, {}), '(url)', False, 'import pika\n'), ((23, 17, 23, 48), 'pika.BlockingConnection', 'pika.BlockingConnection', ({(23, 41, 23, 47): 'params'}, {}), '(params)', False, 'import pika\n'), ((25, 17, 25, 39), 'pika.BasicProperties', 'pika.BasicProperties', ({}, {}), '()', False, 'import pika\n')]