import json
import csv
import requests
from requests.auth import HTTPBasicAuth
import secret

base_url = 'https://www.mysportsfeeds.com/api/feed/pull/nfl/2016-2017-regular/'


def main():
    division_standings()
    playoff_standings()
    playoff_standings()
    player_stats()
    points_for()
    tiebreaker()
    player_score()



# Get Division Standings for each team
def division_standings():
    pass


# Get Playoff Standings for each team (need number 5 & 6 in each conference)
def playoff_standings():
    pass


# Get individual statistics for each category
def player_stats():
    url = base_url + 'cumulative_player_stats.json?playerstats=Yds,Sacks,Int'
    response = requests.get((url),
    auth=HTTPBasicAuth(secret.msf_username, secret.msf_pw))

    all_stats = response.json()
    stats = all_stats["cumulativeplayerstats"]["playerstatsentry"]


# Get points for for the number one team in each conference:
def points_for():
    pass


# Get the tiebreaker information
def tiebreaker():
    pass


# Calculate the player scores
def player_score():
    pass


if __name__ == '__main__':
    main()

@@ -32,16 +32,31 @@
 equests%0A
+import sqlite3%0A
 from req
@@ -873,16 +873,872 @@
 ntry%22%5D%0A%0A
+    for data in stats:%0A        try:%0A            player_id = (data%5B%22player%22%5D%5B%22ID%22%5D)%0A            passyds = (data%5B%22stats%22%5D%5B%22PassYards%22%5D%5B%22#text%22%5D)%0A            rushyds = (data%5B%22stats%22%5D%5B%22RushYards%22%5D%5B%22#text%22%5D)%0A            recyds = (data%5B%22stats%22%5D%5B%22RecYards%22%5D%5B%22#text%22%5D)%0A            sacks = (data%5B%22stats%22%5D%5B%22Sacks%22%5D%5B%22#text%22%5D)%0A            interceptions = (data%5B%22stats%22%5D%5B%22Interceptions%22%5D%5B%22#text%22%5D)%0A#            print (player_id, passyds, rushyds, recyds, sacks, interceptions)%0A        except KeyError:%0A            continue%0A%0A        conn = sqlite3.connect('nflpool.sqlite')%0A        cur = conn.cursor()%0A%0A        cur.execute('''INSERT INTO player_stats(player_id, passyds, rushyds, recyds, sacks, interceptions, season)%0A            VALUES(?,?,?,?, ?, ?, %222016%22)''', (player_id, passyds, rushyds, recyds, sacks, interceptions))%0A%0A        conn.commit()%0A        conn.close()%0A%0A
 %0A# Get p

Add function to import individual player statistics via MySportsFeed API