An example of turning some simple code into an API

mattseh

import this
Apr 6, 2009
5,504
72
0
A ~= A
https://github.com/stirt/FootballScores/blob/master/app.py

I guided a friend through making this yesterday, I know the code isn't perfect, but it might give people some ideas.

It was made in an hour, from a starting point of my friend not knowing heroku or flask-classy, with just a generic python class that pulled JSON from the BBC.

tl;dr: use the right tools, you can make something quickly that is easy to extend (methods like league and team) and will host with zero cost and little work, and should be able to take lots of hits per second, due to caching.
 


LEVEL UP:

And when their isn't a nice JSON to grab: DIY! Run Scrapy in server mode, scrape sites and serve your own JSON to the code above.
 
Hey I'm having some trouble understanding the code, can you help?

1) Don't Ruby scripts usually end in .rb?
2) These football stats don't seem to match up with the NFL scores this year so far?

thx bro
 
Hey I'm having some trouble understanding the code, can you help?

1) Don't Ruby scripts usually end in .rb?
2) These football stats don't seem to match up with the NFL scores this year so far?

thx bro

stirton, stirtoff.
 
I started porting this to Sinatra but got too lazy to look up Python's API.

Like why it has so many __underscores__ and why you use tabs instead of spaces and why I had to horizontally scroll to see all the code.

Just kidding, you lost me at app.py.

9a.png


But honestly, I love making simple Sinatra apps in the same spirit as this.
 
I started two different projects with Flask-classy, and it works OK for some stuff, but in the end I didn't feel it really added any significant value. In fact I felt I had to do too much coding around it, and ripped it out of both projects after a while.

I'm sure some people will find it useful though, I think it's kind of cool for more simple web apps.
 
I started two different projects with Flask-classy, and it works OK for some stuff, but in the end I didn't feel it really added any significant value. In fact I felt I had to do too much coding around it, and ripped it out of both projects after a while.

I'm sure some people will find it useful though, I think it's kind of cool for more simple web apps.

not enough rage, -rep
 
not enough rage, -rep

I know you where waiting for something like this:

FUCKING FLASK WAS GREAT WITHOUT BEING ALL LIKE, "I NEED TO WRITE A FUCKING CLASS BECAUSE I JUST CAN'T GET ENOUGH OF CLASSES!"

+rep me bitch.
 
I know you where waiting for something like this:

FUCKING FLASK WAS GREAT WITHOUT BEING ALL LIKE, "I NEED TO WRITE A FUCKING CLASS BECAUSE I JUST CAN'T GET ENOUGH OF CLASSES!"

+rep me bitch.

moar -rep for only moderate rage.

On the rage scale, I'd say you're about Rage7 right now.