Exemplo n.º 1
0
def index():
    """
    Example view demonstrating rendering a simple HTML page.
    """
    incidents_with_age = Incident.select().where(Incident.age > 0).order_by(
        Incident.age.asc())
    incidents_without_age = Incident.select().where(
        Incident.age >> None).order_by(Incident.age.asc())
    incidents = list(incidents_with_age) + list(incidents_without_age)
    states = [
        i.state for i in Incident.select(Incident.state).distinct().order_by(
            Incident.state)
    ]

    def slug(incident):
        uniq = incident.name or 'unknown'

        if (incident.postofficename):
            uniq += '-' + incident.postofficename

        uniq += '-' + incident.state

        return uniq.lower().replace(' ', '-').replace('.',
                                                      '').replace('--', '-')

    return render_template('index.html',
                           incidents=incidents,
                           states=states,
                           slug=slug,
                           **make_context())
Exemplo n.º 2
0
def index():
    """
    Example view demonstrating rendering a simple HTML page.
    """
    incidents_with_age = Incident.select().where(Incident.age > 0).order_by(Incident.age.asc())
    incidents_without_age = Incident.select().where(Incident.age >> None).order_by(Incident.age.asc())
    incidents = list(incidents_with_age) + list(incidents_without_age)
    states = [i.state for i in Incident.select(Incident.state).distinct().order_by(Incident.state)]

    def slug(incident):
        uniq = incident.name or 'unknown'

        if (incident.postofficename):
            uniq += '-' + incident.postofficename

        uniq += '-' +  incident.state

        return uniq.lower().replace(' ', '-').replace('.', '').replace('--', '-')

    return render_template('index.html', incidents=incidents, states=states, slug=slug, **make_context())
Exemplo n.º 3
0
#!/usr/bin/env python

from bs4 import BeautifulSoup
import requests

from models import Incident

url_base = 'http://www.osha.gov/pls/imis/establishment.inspection_detail?id='

for incident in Incident.select():
    if incident.narrative:
        pass
    else:
        try:
            url = url_base + '%s' % incident.inspection_no
            print url
            r = requests.get(url)
            soup = BeautifulSoup(r.content)

            tables = soup.find(id="maincontain").find_all('table',
                                                          bgcolor='white')
            num_matches = len(tables)
            narrative = tables[num_matches - 3].find('td').text.strip()

            print narrative
            query = Incident.update(narrative=narrative).where(
                Incident.inspection_no == incident.inspection_no)
            print query
            query.execute()
        except Exception as error:
            print 'Failed: %s, error is: %s' % (incident.inspection_no, error)
Exemplo n.º 4
0
#!/usr/bin/env python

from bs4 import BeautifulSoup
import requests

from models import Incident

url_base = 'http://www.osha.gov/pls/imis/establishment.inspection_detail?id='

for incident in Incident.select():
    if incident.narrative:
        pass
    else:
        try:
            url = url_base + '%s' % incident.inspection_no
            print url
            r = requests.get(url)
            soup = BeautifulSoup(r.content)

            tables = soup.find(id="maincontain").find_all('table', bgcolor='white')
            num_matches = len(tables)
            narrative = tables[num_matches-3].find('td').text.strip()

            print narrative
            query = Incident.update(narrative=narrative).where(Incident.inspection_no == incident.inspection_no)
            print query
            query.execute()
        except Exception as error:
            print 'Failed: %s, error is: %s' % (incident.inspection_no, error)