home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyo (Python 2.5)
-
- from __future__ import with_statement
- from util import callsback, threaded, pythonize, do, soupify, traceguard, odict, scrape_clean
- from util.BeautifulSoup import BeautifulStoneSoup
- from itertools import izip
- from logging import getLogger
- log = getLogger('yahooprofile')
- from threading import Thread
- import wx
- from urllib2 import urlopen
- profile_url = 'http://profiles.yahoo.com/%s?warn=1'
-
- def get(yahooid):
- data = urlopen(profile_url % yahooid).read().decode('utf-8')
- return scrape_profile(data)
-
- get = threaded(get)
-
- def scrape_profile(s):
- s = s.replace(u' ', u' ').replace(u'Hobbies:</dd>', u'Hobbies:</dt>')
- soup = BeautifulStoneSoup(s, convertEntities = BeautifulStoneSoup.ALL_ENTITIES, fromEncoding = 'utf-8')
- profile = odict()
- for section in ('basics', 'more'):
- div = soup('div', id = 'ypfl-' + section)[0].dl
- if div is not None:
- info = _[1]
- profile.update(dictfrompairs(info))
- continue
- []
-
- links = [](_[2])
- linktuples = _[3]
- finallinks = []
- for i, tuple in enumerate(linktuples):
- finallinks.append(tuple)
- if i != len(linktuples) - 1:
- finallinks.append(u'\n')
- continue
- []
-
- links['Links:'] = finallinks
- (do,)((lambda .0: for k in .0:
- if k.startswith('Cool Link'):
- links.pop(k)continue)(links.keys()))
- profile.update(links)
- for p in soup.findAll('p', attrs = {
- 'class': 'footnote' }):
- c = p.renderContents(None)
- for hdr in ('Member Since ', 'Last Update: '):
- if c.startswith(hdr):
- profile[hdr] = c[len(hdr):]
- continue
- []
-
-
- for k, v in dict(profile).iteritems():
- if isinstance(v, basestring):
- [] if 'Home Page:' in links else dictfrompairs(dict.__setitem__, profile, k if v.strip() in ('', 'No Answer') else scrape_clean(v))
- continue
-
- profile.pop('Yahoo! ID:', None)
- return profile
-
-
- def dictfrompairs(info):
- return dict(izip(info[::2], info[1::2]))
-
-
- def anchor2tuple(s):
- if not s:
- return None
-
- a = soupify(s).a
- return None if a else None
-
-