Google Scripts for Contacts
Here you can find a few Gmail related scripts.
Delete temporary contacts
You surely have created a contact that you want to delete later and possibly you also have forgotten about deleting it. To avoid this, just create a Group called "Tiny" (or wherever you want) and as a note add the time you want to keep it in your contacts: "x months" or "x years". Next, have the following script running every month, for instance.
Delete temporary contacts
You surely have created a contact that you want to delete later and possibly you also have forgotten about deleting it. To avoid this, just create a Group called "Tiny" (or wherever you want) and as a note add the time you want to keep it in your contacts: "x months" or "x years". Next, have the following script running every month, for instance.
function deleteTinyContacts() {
var group = ContactsApp.getContactGroup("Tiny");
var contacts = ContactsApp.getContactsByGroup(group)
var hoy = new Date();
Logger.log("today is " + hoy);
Logger.log("total contacts to delete: " + contacts.length);
for (var i = 0; i < contacts.length; i++) {
var date = contacts[i].getLastUpdated();
Logger.log(contacts[i].getFullName() + " was updated last in " + date);
var datediff = DateDiff.inMonths(date,hoy);
Logger.log("contact updated " + datediff + " months ago");
var note = contacts[i].getNotes();
var res = note.split(" ");
var Tmonths = calcMonths(res[1]);
var todelete = res[0]*Tmonths;
Logger.log("contact must be deleted after " + todelete + " months");
if (datediff>=todelete){
group.removeContact(contacts[i]);
}
}
}
var DateDiff = {
inDays: function(d1, d2) {
var t2 = d2.getTime();
var t1 = d1.getTime();
return parseInt((t2-t1)/(24*3600*1000));
},
inWeeks: function(d1, d2) {
var t2 = d2.getTime();
var t1 = d1.getTime();
return parseInt((t2-t1)/(24*3600*1000*7));
},
inMonths: function(d1, d2) {
var d1Y = d1.getFullYear();
var d2Y = d2.getFullYear();
var d1M = d1.getMonth();
var d2M = d2.getMonth();
return (d2M+12*d2Y)-(d1M+12*d1Y);
},
inYears: function(d1, d2) {
return d2.getFullYear()-d1.getFullYear();
}
}
function calcMonths(str){
if(str=="año"){return 12;}
else if(str=="mes"){return 1;}
}
var group = ContactsApp.getContactGroup("Tiny");
var contacts = ContactsApp.getContactsByGroup(group)
var hoy = new Date();
Logger.log("today is " + hoy);
Logger.log("total contacts to delete: " + contacts.length);
for (var i = 0; i < contacts.length; i++) {
var date = contacts[i].getLastUpdated();
Logger.log(contacts[i].getFullName() + " was updated last in " + date);
var datediff = DateDiff.inMonths(date,hoy);
Logger.log("contact updated " + datediff + " months ago");
var note = contacts[i].getNotes();
var res = note.split(" ");
var Tmonths = calcMonths(res[1]);
var todelete = res[0]*Tmonths;
Logger.log("contact must be deleted after " + todelete + " months");
if (datediff>=todelete){
group.removeContact(contacts[i]);
}
}
}
var DateDiff = {
inDays: function(d1, d2) {
var t2 = d2.getTime();
var t1 = d1.getTime();
return parseInt((t2-t1)/(24*3600*1000));
},
inWeeks: function(d1, d2) {
var t2 = d2.getTime();
var t1 = d1.getTime();
return parseInt((t2-t1)/(24*3600*1000*7));
},
inMonths: function(d1, d2) {
var d1Y = d1.getFullYear();
var d2Y = d2.getFullYear();
var d1M = d1.getMonth();
var d2M = d2.getMonth();
return (d2M+12*d2Y)-(d1M+12*d1Y);
},
inYears: function(d1, d2) {
return d2.getFullYear()-d1.getFullYear();
}
}
function calcMonths(str){
if(str=="año"){return 12;}
else if(str=="mes"){return 1;}
}
Comentarios
Publicar un comentario