Popular recipes by Bill Bell http://code.activestate.com/recipes/users/98151/2008-05-07T17:33:26-07:00ActiveState Code RecipesDate & time RFC822 formatted for RSS2, etc (straw man) (Python)
2008-05-07T17:33:26-07:00Bill Bellhttp://code.activestate.com/recipes/users/98151/http://code.activestate.com/recipes/572190-date-time-rfc822-formatted-for-rss2-etc-straw-man/
<p style="color: grey">
Python
recipe 572190
by <a href="/recipes/users/98151/">Bill Bell</a>
(<a href="/recipes/tags/algorithms/">algorithms</a>).
</p>
<p>I live in a geographical area whose daylight savings time provisions seem to fool software. I would therefore like to avoid mentioning time zone when I create a timestamp in RFC822 format. I have looked for but could not find an elegant way of expressing what I want. In hopes that someone will see this and be aghast at my ignorance, then provide something nice, I humbly offer the following.</p>
<p>It takes a datetime and gives back an RFC822 timestamp (I think).</p>
Is scraping easiest with Internet Explorer on Windows? (Python)
2006-06-10T15:32:40-07:00Bill Bellhttp://code.activestate.com/recipes/users/98151/http://code.activestate.com/recipes/496789-is-scraping-easiest-with-internet-explorer-on-wind/
<p style="color: grey">
Python
recipe 496789
by <a href="/recipes/users/98151/">Bill Bell</a>
(<a href="/recipes/tags/web/">web</a>).
</p>
<p>Used in conjunction with Mozilla's "DOM Inspector" and Mozilla's "View | Page Source" and (say) PythonWin, the parser component of IE can make scraping fairly easy in large part because the parse tree that it produces is rigorously self-similar from root to leaf. Here's an example that parallels the one offered for ScrapeNFeed.</p>
Refreshing the Windows Desktop -- New Help for the Absent-minded (Python)
2005-04-30T10:21:46-07:00Bill Bellhttp://code.activestate.com/recipes/users/98151/http://code.activestate.com/recipes/412808-refreshing-the-windows-desktop-new-help-for-the-ab/
<p style="color: grey">
Python
recipe 412808
by <a href="/recipes/users/98151/">Bill Bell</a>
(<a href="/recipes/tags/ui/">ui</a>).
</p>
<p>Script that rewrites a to-do list on the Windows Active Desktop and then refreshes the display.</p>
Using ctypes to manipulate Windows registry and to register DLLs (Python)
2004-06-22T13:32:10-07:00Bill Bellhttp://code.activestate.com/recipes/users/98151/http://code.activestate.com/recipes/286159-using-ctypes-to-manipulate-windows-registry-and-to/
<p style="color: grey">
Python
recipe 286159
by <a href="/recipes/users/98151/">Bill Bell</a>
(<a href="/recipes/tags/sysadmin/">sysadmin</a>).
Revision 2.
</p>
<p>Indicates the essentials of creating keys, or otherwise manipulating the Windows registry, using ctypes; also of registering a DLL.</p>
<p>Hurrah for ctypes!</p>
How to Connect to an Already Running Instance of Internet Explorer (Python)
2004-06-13T23:03:49-07:00Bill Bellhttp://code.activestate.com/recipes/users/98151/http://code.activestate.com/recipes/269345-how-to-connect-to-an-already-running-instance-of-i/
<p style="color: grey">
Python
recipe 269345
by <a href="/recipes/users/98151/">Bill Bell</a>
(<a href="/recipes/tags/web/">web</a>).
Revision 2.
</p>
<p>Various sources (but principally Hammond and Robinson) show how to instantiate Internet Explorer in order to have access to its interfaces. However, few places show how to connect to an instance that is already running, which is so easy in VB.</p>
<p>Thanks are due to someone called "gcash" for this idea. See <a href="http://dbforums.com/t867088.html." rel="nofollow">http://dbforums.com/t867088.html.</a></p>
<p>It just seemed to me that this is a good recipe to have in this collection as a reference to a certain approach, rather than as a full solution.</p>
Extract text from XML document, II (Python)
2004-03-21T09:51:34-08:00Bill Bellhttp://code.activestate.com/recipes/users/98151/http://code.activestate.com/recipes/275370-extract-text-from-xml-document-ii/
<p style="color: grey">
Python
recipe 275370
by <a href="/recipes/users/98151/">Bill Bell</a>
(<a href="/recipes/tags/xml/">xml</a>).
</p>
<p>Alternative way of extracting text from a WF XML source.</p>
Accepting Four Points in 2-space (Python)
2004-03-10T06:47:51-08:00Bill Bellhttp://code.activestate.com/recipes/users/98151/http://code.activestate.com/recipes/273592-accepting-four-points-in-2-space/
<p style="color: grey">
Python
recipe 273592
by <a href="/recipes/users/98151/">Bill Bell</a>
(<a href="/recipes/tags/graphics/">graphics</a>).
</p>
<p>Photographic document images are often rotated, if only slightly. This code mediates an input of a series of four points--assumed to be the corners of a rectangular document--in any order, as mouse clicks. Then it determines the orientation of the points and calculates a "quality" value, as an indication to the user of how well the four points s/he has chosen approximate to the corners of a rotated rectangle. Finally, it makes the information that it has been passed, or that it has been able to glean, available to the script that invoked it.</p>
HTML Page Scraping (of the Quick and Dirty Variety) (Python)
2003-12-31T17:43:07-08:00Bill Bellhttp://code.activestate.com/recipes/users/98151/http://code.activestate.com/recipes/259143-html-page-scraping-of-the-quick-and-dirty-variety/
<p style="color: grey">
Python
recipe 259143
by <a href="/recipes/users/98151/">Bill Bell</a>
(<a href="/recipes/tags/web/">web</a>).
Revision 2.
</p>
<p>This recipe is really about using previously identified information in a web page--ie, state information--to decide how to use newly identified information. To view a page of the kind that can be scraped using the code below visit
<a href="http://www.archives.ca/02/02012202_e.html" rel="nofollow">http://www.archives.ca/02/02012202_e.html</a>
select "Ontario", enter "Cornwall" in the Geographic Location box, and select "MAX" in the Number of References per page list.</p>
<p>Two kinds of document images are offered within each page served by the census site, namely, schedule 1 document images and schedule 2. Only the schedule 1
documents provide information in which I have an interest at present (namely surnames, birthdates, etc). I would, therefore, like to extract information that identifies schedule 1 images and ignore the others.</p>
<p>Put in terms of state, when my script notices that it has most recently seen HTML code indicating schedule 1 I want it to extract information in the URLs in the "option" tags; when it has found schedule 2 I want it to ignore the URLs. It might be that one of the simplest ways of doing this is to form a regular expression (RE) that alternates one RE that recognises schedule numbers and one RE that recognises the URLs, then use this whole RE with a "sub" function so that the matches can be processed in a purpose-built function.</p>
<p>Incidentally, I have found that Phil Schwartz' "Kodos" Python Regex Debugger makes it a lot faster to create and check REs. Many thanks, Phil!</p>
Choose a random k-subset of {1,2, ..., n} (Python)
2002-10-13T09:37:05-07:00Bill Bellhttp://code.activestate.com/recipes/users/98151/http://code.activestate.com/recipes/156453-choose-a-random-k-subset-of-12-n/
<p style="color: grey">
Python
recipe 156453
by <a href="/recipes/users/98151/">Bill Bell</a>
(<a href="/recipes/tags/algorithms/">algorithms</a>).
</p>
<p>This is a translation of the Fortran subroutine RANKSB which appears on pp 38-9 of Nijenhuis & Wilk (1975) Combinatorial Algorithms, Academic Press.</p>
Barebones VC++ code: invoking Python COM factory and factory-made COM object (Python)
2002-07-27T11:44:45-07:00Bill Bellhttp://code.activestate.com/recipes/users/98151/http://code.activestate.com/recipes/141602-barebones-vc-code-invoking-python-com-factory-and-/
<p style="color: grey">
Python
recipe 141602
by <a href="/recipes/users/98151/">Bill Bell</a>
(<a href="/recipes/tags/extending/">extending</a>).
</p>
<p>Two items:</p>
<ol>
<li>Python script that defines and registers a factory COM class and another COM class that can be instantiated by the factory.</li>
<li>(Ugly) VC++ code that exercises the factory and then the object returned by the factory.</li>
</ol>
<p>The Python COM object returned by the factory provides rudimentary stemming; ie, it removes any final 's' from a word that is passed to it and returns the truncated word as its result.</p>
Using MSHTML to Parse HTML (Python)
2002-06-26T13:28:46-07:00Bill Bellhttp://code.activestate.com/recipes/users/98151/http://code.activestate.com/recipes/135702-using-mshtml-to-parse-html/
<p style="color: grey">
Python
recipe 135702
by <a href="/recipes/users/98151/">Bill Bell</a>
(<a href="/recipes/tags/web/">web</a>).
</p>
<p>MSHTML is the COM component used by Internet Explorer to parse HTML pages (since version 4 of IE). It can be used independently of IE as shown here.</p>
Simple Application of htmllib for Parsing HTML (Python)
2002-06-22T06:36:40-07:00Bill Bellhttp://code.activestate.com/recipes/users/98151/http://code.activestate.com/recipes/135005-simple-application-of-htmllib-for-parsing-html/
<p style="color: grey">
Python
recipe 135005
by <a href="/recipes/users/98151/">Bill Bell</a>
(<a href="/recipes/tags/web/">web</a>).
</p>
<p>Shows: how to derive a class from NullWriter that accumulates text from the body of an HTML page, how to derive a class from HTMLParser that retains metatag information, how to instantiate these classes and display a typical result of using them.</p>
Using RegObj: Automation access to the MSW Registry (Python)
2002-07-03T11:10:38-07:00Bill Bellhttp://code.activestate.com/recipes/users/98151/http://code.activestate.com/recipes/137551-using-regobj-automation-access-to-the-msw-registry/
<p style="color: grey">
Python
recipe 137551
by <a href="/recipes/users/98151/">Bill Bell</a>
(<a href="/recipes/tags/sysadmin/">sysadmin</a>).
</p>
<p>RegObj is an ActiveX server for registry manipulation that can be driven using Python. Its object model provides significant advantages over the use of the
registry API.</p>
Returning results from the XML interface at searchhippo.com (Python)
2002-06-23T14:07:20-07:00Bill Bellhttp://code.activestate.com/recipes/users/98151/http://code.activestate.com/recipes/135130-returning-results-from-the-xml-interface-at-search/
<p style="color: grey">
Python
recipe 135130
by <a href="/recipes/users/98151/">Bill Bell</a>
(<a href="/recipes/tags/web/">web</a>).
</p>
<p>Semi-lazy interrogation of <a href="http://searchhippo.com" rel="nofollow">searchhippo.com</a> returns a virtual array of the search engine's records.</p>
Determining if another instance of a script already running in MSW (Python)
2001-08-26T17:41:13-07:00Bill Bellhttp://code.activestate.com/recipes/users/98151/http://code.activestate.com/recipes/67663-determining-if-another-instance-of-a-script-alread/
<p style="color: grey">
Python
recipe 67663
by <a href="/recipes/users/98151/">Bill Bell</a>
.
</p>
<p>A script can use this code to determine whether another instance of itself is already in execution. 32-bit MSW only.</p>
Displaying Decoded Hotkeys for Shortcuts in MSW (Python)
2001-09-04T05:25:11-07:00Bill Bellhttp://code.activestate.com/recipes/users/98151/http://code.activestate.com/recipes/67683-displaying-decoded-hotkeys-for-shortcuts-in-msw/
<p style="color: grey">
Python
recipe 67683
by <a href="/recipes/users/98151/">Bill Bell</a>
.
</p>
<p>The ActiveState Python distribution includes an example that shows how to get and set MSW shortcuts. This code shows how to extend the example to decode the hotkeys (such as 'Alt-Ctrl-Z' and 'Shift-Ctrl-B' that can be associated with shortcuts.</p>