Sign in to follow this  
Followers 0
beestinga

Google Calendar batch event creation

3 posts in this topic

So, my wife is a nurse and she works 12-hour night shifts, 7pm-7am. Entering her schedule each month is typically a pain because it means clicking on each day, creating an event, editing that event, and setting all of the same parameters over and over again (same times, no notifications, show me as available, etc.) - the only thing that changes is the day.

So, I whipped this up real quick 'n' dirty. It's not very good, as it doesn't use FF.au3 to make sure that the pages load or to enter things in. If, for example, you have 2 notifications on by default instead of 1, then this won't work for you.

To use it, just make a text file ("dates.txt") on the root of your c: drive with a different date (no year) on each line. Open up your google calendar and run the program. You'll also need to tell it where to click and enter the specifics about your event.

Actually, this may be entirely useless to anyone but me.....but, oh well, here it is. It's taken me about 4x as long to write this write-up as it did to code the thing.

#Include <File.au3>
func fillEvent($date)
    WinActivate("Google Calendar")
    MouseClick("left",53,234) ;clicks create event
    sleep(1000) ;short delay for the page to change
    Send("AJ Work{TAB}"&$date&"/2010{TAB}1900{TAB}700am")

for $j = 1 to 17 ;tab down to the remove reminder
Send("{TAB}")
next

Send("{ENTER}{TAB}{TAB}{UP}") ;remove reminder, set available and
Send("{TAB}{TAB}{TAB}{TAB}{Enter}")
Sleep(1000) ;snooze until you get back to the main calendar page
endfunc

$file = "c:\dates.txt"
FileOpen($file, 0)
For $i = 1 to _FileCountLines($file)
    $date = FileReadLine($file, $i)
    fillEvent($date)
Next
FileClose($file)

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

I've made something similar, mine grabs my work schedule from a web page that my employer posts it to & then adds it to Google Calendar.

First off, I use either Chrome or Firefox for my normal surfing, so I decided to implement IE for this script. In IE, I have it set to remove all information on exit, so it doesn't store any information. This was the easiest way for me to make this script multiuser. Multiuser was a must for me.

So, what this does is just log into the web page with my schedule, grab my schedule from the webpage, into a variable, remove all the garbage that isn't my work schedule (since I'm working with the data that's viewable on the webpage in text format, it's MUCH nicer than working with the web page HTML.

The web page is always 2-weeks out, so I couldn't use the implementation of the OP as I would be theoretically running the script anywhere from everyday to once every 2 weeks & I have no way to check if the information is already in the calendar, because of this, I need to keep track of what data has already been entered. For this, I just use a simple INI file based on the name of the person running the program and have it store the dates its already programmed into calendar. If it encounters these dates again, it won't add them to the calendar.

Then, my Google Calendar has the option to add a POPUP or EMAIL, but the other person I coded this for doesn't have those options by default at all, so I had to make it so for ME, it would remove the email option, and set it to popup an hour before the work schedule and for the OTHER person, it'll tab less times because those options don't exist at all, so you'll want to manually try adding something and tab through to see what you need it to do.

I know the code isn't pretty or commented properly & I apologize for that, but I wasn't originally intending to post this, but decided someone else might want to do something similar and want to use my code as a starting point.

I apologize that this obviously can't be a working sample, since I can't allow you to log in to my work schedule. BUT, I can give you the baseline for what the program gets from the web page. Below the code is exactly what the program initially stores in $sText, so if you want to modify this, you'll at least be able to see WHY the program is doing what it's doing. You could also store that data to a text file and modify the script to pull it into the variable & let the program run to see what it does. While debugging, I just changed: while $loop<$Array[0] to while $loop<5 and it gave me an indication of what it was going to do.

I plan on GUI-iffying this eventually to allow the user specific information to be added into a text box, so it wouldn't need to be recompiled per person, but for now, it's only a 2-user script & I don't know who else I'd give it to who wouldn't mind the restrictions that I need on IE for it to work.

#include <IE.au3>

$user="tj"

if $user=="tj" Then
    $id="WORKID"
    $pass="WORKPASS"
    $email="EMAIL@gmail.com"
    $emailPass="EMAILPASSWORD"
EndIf

if $user=="OtherPerson" Then
    $id="WORKID"
    $pass="WORKPASS"
    $email="EMAIL@gmail.com"
    $emailPass="EMAILPASSWORD"
EndIf

$oIE = _IECreate ("http://WORKWEBPAGE.com",0,1,1,1)
Send("{CTRLDOWN}{HOME}{CTRLUP}{CTRLUP}" & $id  & "{TAB}" & $pass & "{ENTER}")
_IELoadWait($oIE)
$sText = _IEBodyReadText ($oIE)
_IEQuit ($oIE)


$oIE = _IECreate ("http://www.google.com/calendar/",0,1,1,1)
Send("{CTRLDOWN}{HOME}{CTRLUP}{CTRLUP}" & $email  & "{TAB}" & $emailPass & "{ENTER}")
_IELoadWait($oIE)


$sText = StringTrimLeft($sText,StringInStr ($sText, "Time")+4)
$Array=StringSplit($sText,@CR)

$loop=1
while $loop<$Array[0]
    $Array[$loop]=StringTrimLeft($Array[$loop],5)

    $Date=StringStripWS(StringLeft($Array[$loop],10),8)
    $Shift=StringStripWS(StringRight($Array[$loop],14),8)

    if $Date<>$Shift Then
        $Shift=StringReplace(StringRight($Shift,StringLen($Shift)-1),":","") ;Remove excess character that is needed if this is a non-workday
        $Shift=StringSplit($Shift,"-")


        if INIRead("\\tjserver\backup\" & $user & "\work.ini",$Date,"Hours","ASDF")=="ASDF" Then
            WinActivate("Google Calendar")
            Send("c")
            _IELoadWait($oIE)
            sleep(500)
            if $User=='tj' Then
                Send("WORK{TAB}" & $Date & "{TAB}" & $Shift[1] & "{TAB}" & $Shift[2] & "{TAB 4}WORKPLACE{TAB 13}{ENTER}{TAB 2}1{TAB}h{TAB 7}{ENTER}")
            ElseIf $user='OtherPerson' Then
                Send("WORK{TAB}" & $Date & "{TAB}" & $Shift[1] & "{TAB}" & $Shift[2] & "{TAB 4}WORKPLACE{TAB 15}{ENTER}")
            EndIf

            IniWrite("\\tjserver\backup\" & $user & "\work.ini",$Date,"Hours",$Shift[1] & '-' & $Shift[2])
            ;MsgBox(0, "Body Text",@CRLF & "FULL - " & $Array[$loop] & @CRLF & @CRLF & "Date - " & $Date & @CRLF & @CRLF & "Shift - " & $Shift)
        EndIf
    EndIf
    $loop+=1
WEnd

_IEQuit ($oIE)

MsgBox(1,$user,"DONE!")

WORKID
My Working Schedule
Sign up Email Notice
Days Off Request
Available Shifts
Log Off 
Date    Department  A/C Position    Time
Fri 05/28/2010  A.B.C.  666 -Description    Supervisor  08:00 - 16:30
Sat 05/29/2010  A.B.C.  666 -Description    Supervisor  08:00 - 16:30
Sun 05/30/2010  A.B.C.  666 -Description    Supervisor  08:00 - 16:30
Mon 05/31/2010  A.B.C.  666 -Description    Supervisor  13:30 - 22:00
Tue 06/01/2010               
Wed 06/02/2010  A.B.C.  666 -Description    Supervisor  13:30 - 20:00
Thu 06/03/2010               
Fri 06/04/2010  A.B.C.  666 -Description    Supervisor  08:00 - 16:30
Sat 06/05/2010  A.B.C.  666 -Description    Supervisor  08:00 - 16:30
Sun 06/06/2010  A.B.C.  666 -Description    Supervisor  08:00 - 16:30
Mon 06/07/2010  A.B.C.  666 -Description    Supervisor  13:30 - 20:00
Tue 06/08/2010               
Wed 06/09/2010  A.B.C.  666 -Description    Supervisor  13:30 - 20:00
Thu 06/10/2010
Edited by TJHart85

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

I've modified the script from above pretty heavily to make more use of the IE.au3 library.

Not done yet, but probably all the work I'm going to put into it for a while.

Hopefully my code will be usefull as a starting point for someone else.

#comments-start
TOOLS->OPTIONS->DELETE BROWSING HISTORY ON EXIT
    OPTION IS PREFERRED IF MULTIPLE USERS USE THE PC!
        IF ANOTHER USER IS LOGGED INTO A GOOGLE ACCOUNT, 
        IT WILL CAUSE PROBLEMS!
#comments-end

#include <IE.au3>

$user="tj"

if $user=="tj" Then
    $id="workid"
    $pass="workpass"
    $email="email@gmail.com"
    $emailPass="password"
EndIf

if $user=="OtherUser" Then
    $id="workid"
    $pass="workpass"
    $email="email@gmail.com"
    $emailPass="password"
EndIf

Do
    ;Create instance of IE
    $oIE = _IECreate ("http://WORKWEBPAGE.com",0,1,1,1)
    _IELoadWait($oIE)

    ;Select form
    $oForm = _IEFormGetObjByName ($oIE, "form1")

    ;Select text inputs and set proper values
    $oQuery = _IEFormElementGetObjByName ($oForm, "txtID")
    _IEFormElementSetValue ($oQuery,$id)
    $oQuery = _IEFormElementGetObjByName ($oForm, "txtPASS")
    _IEFormElementSetValue ($oQuery,$pass)

    ;Simulate clicking of LOGIN button
    $oSubmit = _IEGetObjByName ($oIE, "btnOK")
    _IEAction ($oSubmit, "click")
    _IELoadWait ($oIE)

    _IELoadWait($oIE)
    $sText = _IEBodyReadText ($oIE)
    _IEQuit ($oIE)
Until $sText <> "" 



$oIE = _IECreate ("http://www.google.com/calendar/",0,1,1,1)
_IELoadWait($oIE)

;Select form
$oForm = _IEFormGetObjByName ($oIE, "gaia_loginform")

;Select text inputs and set proper values
$oQuery = _IEFormElementGetObjByName ($oForm, "Email")
_IEFormElementSetValue ($oQuery,$email)
$oQuery = _IEFormElementGetObjByName ($oForm, "Passwd")
_IEFormElementSetValue ($oQuery,$emailPass)

;Simulate clicking of Sign In button
$oSubmit = _IEGetObjByName ($oIE, "signIn")
_IEAction ($oSubmit, "click")
_IELoadWait ($oIE)


$sText = StringTrimLeft($sText,StringInStr ($sText, "Time")+4)
$Array=StringSplit($sText,@CR)


$loop=1
while $loop<$Array[0]
    $Array[$loop]=StringTrimLeft($Array[$loop],5)

    ;MsgBox(0,"",$Array[$loop] & @CRLF & StringStripWS(StringLeft($Array[$loop],10),8))

    $Date=StringStripWS(StringLeft($Array[$loop],10),8)
    $Shift=StringStripWS(StringRight($Array[$loop],14),8)

    if $Date<>$Shift Then
        $Shift=StringReplace(StringRight($Shift,StringLen($Shift)-1),":","") ;Remove excess character that is needed if this is a non-workday
        $Shift=StringSplit($Shift,"-")

        if INIRead("\\tjserver\backup\" & $user & "\work.ini",$Date,"Hours","ASDF")="ASDF" Then

        _IELoadWait($oIE)
        sleep(1500)
        _IELoadWait($oIE)

        $NoGo=True
        while $NoGo=True
            ;Get ControlID for IE to send a 'c' command to launch new calendar item
            $hwnd = _IEPropertyGet($oIE, "hwnd")
            ;_IEAction ($oSubmit, "focus")
            ControlSend($hwnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "c")
            _IELoadWait($oIE)
            if StringInStr(_IEBodyReadText ($oIE),"Back to Calendar",2) <> 0 Then $NoGo=False
            sleep(250)
        WEnd

        ;Select form
        $oForm = _IEFormGetObjByName ($oIE, "masterForm")
        ;Select text inputs and set proper values
        $oQuery = _IEFormElementGetObjByName ($oForm, "title")
        _IEFormElementSetValue ($oQuery,"Work")


        if $User='tj' Then
            ControlSend($hwnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "{TAB}" & $Date & "{TAB}" & $Shift[1] & "{TAB}" & $Shift[2] & "{TAB 4}Great America, 60031{TAB 13}{ENTER}{TAB 2}1{TAB}h{TAB 7}{ENTER}")
        ElseIf $user='OtherUser' Then
            ControlSend($hwnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "{TAB}" & $Date & "{TAB}" & $Shift[1] & "{TAB}" & $Shift[2] & "{TAB 4}Great America, 60031{TAB 15}{ENTER}")
        EndIf

        IniWrite("\\tjserver\backup\" & $user & "\work.ini",$Date,"Hours",$Shift[1] & '-' & $Shift[2])
        ;MsgBox(0, "Body Text",@CRLF & "FULL - " & $Array[$loop] & @CRLF & @CRLF & "Date - " & $Date & @CRLF & @CRLF & "Shift - " & $Shift)
        sleep(2000)
        EndIf
    EndIf
    $loop+=1
WEnd

_IEQuit ($oIE)

MsgBox(1,$user,"DONE!")
Edited by TJHart85

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0