#!/usr/bin/env python # -*- coding: UTF-8 -*- import me2day from xml.dom.minidom import parseString as xml class Expo: def __init__(self, id, api_key): self.id = id me2day.init(id, api_key, 'xml') def get_posts(self): body = xml(me2day.getLatests(self.id).body) for post in body.getElementsByTagName('post'): print post.getElementsByTagName('body')[0].firstChild.nodeValue def write_post(self): body = raw_input("내용을 입력하세요\n") tags = raw_input("태그를 입력하세요\n") icon = raw_input("아이콘 번호를 선택하세요\n") print xml( me2day.createPost(body, tags, icon).body ).getElementsByTagName('body')[0].firstChild.nodeValue def get_friends(self): body = xml(me2day.getFriends(self.id, 'all').body) for person in body.getElementsByTagName('person'): print person.getElementsByTagName('id')[0].firstChild.nodeValue, print ':', print person.getElementsByTagName('nickname')[0].firstChild.nodeValue def usage(self): print '=' * 8 print '1. 최근글 가져오기' print '2. 글 작성' print '3. 친구 보기' print '4. 그만 하기' print '=' * 8 methods = [ 'get_posts', 'write_post', 'get_friends' ] def start(self): while True: self.usage() try: cmd = int(raw_input('>> ')) except ValueError: continue if cmd == 4: break getattr(self, self.methods[cmd - 1])() id = raw_input('me2day id: ').strip() api_key = raw_input('me2day api_key: ').strip() console = Expo(id, api_key) console.start()