[Tutor] screen scraping web-based email

2007-04-18 Thread James Cunningham
Hello. I've been playing with Python for a while, and even have some
small scripts in my employ, but I have a bit of a problem and I'm not
sure how to proceed.

I'm starting graduate school (econ!) in the Fall; the school I'll be
attending uses Lotus for email and allows neither forwarding nor
POP/IMAP access. This is - for many, many reasons - *quite*
unacceptable to me.

I'd like to write a daemon that logs into the text-based web client
every so often, scrapes for new email, and uses smtplib to send that
email to another email address. But I really don't know how I'd go
about logging in and staying logged in without a browser.

Hints are appreciated. Am I wrong-headed about this? Any other options
available to me?

(I know I could do it with a torturous combination of applescript and
python ... but I'd like to avoid that, plus I'd like something
remotely portable.)
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] screen scraping web-based email

2007-04-18 Thread James Cunningham
On Wed, 18 Apr 2007 12:15:26 -0400, Kent Johnson wrote:
> James Cunningham wrote:
> 
>> I'd like to write a daemon that logs into the text-based web client
>> every so often, scrapes for new email, and uses smtplib to send that
>> email to another email address. But I really don't know how I'd go
>> about logging in and staying logged in without a browser.
>> 
>> Hints are appreciated. Am I wrong-headed about this? Any other options
>> available to me?
> 
> This might be a starting point:
> http://pywebmail.sourceforge.net/
> 
> Otherwise mechanize and Beautiful Soup will give you some high-level 
> tools to get started with:
> http://wwwsearch.sourceforge.net/mechanize/
> http://www.crummy.com/software/BeautifulSoup/
> 
> Kent


pywebmail sounds great, and mechanize is actually just what I was 
looking for. Thanks a lot, especially for the quick response!

Best,
James
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] review of beginner's code requested

2006-11-14 Thread James Cunningham
Hello.
I'm new to Python; for a project to get to know the language I wrote up an api for representing finite topologies, and for subsets of topologies for which the orbit (the number of ways to use closure, interior, and complement operators to get separate sets) is fourteen.
It can be used like this:
some_set = [[1, 2, 3], [1, 2], [2, 3], [1, 3], [1], [2], [3], []]a = FiniteTopology(some_set, [1, 2, 3])
...
With all attendant methods. The constructor will take a list of lists or a set of sets.
orbits_of_fourteen(8)
will generate all topologies on subsets of [1, 2, 3, 4, 5, 6, 7, 8], and look for subsets of those topologies whose orbits are of length fourteen. (It will also never end. I wouldn't recommend trying that; I put it in as an exercise.)
One thing I'm not sure of: if the user tries to create a FiniteTopology with a collection of sets that's not a topology, I throw a NotATopologyError in the constructor. But it looks like the FiniteTopology instance is still created. Is there any way to keep the instance from being created at all?
I'm also interested in tips about documentation and style.
Thanks a lot!
Best,James
#!/usr/bin/env python
class NotATopologyError(Exception):
    passclass FiniteTopology(object):
    """This represents a finite topology on a set of elements that can be    represented by Python's builtin set class. Its representation is of a set
    of frozensets, but its constructor will take a list of lists; let it be
    stressed that the elements on which the topology is defined must be    immutable."""
    def __init__(self, topology, main_set):        """Creates an instance of FiniteTopology, checking first to make sure
        that it *is* a topology. If it isn't, we raise a NotATopology        exception."""
        self.topology = set([frozenset(element) for element in topology])
        self.main_set = set(main_set)
        if not self._is_a_topology():            raise NotATopologyError()
    def get_topology(self):        return self.topology
    def _is_a_topology(self):        """Checks if self.topology
 is a topology."""        check_one = self._check_contains_empty_main()
        check_two = self._check_unions()        check_three = self._check_intersections()
        return check_one and check_two and check_three
    def _check_contains_empty_main(self):
        """A topology contains its set and the empty set."""
        return self.main_set in self.topology and set([]) in self.topology
    def _check_unions(self):        """A topology contains all unions of open sets."""
        for i in xrange(1, len(self.topology) + 1):            for subset in combinations(self.as_list(), i):
                current_union = set()                for one_set in subset:
                    current_union = current_union.union(one_set)                if not current_union in self.topology:
                    return False        return True
    def _check_intersections(self):        """A topology contains all pairwise intersections of open sets."""
        for item in self.topology:            for next_item in self.topology
:                intersect = set(item).intersection(next_item)                if not intersect in 
self.topology:                    return False        return True
    def as_list(self):        """Returns a list representation of the topology."""
        return [[i for i in j] for j in self.topology]
    def orbit(self, subset):        """Calculates the maximum number of ways we can use take complements,
        interiors, and closures of a set to make unique sets. There are at        most 14 ways to do this, and usually less."""
        orbit = set()
        complement = self.complement        closure = self.closure        interior = 
self.interior        orbit.add(frozenset(subset))
        orbit.add(frozenset(complement(subset)))        orbit.add(frozenset(complement(interior(subset
        orbit.add(frozenset(complement(interior(complement(subset)        
orbit.add(frozenset(complement(interior(complement(closure(subset))        orbit.add(frozenset(interior(subset)))
        orbit.add(frozenset(interior(closure(subset        orbit.add(frozenset(interior(complement(subset
        orbit.add(frozenset(interior(complement(interior(subset)        orbit.add(frozenset(interior(closure(interior(subset)
        orbit.add(frozenset(interior(closure(interior(complement(subset))        orbit.add(frozenset(closure(subset)))
        orbit.add(frozenset(closure(interior(subset        orbit.add(frozenset(closure(interior(complement(subset)
        return orbit
    def closure(self, subset):        """A limit point p of a set X is such that all open sets containing p
        contain another point of X not equal to p. The closure of a set is the        set plus all of its limit points.
        This finds all of the limit points of the subset and adds them."""
        subset = set(subset)        set_of_lps = set()
        for maybe_lp in self.m

Re: [Tutor] Starting over with Python

2006-12-14 Thread James Cunningham

Sum works just fine, as others have said. A more generic way to do this:

reduce(lambda x, y: x + y, (i for i in range(100) if i % 2))

Reduce iterates through the list, calling x + y on the next element in the
list and the previous sum, in effect summing the whole thing. I might do the
following:

def reduce_list(list, operator):
   return reduce(lambda x, y: operator(x, y), list)

reduce_list((i for i in range(100) if i % 2), int.__add__)
reduce_list((i for i in range(100) if i % 2), int.__mul__)

etc.

best,
james

On 12/13/06, John Carmona <[EMAIL PROTECTED]> wrote:


After quite a while away from Python, I have decided to re-study Python. I
am interested to learn Python to support my love for Cryptography. I have
a
first very easy question (did some search on Google but could not find
anything helpful). I realise that this is very basic so be gentle with me.

If i insert the following script:


-
odd =1
>>>while odd <=100:
if (odd%2)==1:
print odd
odd = odd + 1

-
I get a list of the odd numbers from 1 to 99. But now if I wanted to add
those number together (i.e. 1 + 3 +5 + 7 etc.), what line of coding should
I
include? I have tried to add "odd + odd" but it did not work. In advance
thanks.

If anyone could direct me to some site where python is associated with
Cryptography I would be very grateful. Many thanks
JC

_
Be the first to hear what's new at MSN - sign up to our free newsletters!
http://www.msn.co.uk/newsletters

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor