Skip to content

Instantly share code, notes, and snippets.

@davedelong
Created November 19, 2012 21:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davedelong/4114242 to your computer and use it in GitHub Desktop.
Save davedelong/4114242 to your computer and use it in GitHub Desktop.
Removing unused tags from Evernote
//
// main.m
// Tag Cleaner
//
// Created by Dave DeLong on 11/17/12.
// Copyright (c) 2012 Dave DeLong. All rights reserved.
//
// requires https://github.com/evernote/evernote-sdk-mac
#import <Foundation/Foundation.h>
#import "EDAMErrors.h"
#import "EDAMLimits.h"
#import "EDAMNoteStore.h"
#import "EDAMTypes.h"
#import "EDAMUserStore.h"
#import "TBinaryProtocol.h"
#import "TProtocol.h"
#import "TProtocolException.h"
#import "TProtocolFactory.h"
#import "TProtocolUtil.h"
#import "TApplicationException.h"
#import "TException.h"
#import "TProcessor.h"
#import "TProcessorFactory.h"
#import "THTTPClient.h"
#import "TMemoryBuffer.h"
#import "TTransport.h"
#import "TTransportException.h"
#import "TSharedProcessorFactory.h"
// You can acquire a Developer Token from https://www.evernote.com/api/DeveloperToken.action
NSString * const ENDeveloperToken = @"...";
int main(int argc, const char * argv[]) {
@autoreleasepool {
THTTPClient *httpClient = [[THTTPClient alloc] initWithURL:[NSURL URLWithString:@"https://www.evernote.com/edam/user"]];
TBinaryProtocol *userStoreProtocol = [[TBinaryProtocol alloc] initWithTransport:httpClient];
EDAMUserStoreClient *userStoreClient = [[EDAMUserStoreClient alloc] initWithProtocol:userStoreProtocol];
NSString *noteStoreString = [userStoreClient getNoteStoreUrl:ENDeveloperToken];
NSURL *noteStoreURL = [NSURL URLWithString:noteStoreString];
THTTPClient *noteStoreTransport = [[THTTPClient alloc] initWithURL:noteStoreURL];
TBinaryProtocol *noteStoreProtocol = [[TBinaryProtocol alloc] initWithTransport:noteStoreTransport];
EDAMNoteStoreClient *noteStoreClient = [[EDAMNoteStoreClient alloc] initWithProtocol:noteStoreProtocol];
NSArray *tags = [noteStoreClient listTags:ENDeveloperToken];
NSInteger counter = 0;
for (id tag in tags) {
NSArray *tagGuids = @[[tag guid]];
EDAMNoteFilter *filter = [[EDAMNoteFilter alloc] initWithOrder:0 ascending:YES words:nil notebookGuid:nil tagGuids:tagGuids timeZone:nil inactive:NO];
EDAMNoteCollectionCounts *counts = [noteStoreClient findNoteCounts:ENDeveloperToken :filter :NO];
NSDictionary *tagCounts = [counts tagCounts];
id count = [tagCounts objectForKey:[tag guid]];
if (count == nil || [count integerValue] == 0) {
[noteStoreClient expungeTag:ENDeveloperToken :[tag guid]];
counter++;
}
}
NSLog(@"expunged %ld unused tags", counter);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment