def main(): import argparse parser = argparse.ArgumentParser() parser.add_argument('db', help="The ybookmarks.sqlite file in firefox " "profile directory") args = parser.parse_args() conn = sqlite3.connect(args.db) curs = conn.cursor() curs.execute("select rowid, name, url, shared, description, added_date from bookmarks") bookmarks = dict((id, Bookmark(name=name, url=url, add_date=added_date/1000000, private=(shared != "true"), description=description)) for id, name, url, shared, description, added_date in curs) curs.execute("select rowid, name from tags") tags = dict((id, name) for id, name in curs) bookmarks_tags = defaultdict(list) curs.execute("select bookmark_id, tag_id from bookmarks_tags") for bookmark_id, tag_id in curs: bookmarks_tags[bookmark_id].append(tag_id) for bookmark_id, bookmark in bookmarks.items(): bookmark.tags = [tags[tid] for tid in bookmarks_tags[bookmark_id]] api = DeliciousAPI(raw_input("username: "******"password: "******"Posting %s" % bm.name api.posts_add(url=bm.url, description=bm.name, extended=bm.description, tags=','.join(bm.tags), dt=bm.add_date.strftime('%Y-%m-%dT%H:%M:%SZ'), replace=True, shared=not bm.private) time.sleep(1)
def main(): import argparse parser = argparse.ArgumentParser() parser.add_argument('db', help="The ybookmarks.sqlite file in firefox " "profile directory") args = parser.parse_args() conn = sqlite3.connect(args.db) curs = conn.cursor() curs.execute( "select rowid, name, url, shared, description, added_date from bookmarks" ) bookmarks = dict( (id, Bookmark(name=name, url=url, add_date=added_date / 1000000, private=(shared != "true"), description=description)) for id, name, url, shared, description, added_date in curs) curs.execute("select rowid, name from tags") tags = dict((id, name) for id, name in curs) bookmarks_tags = defaultdict(list) curs.execute("select bookmark_id, tag_id from bookmarks_tags") for bookmark_id, tag_id in curs: bookmarks_tags[bookmark_id].append(tag_id) for bookmark_id, bookmark in bookmarks.items(): bookmark.tags = [tags[tid] for tid in bookmarks_tags[bookmark_id]] api = DeliciousAPI(raw_input("username: "******"password: "******"Posting %s" % bm.name api.posts_add(url=bm.url, description=bm.name, extended=bm.description, tags=','.join(bm.tags), dt=bm.add_date.strftime('%Y-%m-%dT%H:%M:%SZ'), replace=True, shared=not bm.private) time.sleep(1)
def cook_select_resource (request, key): """Take the submitted resource and tag it in delicious using the users prerferences ready for the Baking step""" # This is in the framework template return HttpResponse(render_to_string(request, template_name, data), # Process request["url"] # res_url = request.REQUEST["resource_url"] res_url = request.REQUEST.get("resource_url") # res_txt = request.REQUEST["resource_text"] res_txt = request.REQUEST.get("resource_text") if res_txt is None: res_txt = "Untitled resource"; if res_url is None: print "No URL given" else: # a = pydelicious.apiNew('ibbomashup', '**************') a = DeliciousAPI('ibbomashup', '**************') a.tags_get() print "Select the resource "+res_url+" notes text is "+res_txt a.posts_add(res_url, res_txt, tags="test", extended="text"); # a.posts_add("http://my.com/", "title", extended="description", tags="my tags") return HttpResponse("fred.html")
class DeliciousSyncDB: def __init__(self, username, password): """ Initializes the DeliciousSyncDB object. This functions accepts two arguments username and password. Both are required. """ self.api = DeliciousAPI(username, password) def _cleanTags(self, tags): """ Utility function that sets tags to lower case, removes commas and double quotes and removes all duplicate tags. Returns a unicode string. """ tags = tags.lower().replace('\"', '').replace(',', '').split(' ') tags = set(tags) tags = ' '.join(tags) return u'%s' % tags def _syncPost(self, post): """ Utility function that saves bookmarks to the local database. In the case a bookmark already exists it will be updated instead. """ time_obj = time.strptime(post['time'], "%Y-%m-%dT%H:%M:%SZ") save_date = datetime.datetime(*time_obj[0:7]) try: shared = post['shared'] except KeyError: shared = True finally: if shared == 'no': shared = False tags = self._cleanTags(post['tag']) d = { 'title': post['description'], 'url': post['href'], 'tags': tags, 'notes': post['extended'], 'post_hash': post['hash'], 'post_meta': post['meta'], 'save_date': save_date, 'shared': shared } b, created = Bookmark.objects.get_or_create(url = d['url'], defaults = d) if created == False: if not b.post_meta == unicode(d['post_meta']): b = Bookmark( id=b.id, title=d['title'], url=d['url'], tags=d['tags'], notes=d['notes'], post_hash=d['post_hash'], post_meta=d['post_meta'], save_date=d['save_date'], shared=d['shared'] ) b.save(syncAPI=True) def syncRecent(self, results=15): """ Syncronizes recent Delicious boomarks to a local database. This uses the posts/all api call instead of using the posts/recent call. Doing so provides the meta attribute in order to update previously saved bookmarks with modified data from Delicious. syncRecent takes one argument for results. If not specified the default number of results returned is 15. """ posts = self.api.posts_all(results = str(results)) for post in posts['posts']: self._syncPost(post) def syncAll(self): """ Syncronizes all Delicious boomarks to a local database. Using the meta attribute previously saved bookmarks will also be updated as well. """ posts = self.api.posts_all() for post in posts['posts']: self._syncPost(post) def processQueue(self): """ Queue processor to process local bookmarks that are going to be pushed to Delicious using posts/add. Bookmarks saved locally are flagged as queued and unflagged as they have been processed. If a boomark is unsucessfully updated the program will fail silently and move on to the next one until the entire queue has been processed once through. """ bookmarks = Bookmark.objects.filter(queued=True) for bookmark in bookmarks: time.sleep(1.5) try: if bookmark.shared == False: shared = 'no' else: shared = 'yes' self.api.posts_add( bookmark.url, bookmark.title, extended=bookmark.notes, tags=bookmark.tags, shared=shared, replace='yes') bookmark.queued = False bookmark.save(syncAPI=True) except: pass
if (len(u) > 0 and len(u[0].childNodes) > 0): url = u[0].childNodes[0].data.encode('ascii','replace') da = node.getElementsByTagName("pubDate") if (len(da) > 0 and len(da[0].childNodes) > 0): date = da[0].childNodes[0].data.encode('ascii','replace') ddate = time.strftime("%Y-%m-%dT%H:%M:%SZ",time.strptime(date,"%a, %d %b %Y %H:%M:%S %Z")) d = node.getElementsByTagName("description") if (len(d) > 0 and len(d[0].childNodes) > 0): desc = d[0].childNodes[0].data.encode('ascii','replace') labelNodes = node.getElementsByTagName("smh:bkmk_label") for l in labelNodes: if (len(l.childNodes) > 0): labels.append(l.childNodes[0].data.encode('ascii','replace')) for tag in labels: tag_string += tag.replace(" ","_") + " " print ddate + " " + title + ":" + url + ":" + desc + ":'" + tag_string + "'" try: delish.posts_add(url, title, extended=desc, tags=tag_string, dt=ddate, replace=True) except PyDeliciousUnauthorized: print "Authorization to Delicious failed" exit(0) except PyDeliciousThrottled: print "Being throttled by delicious, waiting 2 seconds" sleep(2) try: delish.posts_add(url, title, extended=desc, tags=tag_string, dt=ddate, replace=True) except PyDeliciousThrottled: print "Still throttled, quitting." exit(0) sleep(1) #delicious doesn't want to be flooded with requests. Fair enough
def post_to_Delicious(art_data): a = DeliciousAPI(config.DELICIOUS_USER,config.DELICIOUS_PWD) arturl = config.BASE_URL % art_data['bibcode'].strip() entry_tags = ",".join(art_data['keywords']) a.posts_add(arturl, art_data['title'], extended=config.EXTENDED_DESCRIPTION, tags=entry_tags)
import getpass from pydelicious import DeliciousAPI, DeliciousItemExistsError sourceUser = raw_input("Username [source]: ") sourcePasswd = getpass.getpass("Password [source]: ") sourceDlcs = DeliciousAPI(sourceUser, sourcePasswd) print "Getting all bookmarks from source:" + sourceUser sourceBkmrks = sourceDlcs.posts_all()['posts'] print "Done getting bookmarks" fromTag = ' from:' + sourceUser destUser = raw_input("Username [destination]: ") destPasswd = getpass.getpass("Password [destination]: ") destDlcs = DeliciousAPI(destUser, destPasswd) sourceSize = len(sourceBkmrks) for i in range(46,sourceSize): bkmrk = sourceBkmrks[i] href = bkmrk['href'] desc = bkmrk['description'] ext = bkmrk['extended'] if 'extended' in bkmrk else '' share = bkmrk['shared'] if 'shared' in bkmrk else 'yes' date = bkmrk['time'] tag = bkmrk['tag'] if 'tag' in bkmrk else '' tag += fromTag print 'Copying (' + str(i+1) + '/' + str(sourceSize) + ') '+ desc + ' (' + href + ')' try : destDlcs.posts_add(href, desc, extended = ext, tags = tag, dt= date, shared = share) except DeliciousItemExistsError: desc + ' (' + href + ') already exists'