def update(c = 0): user = User.objects.get(id = flowsettings.FOR_USER_ID) if c: items = FlowItem.objects.get_for_user(user,Bookmark) for item in items: if item.object: item.object.delete() item.delete() delicious = DeliciousClient(flowsettings.DELICIOUS_USERNAME, flowsettings.DELICIOUS_PASSWORD) # Check to see if we need an update last_update_date = FlowItem.objects.get_last_update_of_model(Bookmark, interactive = False) last_post_date = utils.parsedate(delicious.posts.update().get("time")) # First we sync bookmarks which have been added or edited on the site books = FlowItem.objects.get_interactive_for_model(Bookmark) if books: log.info("Found %s bookmarks changed or added on the site: sync with delicious", books.count()) for b in books: if not addnew(delicious, b): log.warn('Problem while syncronising bookmark %s with delicious' % b.url) if last_post_date <= last_update_date: log.info("Skipping update: last update date: %s; last post date: %s", last_update_date, last_post_date) return for datenode in reversed(list(delicious.posts.dates().getiterator('date'))): dt = utils.parsedate(datenode.get("date")).date() ld = last_update_date.date() if dt >= ld: log.debug("Checking delicious bookmarks for date %s" % format(dt,settings.DATE_FORMAT)) _update_bookmarks_from_date(delicious, dt, user)
def _handle_bookmark(info, user): b, created = Bookmark.objects.get_or_create( url = info['href'], defaults = dict( name = info['description'], extended = info.get('extended', ''), ) ) if not created: b.name = info['description'] b.extended = info.get('extended', '') b.save() visibility = 3 if info.get('shared','yes') == 'no': visibility = 1 return FlowItem.objects.create_or_update( b, user = user, timestamp = utils.parsedate(info['time']), tags = info.get('tag', ''), source = __name__, source_id = info['hash'], visibility = visibility )