forked from uberfastman/yfpy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1b1da7e
commit dd65f8e
Showing
13 changed files
with
198 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,12 @@ | ||
auth/private.json | ||
auth/token.json | ||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
|
||
# JetBrains IDE project files | ||
.idea/* | ||
|
||
# Distribution / packaging | ||
.Python | ||
build/ | ||
dist/ | ||
*.egg-info/ |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
certifi==2019.6.16 | ||
chardet==3.0.4 | ||
idna==2.8 | ||
pyaml==19.4.1 | ||
PyYAML==5.1.2 | ||
rauth==0.7.3 | ||
requests==2.22.0 | ||
stringcase==1.2.0 | ||
urllib3==1.25.3 | ||
yahoo-oauth==0.1.9 |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
{ | ||
"consumer_key": "YAHOO_DEVELOPER_APP_CONSUMER_KEY_STRING", | ||
"consumer_secret": "YAHOO_DEVELOPER_APP_CONSUMER_SECRET_STRING" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
yahoo-oauth==0.1.9 | ||
stringcase==1.2.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[metadata] | ||
description-file = README.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import setuptools | ||
|
||
with open("README.md", "r") as docs: | ||
long_description = docs.read() | ||
|
||
with open("requirements.txt") as reqs: | ||
required = reqs.read().splitlines() | ||
|
||
setuptools.setup( | ||
name="yffpy", | ||
version="1.0.0", | ||
author="Wren J. R.", | ||
author_email="wrenjr@yahoo.com", | ||
description="Python API wrapper for the Yahoo Fantasy Football public API.", | ||
long_description=long_description, | ||
long_description_content_type="text/markdown", | ||
url="https://github.com/uberfastman/yffpy", | ||
packages=setuptools.find_packages(), | ||
classifiers=[ | ||
"Programming Language :: Python :: 3", | ||
"Programming Language :: Python :: 3.7", | ||
"License :: OSI Approved :: GNU General Public License v3 (GPLv3)", | ||
"Operating System :: OS Independent", | ||
"Development Status :: 4 - Beta", | ||
"Topic :: Software Development :: Libraries :: Python Modules", | ||
"Environment :: Console", | ||
"Intended Audience :: Developers" | ||
], | ||
python_requires=">=3.5", | ||
install_requires=required | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from yffpy.data import Data | ||
from yffpy.models import User, Game, League, Team, Standings, Manager, RosterAdds, TeamLogo, TeamPoints, TeamStandings, OutcomeTotals, Streak, Settings, RosterPosition, StatCategories, StatModifiers, Stat, StatPositionType, Bonus, Matchup, MatchupGrade, Player, ByeWeeks, Headshot, Name, PlayerPoints, PlayerStats, SelectedPosition | ||
from yffpy.query import YahooFantasyFootballQuery |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import json | ||
import logging | ||
import os | ||
|
||
from yffpy.models import YahooFantasyObject | ||
from yffpy.utils import complex_json_handler, unpack_data | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class Data(object): | ||
|
||
def __init__(self, save_dir): | ||
self.save_dir = save_dir | ||
|
||
@staticmethod | ||
def get(yff_query, params=None): | ||
# run data query | ||
if params: | ||
query_output = yff_query(**params, run=True) | ||
else: | ||
query_output = yff_query(run=True) | ||
data = query_output.get("data") | ||
url = query_output.get("url") | ||
logger.info( | ||
"DATA FETCHED WITH QUERY URL: {}".format(url) + (" AND PARAMS: {}".format(params) if params else "")) | ||
return data | ||
|
||
def save(self, file_name, yff_query, params=None): | ||
|
||
if not os.path.exists(self.save_dir): | ||
os.makedirs(self.save_dir) | ||
|
||
data = self.get(yff_query, params) | ||
|
||
saved_data_file_path = os.path.join(self.save_dir, file_name + ".json") | ||
with open(saved_data_file_path, "w", encoding="utf-8") as data_file: | ||
json.dump(data, data_file, ensure_ascii=False, indent=2, default=complex_json_handler) | ||
logger.info("DATA SAVED LOCALLY TO: {}".format(saved_data_file_path)) | ||
return data | ||
|
||
def load(self, file_name, data_type_class=None): | ||
|
||
saved_data_file_path = os.path.join(self.save_dir, file_name + ".json") | ||
if os.path.exists(saved_data_file_path): | ||
with open(saved_data_file_path, "r", encoding="utf-8") as data_file: | ||
unpacked = unpack_data(json.load(data_file), YahooFantasyObject) | ||
data = data_type_class(unpacked) if data_type_class else unpacked | ||
logger.info("DATA LOADED LOCALLY FROM: {}".format(saved_data_file_path)) | ||
else: | ||
raise FileNotFoundError( | ||
"FILE {} DOES NOT EXIST. CANNOT LOAD DATA LOCALLY WITHOUT HAVING PREVIOUSLY SAVED DATA!".format( | ||
saved_data_file_path)) | ||
return data | ||
|
||
# def persist_and_retrieve_data(self, yff_query, data_dir, data_file_name, data_type_class=None, params=None, | ||
# persist_data=False, refresh_data=True): | ||
# data_persistence_dir = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), data_dir) | ||
# | ||
# if not os.path.exists(data_persistence_dir): | ||
# os.makedirs(data_persistence_dir) | ||
# | ||
# if refresh_data: | ||
# # run data query | ||
# if params: | ||
# query_output = yff_query(**params, run=True) | ||
# else: | ||
# query_output = yff_query(run=True) | ||
# data = query_output.get("data") | ||
# url = query_output.get("url") | ||
# logger.info( | ||
# "DATA FETCHED WITH QUERY URL: {}".format(url) + (" AND PARAMS: {}".format(params) if params else "")) | ||
# else: | ||
# persisted_data_file_path = os.path.join(data_persistence_dir, data_file_name + ".json") | ||
# if os.path.exists(persisted_data_file_path): | ||
# with open(persisted_data_file_path, "r", encoding="utf-8") as data_file: | ||
# unpacked = unpack_data(json.load(data_file), YahooFantasyObject) | ||
# data = data_type_class(unpacked) if data_type_class else unpacked | ||
# logger.info("DATA RETRIEVED LOCALLY: {}".format(persisted_data_file_path)) | ||
# else: | ||
# raise FileNotFoundError( | ||
# "FILE {} DOES NOT EXIST. CANNOT RUN LOCALLY WITHOUT HAVING PREVIOUSLY PERSISTED DATA!".format( | ||
# persisted_data_file_path)) | ||
# | ||
# if persist_data and refresh_data: | ||
# persisted_data_file_path = os.path.join(data_persistence_dir, data_file_name + ".json") | ||
# with open(persisted_data_file_path, "w", encoding="utf-8") as persisted_data_file: | ||
# json.dump(data, persisted_data_file, ensure_ascii=False, indent=2, default=complex_json_handler) | ||
# logger.info("DATA PERSISTED LOCALLY: {}".format(persisted_data_file_path)) | ||
# | ||
# return data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.