Esempio n. 1
0
def import_ideas(soup, commit=True):
    print 'Importing ideas...'

    # <table class="bottomline" width="100%">
    rows = soup\
        .find('table', 'bottomline')\
        .find('tbody')\
        .findAll('tr', recursive=False)

    ideas = []
    for i, row in enumerate(rows[:-1]):
        votes, content = row.findAll('td', recursive=False)
        raw = unicode(content)

        # Pull out content first
        title, author, sector = content.findAll('a')[:3]
        idea_id = find_int(title['href'])

        raw_date = sector.nextSibling
        created_at = parse_idea_date(raw_date)

        author = make_author(author)

        sector_id = find_int(sector['href'])
        sector = Sector.get_by_id(sector_id)

        upvotes_el = votes.find('strong')
        upvotes = find_int(upvotes_el.string.strip())

        downvotes = upvotes_el.nextSibling.nextSibling.nextSibling
        downvotes = find_int(str(downvotes).strip())

        views = find_int(re.search(r'(\d+) Views', raw).group(1))
        stage = re.search(r'Stage : (\w+)', raw).group(1)

        # Create the idea
        key = db.Key.from_path('Idea', idea_id)
        idea = Idea(
            key=key,
            author=author,
            sector=sector,
            title=unicode(title.string),
            upvotes=upvotes,
            downvotes=downvotes,
            views=views,
            stage=stage,
            created_at=created_at,
            tags=['Idea'])
        ideas.append(idea)
        print ' - %s by %s' % (idea, author)

    if commit:
        db.put(ideas)

    return ideas
Esempio n. 2
0
 def get_facet(self, facet, criteria):
     return Sector.get_by_id(int(criteria))