Login

send a simple Campfire chat message from fabric script

Author:
the_man
Posted:
November 23, 2010
Language:
Python
Version:
1.2
Score:
1 (after 1 ratings)

look ma, no api!

a python method for fabric script to send a message to your campfire chat room.

not really a django script but I didn't know where else to put it. I use it to send a deployment messages to campfire when we deploy new revisions. like the comment mentions, put your api key in ~/.fabricrc.

the example api key is garbage so don't waste your time.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
import httplib2

def _send_campfire_message(message):
    """Send message to Campfire using your campfire login"""
    # SETUP: go to http://<your-campfire-subdomain>.campfirenow.com/member/edit
    # put your api key in ~/.fabricrc like:
    # campfire_api_key = abafdc8391ae67ce829accc9198df832f5f821eb13cac9fb
    if env.has_key('campfire_api_key'):
        data = '{"message":{"body":"-- %s --"}}' % message
        conn = httplib2.Http(timeout=3)
        conn.add_credentials(env.campfire_api_key, 'X')
        headers = {'content-type':'application/json'}
        url = "http://<your-campfire-subdomain>-bc.campfirenow.com/room/<your-room-id-number>/speak.json"
        conn.request(url, "POST", data, headers)

More like this

  1. Template tag - list punctuation for a list of items by shapiromatron 10 months, 2 weeks ago
  2. JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 10 months, 3 weeks ago
  3. Serializer factory with Django Rest Framework by julio 1 year, 5 months ago
  4. Image compression before saving the new model / work with JPG, PNG by Schleidens 1 year, 6 months ago
  5. Help text hyperlinks by sa2812 1 year, 7 months ago

Comments

Please login first before commenting.