Created
July 1, 2012 21:46
-
-
Save mbenedettini/3029734 to your computer and use it in GitHub Desktop.
Google contacts wiper
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
import sys | |
import getopt | |
import getpass | |
import atom | |
import gdata.contacts.data | |
import gdata.contacts.client | |
class ContactsWiper(object): | |
def __init__(self, email, password): | |
self.gd_client = gdata.contacts.client.ContactsClient(source='ContactsWiper-1') | |
self.gd_client.ClientLogin(email, password, self.gd_client.source) | |
def wipe(self): | |
max_results = 25000 | |
query = gdata.contacts.client.ContactsQuery() | |
query.max_results = max_results | |
feed = self.gd_client.GetContacts(q = query) | |
print "Got %d contacts" % len(feed.entry) | |
print "Deleting them..." | |
for e in feed.entry: | |
self.gd_client.Delete(e) | |
def main(): | |
"""Demonstrates use of the Contacts extension using the ContactsSample object.""" | |
# Parse command line options | |
try: | |
opts, args = getopt.getopt(sys.argv[1:], '', ['user=', 'pw=']) | |
except getopt.error, msg: | |
print 'python contacts_example.py --user [username] --pw [password]' | |
sys.exit(2) | |
user = '' | |
pw = '' | |
# Process options | |
for option, arg in opts: | |
if option == '--user': | |
user = arg | |
elif option == '--pw': | |
pw = arg | |
while not user: | |
print 'NOTE: Please run these tests only with a test account.' | |
user = raw_input('Please enter your username: ') | |
while not pw: | |
pw = getpass.getpass() | |
if not pw: | |
print 'Password cannot be blank.' | |
try: | |
sample = ContactsWiper(user, pw) | |
except gdata.client.BadAuthentication: | |
print 'Invalid user credentials given.' | |
return | |
sample.wipe() | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment