Error 403 from Google Calendar? Upgrade to the new Google Calendar support. See here for details. close
Welcome, Guest
Please Login or Register.    Lost Password?

Script to Export and Import at fixed intervals
(1 viewing) (1) Guest
Go to bottomPage: 1
TOPIC: Script to Export and Import at fixed intervals
#20104
Script to Export and Import at fixed intervals 1 Year, 1 Month ago  
In order to access my corporate calendar (outlook) from home, I've been syncing with google calendar, but didn't work smothly enough.

My idea is to use Rainlendar (I'm a Pro user since long time) to export the outlook canlendar (when I'm at the office) with a personal google calendar, so I can access later from home.

Through "organizer" funtion in Rainlendar I can copy one or many entries from one calendar to the other, but this is a manual process (even with Ctrl-A to select all, it still required manual intervention). My intent is to look for a script (or a better solution) to sync or export from outlook then import into google calendar, both sitting on my local compoter.

Thanks
wizel10
wizel10
Fresh Boarder
Posts: 3
graphgraph
User Offline Click here to see the profile of this user
The administrator has disabled public write access.
 
#20105
Re:Script to Export and Import at fixed intervals 1 Year, 1 Month ago  
wizel10 wrote:
In order to access my corporate calendar (outlook) from home, I've been syncing with google calendar, but didn't work smothly enough.

My idea is to use Rainlendar (I'm a Pro user since long time) to export the outlook canlendar (when I'm at the office) with a personal google calendar, so I can access later from home.

Through "organizer" funtion in Rainlendar I can copy one or many entries from one calendar to the other, but this is a manual process (even with Ctrl-A to select all, it still required manual intervention). My intent is to look for a script (or a better solution) to sync or export from outlook then import into google calendar, both sitting on my local compoter.

Thanks
wizel10


Welcome to the forum, wizel10.

I been trying to achieve what you want with scripts. But unfortunately, it doesn't work. This is the code:
Code:

function SyncCalendars_OnTimer(userData)
  local arrayUIDs = Rainlendar_ListAllComponents("Calendar1")
  local iItems = #arrayUIDs
  local strNewLine = "\r\n"

  Rainlendar_Log("Syncing " .. iItems .. " items from calendar 1 to calendar 2")
  for i = 1, iItems do
    local strIcalData = Rainlendar_GetComponent(arrayUIDs[i])   
    _, _, strFirst, strUID, strLast = strIcalData:find("(.*)UID:(.-)" .. strNewLine .. "(.*)")
    local auxIcalData = strFirst .. "UID:" .. strUID .. "-copy" .. strNewLine .. strLast
    Rainlendar_CreateComponent(auxIcalData, "GCalendar")
  end
end

-- Create a timer which sync the calendars every 1 minute
Rainlendar_CreateTimer(60 * 1000, SyncCalendars_OnTimer)
SyncCalendars_OnTimer("")



This code only will copy/update every event from calendar 1 into calendar 2, but it won't delete any event removed from calendar 1.
It works with 2 local calendars, but using Google Calendar as the 2nd, looks like Google Calendar (v3) changes the unique identifier (UID) and every time a new instance of the same event is copied.
Jorge_Luis
Platinum Boarder
Posts: 795
graphgraph
User Offline Click here to see the profile of this user
Gender: Male My Rainlendar Skins Location: Argentina Birthday: 03/15
Last Edit: 2013/10/29 20:46 By Jorge_Luis.
The administrator has disabled public write access.
 
#20120
Re:Script to Export and Import at fixed intervals 1 Year, 1 Month ago  

Jorge_Luis wrote:
...
This code only will copy/update every event from calendar 1 into calendar 2, but it won't delete any event removed from calendar 1.
It works with 2 local calendars, but using Google Calendar as the 2nd, looks like Google Calendar (v3) changes the unique identifier (UID) and every time a new instance of the same event is copied.


Thanks Jorge_Luis,
I did try the code, and had a few issues: crashed Rainlendar and then duplicate some entries a few times. Additionally I've added a function to delete all previous entries, but took nearly 5 minutes to fully complete.
The idea seems to be correct, but can't make working as expected.

Code:


function Hotkey_SyncCalendars()
        SyncCalendars_OnTimer("")
end

function CleanCalendars(userData) 
  local arrayUIDs = Rainlendar_ListAllComponents("Test") 
  local iItems = #arrayUIDs 
  
  Rainlendar_Log("Removing " .. iItems .. " items from Google Calendar") 
  for i = 1, iItems do 
    Rainlendar_DeleteComponent(arrayUIDs[i]) 
-- Rainlendar_Log("removing item " .. i .. " from Google Calendar") 
  end 
end 

function CopyCalendars(userData) 
  local arrayUIDs = Rainlendar_ListAllComponents("mymail@outlook.com") 
  local iItems = #arrayUIDs 
  local strNewLine = "\r\n" 
 
  Rainlendar_Log("Copying " .. iItems .. " items from Outlook to Google") 
  for i = 1, iItems do 
    local strIcalData = Rainlendar_GetComponent(arrayUIDs[i])    
    _, _, strFirst, strUID, strLast = strIcalData:find("(.*)UID:(.-)" .. strNewLine .. "(.*)") 
    local auxIcalData = strFirst .. "UID:" .. strUID .. "-copy" .. strNewLine .. strLast 
    Rainlendar_CreateComponent(auxIcalData, "Test") 
  end 
end

function SyncCalendars_OnTimer(userData) 
  CleanCalendars("")
  -- Rainlendar_Message("Clean completed", 4)
  CopyCalendars("")
  -- Rainlendar_Message("Copy completed", 4)
end 
 
-- Create a timer which sync the calendars every 15 minute 
-- Rainlendar_CreateTimer(10*60 * 1000, SyncCalendars_OnTimer) 
-- SyncCalendars_OnTimer("")

wizel10
Fresh Boarder
Posts: 3
graphgraph
User Offline Click here to see the profile of this user
Last Edit: 2013/11/01 13:30 By wizel10.
The administrator has disabled public write access.
 
#20121
Re:Script to Export and Import at fixed intervals 1 Year, 1 Month ago  
If your event doesn't have a location tag, you can use it as a workaround.
In this code (rebuilt from yours) it uses the LOCATION tag to store the Rainlendar/Outlook UID. Then, when retrieve the info it stores each UID in an array. If the event UID is already in the list, it does nothing, if not, is copied to the dstCalendar (srcCalendar and dstCalendar are now in the Timer creator as userData).
This code has defects, but it avoid you to delete one by one each event.

I don't do it here, but always try to use namespaces in the scripts to avoid function's names collisions (e.g. SyncCalendars_NameOfTheFunction() ).

Code:

local arrayStoredUIDs = {}
local strNewLine = "\r\n"  

function Hotkey_SyncCalendars() 
        SyncCalendars_OnTimer("") 
end 
 
function RetrieveCalendars(userData)
  _, _, srcCalendar, dstCalendar = userData:find("(.*)|(.*)")
  local arrayUIDs = Rainlendar_ListAllComponents(dstCalendar)
  local iItems = #arrayUIDs  
   
  Rainlendar_Log("Retrieving " .. iItems .. " items from Google Calendar")  
  for i = 1, iItems do  
    -- Get the UID in the Location tag and store locally
    local strIcalData = Rainlendar_GetComponent(arrayUIDs[i])
    _, _, strUID = strIcalData:find(".*LOCATION:(.-)" .. strNewLine)
    table.insert(arrayStoredUIDs, strUID)
  end  
end  
 
function SyncCalendars_InTable(tbl, item)
  for key, value in pairs(tbl) do
    if value == item then return key end
  end
  return false
end

function CopyCalendars(userData)
  _, _, srcCalendar, dstCalendar = userData:find("(.*)|(.*)")
    
  local arrayUIDs = Rainlendar_ListAllComponents(srcCalendar)  
  local iItems = #arrayUIDs  
  
  Rainlendar_Log("Copying " .. iItems .. " items from Outlook to Google")  
  for i = 1, iItems do  
    if (SyncCalendars_InTable(arrayStoredUIDs, arrayUIDs[i])) then
    else
      local strIcalData = Rainlendar_GetComponent(arrayUIDs[i])     
      _, _, strFirst, strUID, strLast = strIcalData:find("(.*)UID:(.-)" .. strNewLine .. "(.*)")  
      local auxIcalData = strFirst .. "UID:" .. strUID .. "-copy" .. strNewLine 
      auxIcalData = auxIcalData .. "LOCATION:" .. strUID .. strNewLine .. strLast
      Rainlendar_CreateComponent(auxIcalData, dstCalendar)  
    end
  end  
end 
 
function SyncCalendars_OnTimer(userData)  
  RetrieveCalendars(userData) 
  -- Rainlendar_Message("Retrieve completed", 4) 
  CopyCalendars(userData) 
  -- Rainlendar_Message("Copy completed", 4) 
  return true
end  
  
-- Create a timer which sync the calendars every 10 minute  
Rainlendar_CreateTimer(10 * 60 * 1000, SyncCalendars_OnTimer, "mail@outlook|mail@gmail")
-- SyncCalendars_OnTimer("mail@outlook|mail@gmail") 

Jorge_Luis
Platinum Boarder
Posts: 795
graphgraph
User Offline Click here to see the profile of this user
Gender: Male My Rainlendar Skins Location: Argentina Birthday: 03/15
The administrator has disabled public write access.
 
#20203
Re:Script to Export and Import at fixed intervals 1 Year ago  
Jorge_Luis, thanks for your help.
Unfortunately, I couldn't make it working.
I would need to look for a different approach.

Thanks.
wizel10
Fresh Boarder
Posts: 3
graphgraph
User Offline Click here to see the profile of this user
Last Edit: 2013/11/22 06:55 By wizel10.
The administrator has disabled public write access.
 
Go to topPage: 1
get the latest posts directly to your desktop