No title Revision 663737326139 (Tue Jun 07 2011 at 16:45) - Diff Link to this snippet: https://friendpaste.com/4IyqA2qaONYkpyUQDKLHxR Embed: manni perldoc borland colorful default murphy trac fruity autumn bw emacs pastie friendly Show line numbers Wrap lines 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364import _midgard as midgard# Set up the repository configconfiguration = midgard.config()configuration.dbtype = 'SQLite'configuration.database = 'midgardexample'# this will store to SQLite in ~/.midgard2/data/midgardexample.db# Open a Midgard repository connectionconnection = midgard.connection()connection.open_config(configuration)import urllib, urllib2import simplejson as jsonclass QaikuUser(): user = None def __init__(self, username): try: self.user = midgard.db.user({'login': username, 'authtype': 'APIkey'}) except: self.user = midgard.db.user() self.user.login = username self.user.authtype = 'APIkey' self.user.active = True self.user.create() if (self.user.password is None): self.ask_password() self.user.log_in() def ask_password(self): password = raw_input('Please type your Qaiku API key: ') if (self.check_password(password) is False): self.ask_password() self.user.password = password self.user.update() def check_password(self, password): opener = urllib2.build_opener() opener.addheaders = [('User-agent', 'adventure_tablet/0.1')] try: params = urllib.urlencode({'apikey': password}) url = 'http://www.qaiku.com/api/statuses/user_timeline.json?%s' % params req = opener.open(url) except urllib2.HTTPError, e: print('Sorry, authorization failed.') return False except urllib2.URLError, e: print("Connection failed, error %s. Try again later" % (e.message)) return False return True # Match OS user to Midgard userimport getpassusername = getpass.getuser() user = QaikuUser(username)print "Can has Qaiku"