The Cache: Technology Expert's Forum
 
*
Welcome, Guest. Please login or register. September 19, 2019, 05:23:40 AM

Login with username, password and session length


Pages: [1]
  Print  
Author Topic: Google script thoughts  (Read 1939 times)
Phaėton
Lifer
*****
Offline Offline

Posts: 555


⎝⏠⏝⏠⎠


View Profile
« on: December 27, 2012, 10:37:04 AM »

Anyone play with this yet?  Im gonna give it a go....   thoughts?

http://www.google.com/script/start/


heres some example code:

Code:

function Initialize() {

 
  var NAME  = "YOUR_FULL_NAME";           // It will show up in the signature of your outgoing emails
  var GROUP = "GOOGLE_CONTACT_GROUP";     // Enter the exact name of your Google Contacts group

 
 
/*


  Story: http://www.labnol.org/?p=27306
 
  Video: http://www.youtube.com/watch?v=SMxvZgK4BMg
 


  T U T O R I A L
  - - - - - - - -

  Step 0. Go to File -> Make a Copy to copy this script to your Google
  Step 1. Update the values of NAME and GROUP fields above.
  Step 2. Go to File -> Manage Versions and Save a new version.
  Step 3. Go to Publish -> Deploy as Web App, choose "Anyone, even Anonymous" under "Who can access the app" and click Deploy.
  Step 4. Go to Run -> Initialize and authorize the script.
  Step 5. Repeat Step #4 to run the script and you are done!
 


  H E L P
  - - - -
     
  For help, send me a tweet @labnol or an email at amit@labnol.org



  T H E   G E E K Y   S T U F F
  - - -   - - - - -   - - - - -
 
  You can ignore everything that's below this line. 



*/
 
  ScriptProperties.setProperty("NAME",  NAME);
  ScriptProperties.setProperty("GROUP", GROUP);
 
  go();
 
}

function go() {   
 
  var emailNAME     = ScriptProperties.getProperty("NAME");
  var googleGROUP   = ContactsApp.getContactGroup(ScriptProperties.getProperty("GROUP"));
 
  if (googleGROUP) {
   
    var emailSUBJECT  = "Your contact information";   
    var myContacts = googleGROUP.getContacts();
   
    for (i=0; i<myContacts.length; i++) {
     
      var email = myContacts[i].getPrimaryEmail();
      var ID = myContacts[i].getId();
      ID = ID.substr(ID.lastIndexOf("/") + 1);
     
      var emailBody = "Hi,<br /><br />" +
        "Would you please take a moment and update your contact information in my address book. <br /><br />" +
          "Please <a href='" + ScriptApp.getService().getUrl() + "?" +
            Utilities.base64Encode(ID + "#" + email) + "'>click here</a> and fill-in the required details." +
              "Your information will be directly added to my Google Contacts." +
                "<br /><br />Thanks,<br />" + emailNAME;
     
      var emailTEXT = "Hi,\n\n" +
        "Would you please take a moment and update your contact information in my address book. \n\n" +
          ScriptApp.getService().getUrl() + "?" + Utilities.base64Encode(ID + "#" + email) +
            "\n\nJust click the URL, fill-in the form and your details will be directly added to my Google Contacts." +
              "\n\nThanks,\n" + emailNAME;
     
      GmailApp.sendEmail(email, emailSUBJECT, emailTEXT,
                         {htmlBody:emailBody, name:emailNAME});
    }
  }   
}

function doGet() {
  var html = HtmlService.createTemplateFromFile("form").evaluate();
  html.setTitle("Google Contacts - Digital Inspiration")
  return html; 
}

function labnolGetContact(q) {   
 
  var contact = {}; 
  contact.FOUND = 0;
 
  try {
   
    var id = Utilities.base64Decode(q); 
    var email = "";
   
    for(var i = 0; i<id.length; i++) {   
      email += String.fromCharCode(id[i]);
    }   
   
    var contactID = email.substr(0, email.indexOf("#"));
    email = email.substr(email.indexOf("#")+1);
           
    var c = ContactsApp.getContact(email);   
   
    if (c) {
     
      var originalID = c.getId();
      originalID = originalID.substr(originalID.lastIndexOf("/") + 1);
     
      if (contactID != originalID)
        return contact;
     
      contact.FOUND = 1;
     
      if (c.getFullName().length)
        contact.FULL_NAME = c.getFullName();
     
      if(c.getEmails(ContactsApp.Field.HOME_EMAIL).length)
        contact.HOME_EMAIL = c.getEmails(ContactsApp.Field.HOME_EMAIL)[0].getAddress();
     
      if(c.getAddresses(ContactsApp.Field.HOME_ADDRESS).length) {
        contact.HOME_ADDRESS = c.getAddresses(ContactsApp.Field.HOME_ADDRESS)[0].getAddress();
        contact.HOME_ADDRESS = contact.HOME_ADDRESS.replace(/\n/g, ", ");
      }

      if(c.getPhones(ContactsApp.Field.MOBILE_PHONE).length)
        contact.MOBILE_PHONE = c.getPhones(ContactsApp.Field.MOBILE_PHONE)[0].getPhoneNumber();
     
      if(c.getIMs(ContactsApp.Field.SKYPE).length)
        contact.SKYPE = c.getIMs(ContactsApp.Field.SKYPE)[0].getAddress();

      if(c.getUrls(ContactsApp.Field.BLOG).length)
        contact.BLOG = c.getUrls(ContactsApp.Field.BLOG)[0].getAddress();
     
      if(c.getDates(ContactsApp.Field.BIRTHDAY).length) {
        var months = ["0", "JANUARY", "FEBRUARY", "MARCH", "APRIL", "MAY", "JUNE",
                      "JULY", "AUGUST", "SEPTEMBER", "OCTOBER", "NOVEMBER", "DECEMBER"];
        contact.BIRTHDAY = months.indexOf(c.getDates(ContactsApp.Field.BIRTHDAY)[0].getMonth().toString()) +
          "/" + c.getDates(ContactsApp.Field.BIRTHDAY)[0].getDay() +
          "/" + c.getDates(ContactsApp.Field.BIRTHDAY)[0].getYear();
      }     
    }   
   
    return contact;
 
  } catch (e) {
 
    return contact;   
 
  } 
 
}


function labnolUpdateContact(contact) {   
 
  try {   
       
    var c = ContactsApp.getContact(contact.HOME_EMAIL);   
   
    if (c) {
     
      MailApp.sendEmail(Session.getEffectiveUser().getEmail(),
                        "Updated: " + contact.FULL_NAME + " (" + contact.HOME_EMAIL + ")",
                        Utilities.jsonStringify(contact));
           
      c.setFullName(contact.FULL_NAME);
           
      if(c.getIMs(ContactsApp.Field.SKYPE).length)
        c.getIMs(ContactsApp.Field.SKYPE)[0].deleteIMField();
     
      if (contact.SKYPE.length)
        c.addIM(ContactsApp.Field.SKYPE, contact.SKYPE);
     
      if (c.getAddresses(ContactsApp.Field.HOME_ADDRESS).length)
        c.getAddresses(ContactsApp.Field.HOME_ADDRESS)[0].deleteAddressField();
     
      if (contact.HOME_ADDRESS.length)
        c.addAddress(ContactsApp.Field.HOME_ADDRESS, contact.HOME_ADDRESS);
     
      if (c.getPhones(ContactsApp.Field.MOBILE_PHONE).length)
        c.getPhones(ContactsApp.Field.MOBILE_PHONE)[0].deletePhoneField();
     
      if (contact.MOBILE_PHONE.length)
        c.addPhone(ContactsApp.Field.MOBILE_PHONE, contact.MOBILE_PHONE);
     
      if (c.getUrls(ContactsApp.Field.BLOG).length)
        c.getUrls(ContactsApp.Field.BLOG)[0].deleteUrlField();
     
      if (contact.BLOG.length)
        c.addUrl(ContactsApp.Field.BLOG, contact.BLOG);     
     
      if (contact.BIRTHDAY.length) {
       
          var months =
              [ 0, ContactsApp.Month.JANUARY, ContactsApp.Month.FEBRUARY, ContactsApp.Month.MARCH,
               ContactsApp.Month.APRIL, ContactsApp.Month.MAY, ContactsApp.Month.JUNE,
               ContactsApp.Month.JULY, ContactsApp.Month.AUGUST, ContactsApp.Month.SEPTEMBER,
               ContactsApp.Month.OCTOBER, ContactsApp.Month.NOVEMBER, ContactsApp.Month.DECEMBER
              ];
               
        var date = contact.BIRTHDAY.split("/");
       
        if (c.getDates(ContactsApp.Field.BIRTHDAY).length)
          c.getDates(ContactsApp.Field.BIRTHDAY)[0].deleteDateField();
       
        c.addDate(ContactsApp.Field.BIRTHDAY, months[parseFloat(date[0])], parseFloat(date[1]), parseFloat(date[2]));
     
      }
     
    }   
   
  } catch (e) {
     
  } 
 
}
« Last Edit: December 27, 2012, 10:40:54 AM by Phaėton » Logged

When I was your age we used to walk to the TV to change the channel....  _̴ı̴̴̡̡̡ ̡͌l̡̡̡ ̡͌l̡*̡̡ ̴̡ı̴̴̡ ̡̡͡|̲̲̲͡͡͡ ̲▫̲͡ ̲̲̲͡͡π̲̲͡͡ ̲̲͡▫̲̲͡͡ ̲|̡̡̡ ̡ ̴̡ı̴̡̡
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« Reply #1 on: January 06, 2013, 09:44:57 PM »

Sorry I missed this Phae ... what is that about?
Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
Phaėton
Lifer
*****
Offline Offline

Posts: 555


⎝⏠⏝⏠⎠


View Profile
« Reply #2 on: January 09, 2013, 12:10:53 AM »

 

its an entire platform on a cloud... i have my request in to use the google compute
engine ..["Run your large-scale computing workloads on Linux virtual machines hosted on Google's infrastructure"]

ive been reading .... and reading.... there seems to be a ui service and some sort of snap on sort of environment..  a jdbc hookup to a google sql server....

and some ui services that look like pieces of a RAD type environment on the way... this
could get kinda cool!



* 1agooglecode.JPG (76.33 KB, 1024x768 - viewed 199 times.)
Logged

When I was your age we used to walk to the TV to change the channel....  _̴ı̴̴̡̡̡ ̡͌l̡̡̡ ̡͌l̡*̡̡ ̴̡ı̴̴̡ ̡̡͡|̲̲̲͡͡͡ ̲▫̲͡ ̲̲̲͡͡π̲̲͡͡ ̲̲͡▫̲̲͡͡ ̲|̡̡̡ ̡ ̴̡ı̴̡̡
Pages: [1]
  Print  
 
Jump to:  

Perkiset's Place Home   Best of The Cache   phpMyIDE: MySQL Stored Procedures, Functions & Triggers
Politics @ Perkiset's   Pinkhat's Perspective   
cache
mart
coder
programmers
ajax
php
javascript
Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks


Valid XHTML 1.0! Valid CSS!