def __init__(self, username, password=''): # API URL: https://user:[email protected]/v1/posts/all url = "https://%s:%[email protected]/v1/posts/all" % (username, password) h = urllib.urlopen(url) content = h.read() h.close() x = minidom.parseString(content) # sample post: <post href="http://www.pixelbeat.org/cmdline.html" hash="e3ac1d1e4403d077ee7e65f62a55c406" description="Linux Commands - A practical reference" tag="linux tutorial reference" time="2010-11-29T01:07:35Z" extended="" meta="c79362665abb0303d577b6b9aa341599" /> post_list = x.getElementsByTagName('post') for post_index, post in enumerate(post_list): url = post.getAttribute('href') desc = post.getAttribute('description') tags = ",".join([t for t in post.getAttribute('tag').split()]) timestamp = post.getAttribute('time') options = {} options['tags'] = tags options['push'] = False options['msg'] = desc args = [url] g = gitMark(options, args) if post_list.length > 1: print '%d of %d bookmarks imported (%d%%)' % ( post_index + 1, post_list.length, (post_index + 1.0) / post_list.length * 100)
def create(): url = request.forms.get('url', '').strip() tags = request.forms.get('tags', '').strip() message = request.forms.get('message', '').strip() push = request.forms.get('nopush', True) if push == '1': push = False if not url: return template("new", url=url, tags=tags, message=message, error="URL is required.") options = {} options['tags'] = tags options['push'] = push options['msg'] = message args = [url] g = gitMark(options, args) return template("create")
def process_gitmarks_cmd(opts, args): """ processes a gitmarks command opts is list of options. args is 1 or more URL's to process. """ # -- each arg is a URL. for arg in args: g = gitMark(arg, settings.USER_NAME) if 'tags' in opts.keys(): g.addTags(opts['tags']) if 'private' in opts.keys(): g.setPrivacy(opts['private']) # -- get content, and autogen title if canHazWebs(): g.getContent() g.parseTitle() else: logging.error("no netz! overriding push to false!") opts['push'] = False doPush = opts['push'] if 'push' in opts.keys() else 'False' updateRepoWith(g, doPush)
def process_gitmarks_cmd(opts, args): """ processes a gitmarks command opts is list of options. args is 1 or more URL's to process. """ # -- each arg is a URL. for arg in args: g = gitMark(arg,settings.USER_NAME) if 'tags' in opts.keys(): g.addTags(opts['tags']) if 'private' in opts.keys(): g.setPrivacy(opts['private']) # -- get content, and autogen title if canHazWebs(): g.getContent() g.parseTitle() else: logging.error("no netz! overriding push to false!") opts['push'] = False doPush = opts['push'] if 'push' in opts.keys() else 'False' updateRepoWith(g, doPush)
def __init__(self, username, password=''): # API URL: https://user:[email protected]/v1/posts/all url = "https://%s:%[email protected]/v1/posts/all" % (username, password) h = urllib.urlopen(url) content = h.read() h.close() x = minidom.parseString(content) # sample post: <post href="http://www.pixelbeat.org/cmdline.html" hash="e3ac1d1e4403d077ee7e65f62a55c406" description="Linux Commands - A practical reference" tag="linux tutorial reference" time="2010-11-29T01:07:35Z" extended="" meta="c79362665abb0303d577b6b9aa341599" /> post_list = x.getElementsByTagName('post') for post_index, post in enumerate(post_list): url = post.getAttribute('href') desc = post.getAttribute('description') tags = ",".join([t for t in post.getAttribute('tag').split()]) timestamp = post.getAttribute('time') options = {} options['tags'] = tags options['push'] = False options['msg'] = desc # Set the authoring date of the commit based on the imported # timestamp. git reads the GIT_AUTHOR_DATE environment var. os.environ['GIT_AUTHOR_DATE'] = timestamp args = [url] g = gitMark(options, args) # Reset authoring timestamp (abundance of caution) del os.environ['GIT_AUTHOR_DATE'] if post_list.length > 1: print '%d of %d bookmarks imported (%d%%)' % ( post_index + 1, post_list.length, (post_index + 1.0) / post_list.length * 100)
if doCache: logging.warning("Caching data. This may be slow") for post_index, post in enumerate(post_list): try: url = post.getAttribute('href') desc = post.getAttribute('description') timestamp = post.getAttribute('time') raw_tags = post.getAttribute('tag') extended = post.getAttribute('extended') meta = post.getAttribute('meta') # turn a comma separated list of tags into a real list of tags tags = [tag.lstrip().rstrip() for tag in raw_tags.split()] privateString = post.getAttribute('private') g = gitMark(url, 'delicious:'+ str(username)) g.description = desc g.tags = tags g.time = timestamp g.rights = None g.meta = meta g.extended = extended if(privateString == "0" or privateString==""): g.private = False g.parseTitle() newMarksList.append(g) #break here for single test without data resetting/fixing except (KeyboardInterrupt, SystemExit): print >>sys.stderr, ("backup interrupted by KeyboardInterrupt/SystemExit" )