-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpost_commit_hook_template.py
More file actions
36 lines (28 loc) · 997 Bytes
/
post_commit_hook_template.py
File metadata and controls
36 lines (28 loc) · 997 Bytes
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
import tweepy
import sys
"""
ADAPTED FROM: http://nodotcom.org/python-twitter-tutorial.html
"""
def get_api_client(config_dict: dict) -> tweepy.Client:
"""Get api client from tweepy for v2 api endpoints
Args:
config_dict (dict[str,str]): a dictionary with keys needed to auth
specifically consumer_key, consumer_secret, access_token, access_token_secret
"""
return tweepy.Client(**config_dict)
def main():
# Get these values from https://apps.twitter.com/
# See more detailed instructions in the README.md
cfg = {
"consumer_key": "{{YOUR_VALUE_CKEY}}",
"consumer_secret": "{{YOUR_VALUE_CSECRET}}",
"access_token": "{{YOUR_VALUE_ATOKEN}}",
"access_token_secret": "{{YOUR_VALUE_ATOKENSECRET}}"
}
tweet = ""
for arg in sys.argv[1:]:
tweet += " " + arg
twitter_client = get_api_client(config_dict=cfg)
status = twitter_client.create_tweet(text=tweet)
if __name__ == "__main__":
main()