Hi Mohit,
We control our own server, and it is easy to do stuff like this.
Here is a script that I use to update or add certain parts of our
website (currently offline).
Hope it is helpful.
saji
# ---------- %< start of code
#!/usr/bin/ruby
require File.dirname(__FILE__) + '/../config/boot'
require 'commands/runner'
class String
attr_accessor :slug
end
if ARGV.length==0
puts "USAGE : updateWeb YYYY MON service"
puts "for example : updateWeb 2007 NOV monitoring"
exit
end
months =%w( JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV DEC)
def updateContents(pPage,cPage,cSlug,filter,parts,contents)
puts "Updating contents of #{pPage}/#{cPage}"
myPage = Page.find_by_url(pPage+"/"+cSlug)
myPage.parts.clear
nparts=parts.size
0.upto(nparts-1) do |i|
myPage.parts.create(
:content => contents[i],
:name => parts[i],
:filter_id => filter)
end
myPage.update
puts "Finished Updating"
end
def createPage(pPage,cPage,cSlug)
puts "Adding Page #{pPage}/#{cPage}"
parent=Page.find_by_url(pPage)
child = parent.children.create(
:title => cPage.capitalize,
:breadcrumb => cPage,
:slug => cSlug,
:status_id => "100")
child.save!
end
def checkForPage(pPage,cPage,cSlug)
child= Page.find_by_url(pPage+"/"+cSlug)
neClass=child.class
if neClass==FileNotFoundPage
createPage(pPage,cPage,cSlug)
end
end
year=ARGV[0]
month=ARGV[1]
service=ARGV[2]
product=ARGV[2]
# check and create reports page
case service
when "Monitoring"
service=service+"/Highlights/"
when "Prediction"
service=service+"/Outlook/"
when "ISV"
service="Monitoring/Analysis/"+service+"/CurrentStatus/"
when "Drought"
service="Monitoring/Analysis/"+service+"/CurrentStatus/"
end
# For each part of the services string delimited by "/"
# check for existence, if not create the page
servicePages = service.split("/")
pPage="/services"
servicePages.each do |service|
servLow=service.downcase
cPage=service
cSlug=servLow
checkForPage(pPage,cPage,cSlug)
pPage=pPage+"/"+servLow
end
# check and create reports/YYYY page
cPage=year
cSlug=cPage
checkForPage(pPage,cPage,cSlug)
body=<<END_OF_BODY
<r:children:first>
<r:content />
</r:children:first>
END_OF_BODY
sidebar=<<END_OF_SIDEBAR
<div class="box"><div class="linklist">
<h3> Archives By Month </h3>
<r:children:each order="desc">
<r:link/>
</r:children:each>
</div></div>
<r:find url="#{pPage}">
<r:content part="sidebar" />
</r:find>
END_OF_SIDEBAR
parts=["body","sidebar"]
contents=[body,sidebar]
filter=""
updateContents(pPage,cPage,cSlug,filter,parts,contents)
# check and create reports/YYYY/MON page
pPage=pPage+"/"+cSlug
cPage=month
cSlug=(months.index(month) + 1).to_s
checkForPage(pPage,cPage,cSlug)
# check this directory and upload text files and image files separately
product="/Reports/#{product}/#{year}/#{month}"
prodDir=File.dirname(__FILE__)+"/../public/#{product}"
allFiles=`ls #{prodDir}`.split
txtFiles=[]
allFiles.each { |a| txtFiles.push([a]) unless File.extname(a)==".png"}
exit if txtFiles.size==0
exit if txtFiles.size>1
imgFiles=[]
allFiles.each { |a| imgFiles.push([a]) if File.extname(a)==".png"}
exit if imgFiles.size==0
txtFile=txtFiles.first.join
content=File.read(prodDir+"/"+txtFile)
txt=<<END_OF_TXT
<r:content part="image" />
END_OF_TXT
content=content + "\n"+ txt
img_describe=""
parts=["body","image"]
contents=[content,img_describe]
filter="Maruku"
updateContents(pPage,cPage,cSlug,filter,parts,contents)
# ------- %< end of code
* Mohit Sindhwani <[EMAIL PROTECTED]> [2007-12-19 23:59:41 +0800]:
> I'm resurrecting an old thread just before starting to look at it
> myself. I'm likely to work on a project where it will be needed to
> update a large number of pages. I think it may be possible to dump the
> content out to a bunch of files from where it should be possible to pick
> up the pages, add the usual stuff and update the pages to a Radiant site
> using a script.
>
> Is there anyone doing so using the script below or something similar?
> Would it be possible to share?
>
> I've never used script/runner with a live site but I'm willing to look
> at the relevant stuff in the Rails world to make that happen. But I'm
> just starting to wonder how to keep this site scalable (since it
> involves the migration of about 7 books from PDF to Radiant) with a
> bunch of relatively standard things to be included on each page.
>
> Thanks,
> Mohit.
> 12/19/2007 | 11:58 PM.
>
>
>
> Sean Cribbs wrote:
> > Saji,
> >
> > You might try using "create" instead of "build". In that case, it could
> > look like this:
> >
> > parent = Page.find_by_url('/services/news')
> > child = parent.children.create(:title => "Floods", :breadcrumb =>
> > "Floods", :slug => "floods")
> > child.parts.create(:name => "body", :content => "This is a page for
> > flood news")
> >
> > Keep in mind that create and build might not work if the collection is
> > empty or the original object is unsaved [1]. Your other alternative is
> > to build the objects manually, then push it into the collection:
> >
> > parent = Page.find_by_url('/services/news')
> > child = Page.new(:title => "Floods", :breadcrumb => "Floods", :slug =>
> > "floods")
> > part = PagePart.new(:name => "body", :content => "This is a page for
> > flood news")
> > parent.children << child
> > child.parts << part
> >
> > Also note in your second snippet that your part needs a name.
> >
> > Sean
> >
> > [1]
> > http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html#M000642
> >
> > (if I'm interpreting the doc correctly)
> >
> > Saji Njarackalazhikam Hameed wrote:
> >
> >> Dear All,
> >>
> >> Thanks for the kind lessons on how to add a page using script/runner. I
> >> have the following working script to create such a new page:
> >>
> >> # ------ start of script to add a new page ---
> >>
> >> parent = Page.find_by_url('/services/news')
> >> child = parent.children.build(:title => "Floods",
> >> :breadcrumb => "Floods", :slug => "floods")
> >> child.parts.build(:content => "This is a page for flood news",
> >> :name => "body")
> >> child.save!
> >>
> >> # ------ end of script to add a new page ---
> >>
> >> How may I update the contents using script/runner? I have tried
> >> the following, but it does not work. Any help to solve this
> >> would be much appreciated.
> >>
> >> # ---- test script that does not work
> >>
> >> floods = Page.find_by_url('/services/news/floods')
> >> floods.parts.build(:content => "This is now for droughts")
> >> floods.update
> >>
> >> thanks in advance,
> >>
> >> saji
> >>
> >> _______________________________________________
> >> Radiant mailing list
> >> Post: [email protected]
> >> Search: http://radiantcms.org/mailing-list/search/
> >> Site: http://lists.radiantcms.org/mailman/listinfo/radiant
> >>
> >>
> >>
> >
> > _______________________________________________
> > Radiant mailing list
> > Post: [email protected]
> > Search: http://radiantcms.org/mailing-list/search/
> > Site: http://lists.radiantcms.org/mailman/listinfo/radiant
> >
> >
> >
>
>
> _______________________________________________
> Radiant mailing list
> Post: [email protected]
> Search: http://radiantcms.org/mailing-list/search/
> Site: http://lists.radiantcms.org/mailman/listinfo/radiant
--
Saji N. Hameed
APEC Climate Center +82 51 668 7470
National Pension Corporation Busan Building 12F
Yeonsan 2-dong, Yeonje-gu, BUSAN 611705 [EMAIL PROTECTED]
KOREA
_______________________________________________
Radiant mailing list
Post: [email protected]
Search: http://radiantcms.org/mailing-list/search/
Site: http://lists.radiantcms.org/mailman/listinfo/radiant