- ๐ Check out my blog!
- โ๏ธย You can contact me at [email protected]
joeyagreco / pymfl Goto Github PK
View Code? Open in Web Editor NEWPython wrapper for the MyFantasyLeague API.
Home Page: https://pypi.org/project/pymfl/
License: MIT License
Python wrapper for the MyFantasyLeague API.
Home Page: https://pypi.org/project/pymfl/
License: MIT License
I just found this library, and it's great. It's saving me a ton of work. As I'm using it, there are two features I want:
Since pymfl uses requests to interact with the MFL API, a relatively small addition to the public interface is enough to make it so that applications can turn on caching (and even set different cache rules per-API) and store cookies between runs.
By adding a requests.Session
parameter (defaulted to None) to the APIConfig.add_config_for_year_and_league_id
and having pymfl hang onto that with the YearAPIConfig
, then having the client base class use that session instead of the raw cookie value, callers who want caching and saving can get it, with no interface changes for callers who don't care about that.
Assuming a caller wants to use requests-cache for caching and a cookiejar from the standard library http.cookies
, caching and saving cookies would then look something like this:
import os
import logging
from pymfl.api.config import APIConfig
from pymfl.api import CommonLeagueInfoAPIClient
import requests_cache
from http.cookiejar import LWPCookieJar
logger = logging.getLogger(__name__)
# This particular sample assumes the configuration data is stored in the environment,
# and the thing that runs this script calls `load_dotenv` from python-dotenv to make it so.
def run():
try:
mfl_user = os.environ["MFL_USER"]
mfl_pass = os.environ["MFL_PASS"]
mfl_league = os.environ["MFL_LEAGUE"]
mfl_ua = os.environ["MFL_USER_AGENT"]
mfl_cache = os.environ["MFL_CACHE"]
mfl_cookies = os.environ["MFL_COOKIES"]
except KeyError as e:
logger.error(f"MFL parameters need to be configured in the environment:", e)
return
# cache things for 24 hours, for now, to prevent abusive requests while iterating in dev
expiration_seconds = 60 * 60 * 24
cookiejar = LWPCookieJar(mfl_cookies)
if os.path.exists(mfl_cookies):
cookiejar.load(ignore_discard=True)
session = requests_cache.CachedSession(cache_name="mfl-cache", expire_after=expiration_seconds)
session.cookies = cookiejar
APIConfig.add_config_for_year_and_league_id(year=2022, league_id=mfl_league, username=mfl_user, password=mfl_pass,
user_agent_name=mfl_ua, session=session)
league_details = CommonLeagueInfoAPIClient.get_league(year=2022, league_id=mfl_league)
cookiejar.save(ignore_discard=True)
print(f"retrieved league details:\n{league_details}")
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.