Skip to content

Instantly share code, notes, and snippets.

@ochawkeye
Last active October 20, 2015 18:15
Show Gist options
  • Save ochawkeye/dd812022777b2734a316 to your computer and use it in GitHub Desktop.
Save ochawkeye/dd812022777b2734a316 to your computer and use it in GitHub Desktop.
import nfldb
NYGmisc = {}
db = nfldb.connect()
qNYG = nfldb.Query(db)
for gp in qNYG.play_player(team='NYG').player(position='TE').as_aggregate():
# NYGmisc[gp.player] = gp <-- if you do like this, the values are class 'nfldb.query.AggPP'
NYGmisc[gp.player] = {field: getattr(gp, field) for field in gp.fields} # but if you do like this they are type 'dict'
for x in NYGmisc:
print type(x), type(NYGmisc[x])
@ochawkeye
Copy link
Author

<class 'nfldb.types.Player'> <type 'dict'>
<class 'nfldb.types.Player'> <type 'dict'>
<class 'nfldb.types.Player'> <type 'dict'>
<class 'nfldb.types.Player'> <type 'dict'>
<class 'nfldb.types.Player'> <type 'dict'>
<class 'nfldb.types.Player'> <type 'dict'>
<class 'nfldb.types.Player'> <type 'dict'>

@chppppp
Copy link

chppppp commented Oct 20, 2015

this worked for me:

    NYGmisc = { }
    for gp in qNYG.play_player(team='NYG').player(position='TE').as_aggregate():
      NYGmisc[gp.player] = {field: getattr(gp, field) for field in gp.fields}
    for x in NYGmisc:
      for y in NYGmisc[x].iteritems():
        print y
    @app.route("/")
    def main():
        return render_template('index.html',thing10=NYGmisc)

and in my index.html template:

             <h4>nyg</h4>
                <p> <table>
                      {% for key in thing10 %}
                   <tr>
                   <th> {{ key }}  </th>
                        {% for ke in thing10[key].iteritems() %} 
                   <td>   {{ ke }}  </td>
                   </tr>
                        {% endfor %} 
                      {% endfor %}
                </table>  </p> 

This displays the data I want.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment