# -*- 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()
[((262, 303), 'os.environ.get', 'os.environ.get', (['"""CLOUDAMQP_URL"""', 'amqp_url'], {}), "('CLOUDAMQP_URL', amqp_url)\n", (276, 303), False, 'import os\n'), ((316, 339), 'pika.URLParameters', 'pika.URLParameters', (['url'], {}), '(url)\n', (334, 339), False, 'import pika\n'), ((392, 423), 'pika.BlockingConnection', 'pika.BlockingConnection', (['params'], {}), '(params)\n', (415, 423), False, 'import pika\n'), ((469, 491), 'pika.BasicProperties', 'pika.BasicProperties', ([], {}), '()\n', (489, 491), False, 'import pika\n')]