1 # Copyright (c) Twisted Matrix Laboratories.
2 # See LICENSE for details.
5 This example demonstrates how to logon to a remote server and post a diary.
8 $ python advogato.py <name> <diary entry file>
12 from getpass import getpass
14 from twisted.web.xmlrpc import Proxy
15 from twisted.internet import reactor
19 def __init__(self, name, password):
21 self.password = password
22 self.proxy = Proxy('http://advogato.org/XMLRPC')
24 def __call__(self, filename):
25 self.data = open(filename).read()
26 d = self.proxy.callRemote('authenticate', self.name, self.password)
27 d.addCallbacks(self.login, self.noLogin)
29 def noLogin(self, reason):
30 print "could not login"
33 def login(self, cookie):
34 d = self.proxy.callRemote('diary.set', cookie, -1, self.data)
35 d.addCallbacks(self.setDiary, self.errorSetDiary)
37 def setDiary(self, response):
40 def errorSetDiary(self, error):
41 print "could not set diary", error
44 diary = AddDiary(sys.argv[1], getpass())