import requests


def send_to_slack(msg_color, msg_text, field, slack_id, image_id, dry_run=False):
    """Send a post to Slack using Slack webhooks

    Args:
        msg_color (str): any of 'good','warning', 'danger' or a HEX color
        msg_text (str): text of choice to accompany the post
        field (str): name of the field shown in the image posted
        slack_id (str): poster's Slack ID e.g. 'UH0H2QFC2'
        image_id (str): id of chosen image from Google Drive upload
        dry_run (bool): just generate the command, don't execute it

    Returns:
        str: the system command that's used to send this to slack (can be ignored)

    Examples:
        >>> send_to_slack('#3A143E', 'Test', 'Test', 'UH0H2QFC2', '1qWyC6xAHODREDfoZLH4qTYTDwt5m3EEk', dry_run=True)
        {'attachments': [{'color': '#3A143E', 'author_name': '<@UH0H2QFC2>', 'title': 'SkyviewBot Image Post: Test',\
 'text': 'Test', 'image_url': 'http://drive.google.com/uc?export=download&id=1qWyC6xAHODREDfoZLH4qTYTDwt5m3EEk'}]}
    """

    # Replace characters in message text
    msg_text = msg_text.replace("'", "")

    # Construct the full message
    full_msg = {
        "attachments": [
            {
                "color": msg_color,
                "author_name": "<@{}>".format(slack_id),
                "title": "SkyviewBot Image Post: {}".format(field),
                "text": msg_text,
                "image_url": "http://drive.google.com/uc?export=download&id={}".format(image_id)
            }
        ]
    }

    if not dry_run:
        requests.post("https://hooks.slack.com/services/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", json=full_msg)

    return full_msg