* * * * * /bin/bash -l -c 'cd /projects/basecamp && /usr/bin/python task.py >> /projects/basecamp/cron.log 2>&1'
Created
February 1, 2012 01:42
-
-
Save azisaka/1714440 to your computer and use it in GitHub Desktop.
Creates to do lists on Basecamp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
*.pyc | |
client-* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
from ToDoList import Basecamp | |
if __name__ == "__main__": | |
basecamp = Basecamp(username="username", | |
password="password", | |
basecamp_url="basecamp_url", | |
project_id="123456") | |
list1 = basecamp.create_list(name="Daily", | |
description="It's my description") | |
for name in ["Testing", "Works?"]: | |
list1.create_item(name) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
from httplib import HTTPSConnection | |
from base64 import encodestring | |
# notice the 4 soft-spaces indentation two lines separating class or | |
# function definitions, although instance methods uses 1 space | |
class Basecamp: | |
def __init__(self, username, password, basecamp_url, project_id): | |
self.auth = encodestring('%s:%s' % (username, password))[:-1] | |
self.connection = HTTPSConnection(basecamp_url) | |
self.project_id = project_id | |
self.connection.set_debuglevel(1) | |
def post(self, payload, url): | |
self.connection.putrequest("POST", url) | |
self.connection.putheader("Authorization", "Basic %s" % self.auth) | |
# you could use single-quotes when wrapping around double-quotes: | |
self.connection.putheader("Content-type", 'text/xml; charset="UTF-8"') | |
self.connection.putheader("Content-length", "%d" % len(payload)) | |
self.connection.endheaders() | |
self.connection.send(payload) | |
response = self.connection.getresponse() | |
self.connection.close() | |
return response | |
def create_list(self, name, description): | |
_list = List( | |
name=name, | |
description=description, | |
basecamp_instance=self, | |
) | |
_list.create() | |
return _list | |
class List: | |
_template = """ | |
<todo-list> | |
<name>%s</name> | |
<description>%s</description> | |
</todo-list>""".strip() | |
_path = "/projects/%s/todo_lists.xml" | |
# no spaces between parameters and its default args | |
def __init__(self, name, description=None, basecamp_instance=None): | |
self.basecamp_instance = basecamp_instance | |
self.content = (name, description) | |
self.parent_id = self.basecamp_instance.project_id | |
def path(self): | |
return self._path % self.parent_id | |
def payload(self): | |
return self._template % self.content | |
def create(self): | |
response = self.basecamp_instance.post(self.payload(), self.path()) | |
self.id = response.getheader("Location").split('/')[-1] | |
return response | |
def create_item(self, content=""): | |
item = ListItem(parent=self, content=content) | |
item.create() | |
return item | |
class ListItem(List): | |
_template = """ | |
<todo-item> | |
<content>%s</content> | |
</todo-item>""".strip() | |
_path = "/todo_lists/%s/todo_items.xml" | |
# "list" is a python keyword, avoid naming variables after that | |
def __init__(self, parent, content): | |
self.basecamp_instance = parent.basecamp_instance | |
self.content = content | |
self.parent_id = parent.id |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment