The Artima Developer Community
Sponsored Link

Agile Buzz Forum
More Fun with BottomFeeder

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
James Robertson

Posts: 29924
Nickname: jarober61
Registered: Jun, 2003

David Buck, Smalltalker at large
More Fun with BottomFeeder Posted: Feb 20, 2005 3:50 PM
Reply to this message Reply

This post originated from an RSS feed registered with Agile Buzz by James Robertson.
Original Post: More Fun with BottomFeeder
Feed Title: Cincom Smalltalk Blog - Smalltalk with Rants
Feed URL: http://www.cincomsmalltalk.com/rssBlog/rssBlogView.xml
Feed Description: James Robertson comments on Cincom Smalltalk, the Smalltalk development community, and IT trends and issues in general.
Latest Agile Buzz Posts
Latest Agile Buzz Posts by James Robertson
Latest Posts From Cincom Smalltalk Blog - Smalltalk with Rants

Advertisement

After this post yesterday, I thought I'd take a shot at generalizing and extnding the ad-hoc search script. So, I came up with this set of code:

First, a block that defines a "reporting" function


"creates an HTML report for the pattern match"
htmlReportBlock := [:collection | | stream out |
stream := WriteStream on: (String new: 10000).
stream nextPutAll: '<html><body'; cr; cr.
stream nextPutAll: '<p><b>Amazon Reference Report</b></p><p>'; cr; cr.
stream nextPutAll: '<table width="100%">'; cr; cr.
stream nextPutAll: '<tr>'; cr.
collection do: [:each |
	| key value |
	key := each key.
	value := each value.
	stream nextPutAll: '<td><a href="',  key link, '">', key title, '</a></td>'; cr.
	stream nextPutAll: '<td>'.
	stream nextPutAll: value size printString.
	stream nextPutAll: '&nsbp;&nsbp;('.
	1 to: value size do: [:cnt | | each1 |
		each1 := value at: cnt.
		each1 getMyLink isNil
			ifFalse: [	stream nextPutAll: '<a href="', each1 getMyLink, '">', cnt printString, '</a>&nsbp;'].
					cnt = value size
						ifFalse: [stream nextPutAll: ',&nsbp;']].
		stream nextPutAll: ')'.
	stream nextPutAll: '</td></tr><tr>'; cr].
stream nextPutAll: '</table></p>'; cr.
stream nextPutAll: '</body></html>'.
out := 'bookReport.html' asFilename writeStream.
out nextPutAll: stream contents.
out close].

That gave me a reusable block of code for simple reports. Well, marginally reusable :). Next, the basic search function, now with an inbound search string:


"execute with an inbound pattern, answers the matches"
matchItemsBlock := [:pattern  |
	| amazonCollection  matches |
	amazonCollection := SortedCollection new sortBlock: [:a :b | a value size > b value size].
	RSSFeedManager default getAllMyFeeds do: 
	[:each | | items |
		items := each allItems.
		matches := items select:
			 [:eachItem | | desc |
				desc := eachItem description.
				desc 
					ifNil: [false]
					ifNotNil: [pattern match: desc]].
		matches notEmpty ifTrue: [amazonCollection add: each->matches]].
		amazonCollection].

Now, notice how that block has the resulting collection by itself on the last line? That's because blocks, by default, return the result of the last expression. Thus, we need to make sure that it does. Now that we have our functions defined, we can try them out:


"look for matching books, then report on it"
| matches |
matches := matchItemsBlock value: '*href*amazon*asin*'.
htmlReportBlock value: matches.

That will first gather the matches, and then execute the HTML report. We can then look at in a browser, post it to a blog... whatever. What if we wanted to track book references across all of our feeds and items on an ongoing basis? Well, there's a scripting plugin for BottomFeeder - so I can create a simple script that makes use of these functions to create a local feed:


"create a local RSS feed for this search"
| matches |
matches := matchItemsBlock value: '*href*amazon*asin*'.
out := 'bookReport.xml' asFilename writeStream.
matches := matchItemsBlock value: '*href*amazon*asin*'.
[writer := RSS20_SAXWriter new output: out.
writer prolog.
writer startRSS.
writer startChannel.
writer title: 'Amazon Book Report'.
writer description: 'Amazon Book Report for:', Core.Date today printString.
writer pubDate: Core.Timestamp now.
matches do: [:each |
	|  items |
	items := each value.
	items do: [:eachItem |
		writer startItem.
		writer link: eachItem link.
		writer title: eachItem title.
		writer guid: eachItem guid.
		writer pubDate: eachItem pubDateString.
		writer description: eachItem description.
		writer category: eachItem category.
		writer author: eachItem author.
		writer endItem]].
writer endChannel.
writer endRSS]
	ensure: [out close].

If I stick that in my "scripts" directory, I can use the script tool to add it to the set of running scripts. Now I can add this feed to BottomFeeder via a file URL, and have immediate access to all book referencing items. Pretty neat.

Read: More Fun with BottomFeeder

Topic: SOAP - more like CORBA every day Previous Topic   Next Topic Topic: A nice wake up call

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use