def collect_data(): labels = set() posts = [] for post in pydelicious.get_all("upadhyay", "2muchluv")["posts"]: posts.append(post) labels = labels.union(post["tag"].split()) d = { 'labels': labels, 'posts': posts } return d
def handle(self, *args, **options): #api = pydelicious.apiNew(settings.DELICIOUS_USER, settings.DELICIOUS_PASS) update_time = pydelicious.get_update(settings.DELICIOUS_USER, settings.DELICIOUS_PASS) try: latest = Bookmark.objects.latest().saved_date except Bookmark.DoesNotExist: latest=datetime.datetime(1900,1,1) if datetime.datetime(*update_time[:6]) != latest: # print dir(pydelicious) recent_posts = pydelicious.get_all(settings.DELICIOUS_USER, settings.DELICIOUS_PASS, results=9999, fromdt=latest.strftime("%Y-%m-%dT%H:%M:%SZ")) # print "%s" % time.strftime("%d %m %Y" ,update_time) # print "Found %s new bookmarks" % len(recent_posts) for post in recent_posts: # print post['time'][:6] post_time = time.strptime(post['time'],"%Y-%m-%dT%H:%M:%SZ") post_date = datetime.datetime(*post_time[:6]) post_hash = post['meta'] args = ( ('description', post['description']), ('url', post['href']), ('post_hash', post_hash), ('extended_info', post['extended']), ('tags', post['tag']), ('saved_date', post_date), ) try: bookmark = Bookmark.objects.get(post_hash=post_hash) for k,v in args: setattr(bookmark, k, v) except Bookmark.DoesNotExist: bookmark = Bookmark(**dict(args)) bookmark.save()