Repository navigation
Expand file tree
/
Copy pathREADME
More file actions
84 lines (62 loc) · 2.42 KB
/
Copy pathREADME
File metadata and controls
84 lines (62 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
FanFeedr API Python SDK
This is a simple wrapper for accessing the FanFeedr API provided you have registered
for a key at http://developer.fanfeedr.com. To utilize this SDK you will need to
have access to two pieces of data:
1. Your API key
2. The name of the tier you are signed up (basic, bronze, silver, gold)
Installation
----------
Installation is run through setuptools and setup.py. To install this module simply run
the command:
python setup.py install
in the base directory
How to use
----------
Here are a few easy to use use cases for how to use the FanFeedr API Python SDK
First, to get detailed information for all teams in the MLB.
------
from fanfeedr import FanFeedrAPI
ffapi = FanFeedrAPI("your-key", tier="your-tier") #Default basic.
leagues = ffapi.get_collection("leagues")
mlb = None
for league in leagues:
if league["name"] == "MLB":
mlb = league
break
conferences = ffapi.get_collection("conferences", ptype="leagues", puid=mlb["id"])
lmerge = lambda x, y: x+y
divisions = reduce(lmerge, [ffapi.get_collection("divisions",
ptype="conferences",
puid=conference["id"]) for conference in conferences])
teams = reduce(lmerge, [ffapi.get_collection("teams", ptype="divisions", puid=division["id"])
for division in divisions])
teams = map(lambda x: ffapi.get_resource("teams", x["id"]), teams)
print teams
-------
Second, get the hottest news for the Red Sox (using the team data from above)
-----
from fanfeedr import FanFeedrAPI
red_sox = None
for team in teams:
if team["name"] == "Boston Red Sox":
red_sox = team
break
articles = sorted(ffapi.get_collection("content", ptype="teams", puid=red_sox["id"]),
key=lambda x: x["hotness"],
reverse=True)
#Get full info for top 10
articles = [ffapi.get_resource("content", article["id"]) for article in articles[:10]]
print articles
-----
Last, get the next games (in two weeks) for the Red Sox (using the team data from the first example
-----
from fanfeedr import FanFeedrAPI
ffapi = FanFeedrAPI("your-key", tier="your-tier")
red_sox = None
for team in teams:
if team["name"] == "Boston Red Sox":
red_sox = team
break
events = ffapi.get_collection_method("next", "events", ptype="teams", puid=red_sox["id"])
events = [ffapi.get_resource("events", event["id"]) for event in events]
print events