-
Notifications
You must be signed in to change notification settings - Fork 0
/
framed-pitches.py
30 lines (26 loc) · 1.21 KB
/
framed-pitches.py
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
from pybaseball import statcast as sc
import tweepy
from configparser import ConfigParser
import datetime
from datetime import timedelta
import baseball_tweet
config = ConfigParser()
config.read("config.ini")
# AUTH
consumer_key = config["KEYS"]["consumer_key"]
consumer_secret = config["KEYS"]["consumer_secret"]
access_token = config["KEYS"]["access_token"]
access_token_secret = config["KEYS"]["access_token_secret"]
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
today = datetime.date.today()
date_min = today - timedelta(days=today.weekday()+7)
date_max = today - timedelta(days=today.isoweekday())
date_min, date_max = str(date_min), str(date_max)
data = sc(start_dt=date_min, end_dt=date_max)
general_cols = ["player_name", "game_date", "home_team", "away_team", "inning", "inning_topbot", "outs_when_up", "balls", "strikes", "pitch_number"]
# swing and miss farthest from zone, plate_x, plate_z
framed_tweet = baseball_tweet.Framed_pitch(api, "Last weeks #{0} greatest frame by {1} with {2:.2f}ft to the zone! 👀👀👀", general_cols, date_min, date_max)
framed_tweet.rank_data(data, "zone_distance")
framed_tweet.post_tweet()