class Fetcher: def __init__(self): openid = input('Your OpenID (like http://example.myid.net/) : ') print('''Go to following URL and get the user key: https://api.openmaru.com/delegate_key/springnote?app_id=71fcb7c8''' '&openid={}'.format(openid)) key = input('Key: ') print('Connecting...') self.api = Springnote(openid, key) SAVE_PATH = '_api' def fetch(self, path): assert '..' not in path cache_path = os.path.normpath(self.SAVE_PATH + path) if os.access(cache_path, os.F_OK): return open(cache_path, 'rb').read() makedirs(os.path.split(cache_path)[0], exist_ok=True) try: data = self.api._fetch('GET', path) except SpringnoteException as ex: if ex.status in [404]: return None raise open(cache_path, 'wb+').write(data) return data
def __init__(self): openid = input('Your OpenID (like http://example.myid.net/) : ') print('''Go to following URL and get the user key: https://api.openmaru.com/delegate_key/springnote?app_id=71fcb7c8''' '&openid={}'.format(openid)) key = input('Key: ') print('Connecting...') self.api = Springnote(openid, key)
class Fetcher: def __init__(self): openid = input("Your OpenID (e.g. http://example.myid.net/) : ") print("""다음 주소로 가서 API 키를 받으십시오. Go to following URL and get the user key: https://api.openmaru.com/delegate_key/springnote?app_id=71fcb7c8""" '&openid={}'.format(openid)) key = input("Key: ") print("질문 하나만 더 받으면 됩니다. 접속될 때까지 채널 고정!") print("Connecting. Please wait...") self.api = Springnote(openid, key) print("Getting information...") pages = json.loads( self.api._fetch('GET', '/pages.json').decode('ascii')) self.subdomain = re.search(r'(\w+).springnote.com', pages[0]['page']['uri']).group(1) def fetch(self, path, force=False): assert '..' not in path cache_path, _, _ = path.partition('?') cache_path = os.path.normpath( os.path.join(SAVE_PATH, self.subdomain) + cache_path) if '?' in path: path += '&domain={}'.format(self.subdomain) else: path += '?domain={}'.format(self.subdomain) if not force and os.access(cache_path, os.F_OK): return open(cache_path, 'rb').read() makedirs(os.path.split(cache_path)[0], exist_ok=True) try: data = self.api._fetch('GET', path) except SpringnoteException as ex: if ex.status in [403, 404]: return None raise open(cache_path, 'wb+').write(data) return data def fetch_data(self, path, force=False): return json.loads(self.fetch(path, force=force).decode('ascii'))
def main(): # parse options args = parse(sys.argv[1:]) access_token, method, page_id, resource, resource_id, verbose, argv = args print method, 'page', page_id or '', resource or '', resource_id or '' sn = Springnote() ## Authorize if access_token: # use given access token sn.set_access_token(*access_token) else: # go through authorization process sn = auth(sn, verbose) access_token = sn.access_token access_token_option = '--access-token %s:%s' % (access_token.key, access_token.secret) print 'your access token is ', (access_token.key, access_token.secret) print 'you can save it somewhere else and reuse it later like this:' print ' ', sys.argv[0], access_token_option, method, 'page', page_id or '', resource or '', resource_id or '' print if resource is None: handle_page_resource(sn, method, page_id, verbose, argv) elif resource == 'attachments': handle_attachment_resource(sn, method, page_id, verbose, resource_id, argv) # the rest.. in simple springnote_request style else: if resource_id: path = '/pages/%d/%s/%d.json' % (page_id, resource, resource_id) else: path = '/pages/%d/%s.json' % (page_id, resource) url = 'http://api.springnote.com/' + path.lstrip('/') print method, url # response http_response = sn.springnote_request(method, url, verbose=verbose) pprint.pprint(http_response.read()) print http_response.status print
def __init__(self): openid = input("Your OpenID (e.g. http://example.myid.net/) : ") print("""다음 주소로 가서 API 키를 받으십시오. Go to following URL and get the user key: https://api.openmaru.com/delegate_key/springnote?app_id=71fcb7c8""" '&openid={}'.format(openid)) key = input("Key: ") print("질문 하나만 더 받으면 됩니다. 접속될 때까지 채널 고정!") print("Connecting. Please wait...") self.api = Springnote(openid, key) print("Getting information...") pages = json.loads( self.api._fetch('GET', '/pages.json').decode('ascii')) self.subdomain = re.search(r'(\w+).springnote.com', pages[0]['page']['uri']).group(1)