Created
November 19, 2012 21:48
-
-
Save davedelong/4114242 to your computer and use it in GitHub Desktop.
Removing unused tags from Evernote
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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