Richard K Miller wrote:

> Hi Stacey,
>
> I know I'd be interested in seeing your code since I'd like to do 
> something similar for photos.  I'm also an assistant ward clerk and 
> the Bishop would like to use the online photo directory.  I wonder if 
> i could use your script as a starting point for a script to 
> automatically upload all the photos since they have to done one by one.
>
> Richard

Richard,

You won't be able to use my code as is...   However, looking at the code
should give you the idea how the Church web site cookies work and which
perl modules are helpful.

Below is part of the code that does the actual posting of the calendar
events.  The code is rough since I only use it only once a year or so to
post a year's worth of calendar events.  Therefore, I have not taken the
time to clean this code up.  This code won't work as is for you or,
really, anyone else.   It is hard coded for my stake and just for
posting calendar events.

Please note:

(1) This little perl program takes a performated input file with the
information in the form:
       <Day of the Year>^<Event Description>^<Start Date>^<Start
Time>^<End Date>^<End Time>^<Long Description>
    The "^" character is used to seperate the data fields.  I have other
perl programs that takes calendar data from various programs and formats
the data into this "intermediate" form.

(2) The "Live HTTP Headers" plug-in for FireFox is a good way to figure
out how to modify the following for wnat you need.  This will show you
all the header data that is passed by the browser and server even if the
session is encrypted.



#!/usr/bin/perl

use HTTP::Request::Common;
use HTTP::Cookies;
use LWP::UserAgent;

# For Debugging:
#use Data::Dumper;
#use LWP::Debug qw(+);

my $browser = LWP::UserAgent->new(
       # make the agent look like a Mac running FireFox
        agent => 'User-Agent: Mozilla/5.0 (Macintosh; U; PPC Mac OS X
Mach-O; en-US; rv:1.7.3) Gecko/200 40910',
);

my $cnt = 0;

foreach $event (<STDIN>) {

        if ( ($cnt++ % 10) == 0) {
                print "[Refreshing Cookies]\n";
                # Every 10 posts...
                # get "fresh" cookies
                my $response = $browser->post(
                         # The following URL will need to be changed for
your login screen
                       
'https://secure.lds.org/units/a/login/1,13088,779-1,00.html', 
                        [
                        'vgn_form_encoding' => 'UTF8',
                        'Submit' => '',
                         # the following will need to be changed as well
                        'nextUrl' =>
'%2Funits%2Fhome%2F1%2C9781%2C%2C00.html',
                        'URL' => '',
                        'username' => '<PUT YOUR USERNAME HERE>',
                        'password' => '<PUT YOUR PASSWD HERE>'
                        ]
                );

                # Put them in the cookie jar
                $cookie_jar->extract_cookies($response);
                $cookie_jar->save();
        }


        chop($event);

        # print "[" . $event . "]\n";

        ($doy, $descr, $sdate, $stm, $edate, $etm, $bdy) = split(/\^/,
$event);
       
        ($smn, $sdy, $syr) = split(/\//, $sdate);
        ($emn, $edy, $eyr) = split(/\//, $edate);

        $response = post_event($descr, $sdy, $smn, $syr, $stm, $edy,
$emn, $eyr, $etm, $bdy);

        print "POSTED: ", $descr, "(", $sdate, ")", "[",
$response->code(), "]\n";
}

sub post_event {
        my ($sdescr, $sday, $smonth, $syear, $stime, $eday, $emonth,
$eyear, $etime, $body) = @_; 

        my $req = POST
          # The follwing URL will need to change for your stake
          
'https://secure.lds.org/units/a/admin/calendar/edit/1,8140,679-1-5-522864,00.html?ParentSiteId=522864',
           'Content_Type' => 'form-data',
           'Content' =>
           [
                'currentYear2' => '',
                'monthIndex2' => '',
                'cal_event_id' => '',
                'repeat' => '',
                'sub' => 'Submit',
                'testVal' => '',
                'ParentSiteId' => '522864',   # This will need to be
changed for your stake

                'short_descr' => $sdescr,
                'start_day' => $sday,
                'start_month' => $smonth,
                'start_year' => $syear,
                'start_time' => $stime,
                'end_day' => $eday,
                'end_month' => $emonth,
                'end_year' => $eyear,
                'end_time' => $etime,
                'body_long' => $body,

                # all the following will need to be changed for the
wards in your stake
                'All' => '1',
                'number_1' => '99236',
                'n_99236' => '1',
                'number_2' => '206784',
                'n_206784' => '1',
                'number_3' => '238589',
                'n_238589' => '1',
                'number_4' => '277762',
                'n_277762' => '1',
                'number_5' => '268690',
                'n_268690' => '1',
                'number_6' => '82805',
                'n_82805' => '1',
                'number_7' => '268704',
                'n_268704' => '1',
                'number_8' => '42358',
                'n_42358' => '1',
                'number_9' => '179167',
                'n_179167' => '1',
                'number_10' => '227536',
                'n_227536' => '1',
                'number_11' => '276375',
                'n_276375' => '1',
                'number_12' => '386626',
                'n_386626' => '1',
                'number_13' => '108332',
                'n_108332' => '1',
                'number_14' => '226688',
                'n_226688' => '1',
                'number_15' => '228123'
                'n_228123' => '1',
                'checkedGroupsExist' => 'true',
          ];

          $cookie_jar->add_cookie_header($req);

          my $resp = $browser->request($req,);

          return $resp;
}

_______________________________________________
Ldsoss mailing list
Ldsoss@lists.ldsoss.org
http://lists.ldsoss.org/mailman/listinfo/ldsoss

Reply via email to