Пример #1
0
    def default(self, path):
        """
        Main Page - redirects to most current election
        """
        headers = {}
        headers['Content-Type'] = 'text/html; charset=utf-8'
        output = []
        addline = output.append

        query = sql.text("""
            select max(election_id) as max_id
            from elections
            limit 1
            """, bind=sql.engine
        )
        rs = query.execute().fetchall()
        if len(rs) > 0:
            raise web.seeother('/election/%s' % (rs[0].max_id))

        raise web.seeother('/elections')
Пример #2
0
def get_apidoc_page(path):
    """
    Returns API Documentation.
    """
    section = 'Site Notes'
    title = 'API Documentation'
    description = 'Documentation on how to use the RTH Elections API.'
    output = []
    addline = output.append

    query = sql.text("""
        select content, last_updated
        from election_apidoc
        order by doc_id desc
        limit 1
        """, bind=sql.engine
    )
    rs = query.execute().fetchall()
    if len(rs) == 0:
        addline('Sorry, but the API documentation is not currently available.')

    else:
        addline(rs[0].content)
        addline('\n*Last Updated: %s*' % (rs[0].last_updated))
        content = markdown('\n'.join(output))
        toc = pytoc.Toc(html_in=content)
        toc.make_toc()
        full_content = '%s\n%s' % (toc.html_toc, toc.html_out)

    template = t.default
    template = template.replace('[[date]]', get_date())
    template = template.replace('[[time]]', get_time())
    template = template.replace('[[title]]', title)
    template = template.replace('[[section]]', section)
    template = template.replace('[[description]]', description)
    template = template.replace('[[content]]', full_content)
    return title, template
Пример #3
0
 def text(self, text, *args, **kwargs):
     """returns a sql.text() object for performing literal queries."""
     return sql.text(text, engine=self, *args, **kwargs)
Пример #4
0
                    );
"""
conn = sql.im_db_engine.connect()
conn.execute(create_db)
conn.execute("""USE solutions;""")
conn.execute(drop_tables)

conn.execute(schema_countries)
conn.execute(schema_regions)
conn.execute(schema_cities)

with open('countries.json') as fc:
    countries_json = json.load(fc)
    conn.execute(
        sql.text("""
        INSERT INTO `countries` (id, alpha2, alpha3, name, targetable) VALUES
        (:id, :alpha2, :alpha3, :name, :targetable);
    """), *countries_json)

with open('regions.json') as fr:
    regions_json = json.load(fr)
    conn.execute(
        sql.text("""
        INSERT INTO `regions` (id, country_id, name, iso_code) VALUES
        (:id, :country_id, :name, :iso_code);
    """), *regions_json)

with open('cities.json') as fct:
    cities_json = json.load(fct)
    conn.execute(
        sql.text("""
        INSERT INTO `cities` (id, country_id, region_id, name, iso_code) VALUES
Пример #5
0
def all_city_info(city_name):
    res = sql.conn.execute(sql.text(q), {'city_name': city_name}).fetchone()
    return dict(res)
Пример #6
0
    'state': r.state
} for r in results]

print("Rows to insert: ")
print(rows_to_insert)

sql_conn = sql.conn

sql_conn.execute("""CREATE TABLE IF NOT EXISTS max_min_temp_by_state (
                    min_temp DECIMAL(12,5),
                    max_temp DECIMAL(12,5),
                    state VARCHAR(255)
                );""")

table = 'max_min_temp_by_state'
sql_conn.execute("DELETE FROM {};".format(table))

sql_conn.execute(
    sql.text("""
    INSERT INTO `max_min_temp_by_state` (min_temp, max_temp, state) VALUES (:min_temp, :max_temp, :state);
"""), *rows_to_insert)

res = sql_conn.execute("""
    SELECT * FROM `max_min_temp_by_state`;
""").fetchall()

print("Inserted the rows: ")
print(res)

sql_conn.close()