Skip to content

Commit 054add5

Browse files
authored
Merge pull request #8 from and-computers/feature/profiles
Feature/profiles
2 parents edbf796 + 7d1aaa6 commit 054add5

File tree

6 files changed

+101
-20
lines changed

6 files changed

+101
-20
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
*.py[cod]
33
*_autogen*
44
post-commit
5+
.profiles.ini

.profiles.ini

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[default]
2+
CONSUMER_KEY=your_key
3+
CONSUMER_SECRET=my_secret_key
4+
ACCESS_TOKEN=my_token
5+
ACCESS_TOKEN_SECRET=my_secret_token
6+
7+
[kevindurantactual]
8+
CONSUMER_KEY=your_key
9+
CONSUMER_SECRET=my_secret_key
10+
ACCESS_TOKEN=my_token
11+
ACCESS_TOKEN_SECRET=my_secret_token
12+
13+
[kevindurantfanacct]
14+
CONSUMER_KEY=your_key
15+
CONSUMER_SECRET=my_secret_key
16+
ACCESS_TOKEN=my_token
17+
ACCESS_TOKEN_SECRET=my_secret_token

README.md

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,37 @@ changed to do the actual twitter post in python using `Tweepy` because the oauth
1414
![get_dev_tokens](http://g.recordit.co/VlZUSa77T2.gif)
1515
https://www.slickremix.com/docs/how-to-get-api-keys-and-tokens-for-twitter/
1616

17-
2. Run `bash start_tweeting.sh` to execute the script
1817

19-
3. Supply the information when prompted.
20-
- The path to the repository you want to tweet commits for
21-
- The twitter api consumer key
22-
- The twitter api consumer secret
23-
- The twitter api access token
24-
- The twitter api access token secret
18+
2. Fill out the `.profiles.ini` file with as many different twitter account keys as you would like.
19+
20+
```
21+
[default]
22+
CONSUMER_KEY=your_key
23+
CONSUMER_SECRET=my_secret_key
24+
ACCESS_TOKEN=my_token
25+
ACCESS_TOKEN_SECRET=my_secret_token
26+
27+
[kevindurantactual]
28+
CONSUMER_KEY=your_key
29+
CONSUMER_SECRET=my_secret_key
30+
ACCESS_TOKEN=my_token
31+
ACCESS_TOKEN_SECRET=my_secret_token
32+
33+
[kevindurantfanacct]
34+
CONSUMER_KEY=your_key
35+
CONSUMER_SECRET=my_secret_key
36+
ACCESS_TOKEN=my_token
37+
ACCESS_TOKEN_SECRET=my_secret_token
38+
```
39+
40+
2. run `pip install -r requirements.txt` to install dependencies (its just `tweepy` and `configparser`),
41+
42+
3. Run `python start_tweeting.py default` to tweet from the account associated with the keys listed under `default` in `.profiles.ini`
43+
44+
4. When prompted select the folder of the repository you are interested in tweeting out commits for.
45+
46+
5. Watch as all your fake friends unfollow you.
2547

26-
4. Install dependency (its just `tweepy`), run `pip install -r requirements.txt`
2748

2849
--------------------------------------------------------------------------
2950

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
tweepy>=3.0
1+
tweepy>=3.0
2+
configparser

start_tweeting.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
2+
import configparser
3+
import os
4+
import subprocess
5+
import sys
6+
# from tkinter import filedialog
7+
from tkinter import Tk, filedialog
8+
# work on py2 and py3
9+
try:
10+
input = raw_input
11+
except NameError:
12+
pass
13+
14+
cfg = configparser.ConfigParser()
15+
cfg.read('.profiles.ini')
16+
17+
whoami = sys.argv[1]
18+
19+
# parse lambda configuration parameters
20+
CONFIG_PARAMS = {}
21+
for config_tuple in cfg.items(whoami):
22+
name = config_tuple[0]
23+
val = config_tuple[1]
24+
CONFIG_PARAMS[name.upper()] = val
25+
26+
27+
root = Tk()
28+
root.withdraw()
29+
REPOSITORY_PATH = filedialog.askdirectory(title="Select Repository to Tweet From")
30+
root.destroy()
31+
if not REPOSITORY_PATH:
32+
print("Must enter a repository path")
33+
else:
34+
REPOSITORY_PATH = REPOSITORY_PATH if REPOSITORY_PATH.endswith(os.sep) else REPOSITORY_PATH + os.sep
35+
bashCommand = "bash start_tweeting.sh {ck} {csk} {at} {ats} {rp}".format(
36+
ck=CONFIG_PARAMS['CONSUMER_KEY'],
37+
csk=CONFIG_PARAMS['CONSUMER_SECRET'],
38+
at=CONFIG_PARAMS['ACCESS_TOKEN'],
39+
ats=CONFIG_PARAMS['ACCESS_TOKEN_SECRET'],
40+
rp=REPOSITORY_PATH
41+
)
42+
process = subprocess.Popen(bashCommand.split(), stdout=subprocess.PIPE)
43+
output, error = process.communicate()
44+
if error:
45+
print(error)

start_tweeting.sh

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,21 @@
22

33
# This is a program that sets up a repository for tweeting commits!
44

5-
echo -n "Enter the Path/to/your/repository (autocomplete enabled & must end in slash) and press [ENTER]: "
6-
read -e REPOSITORY_PATH
5+
6+
twitter_consumer_key=$1
7+
twitter_consumer_secret=$2
8+
twitter_access_token=$3
9+
twitter_access_token_secret=$4
10+
REPOSITORY_PATH=$5
711

812
# tilde expansion for the case when it exists
913
# https://stackoverflow.com/questions/3963716/how-to-manually-expand-a-special-variable-ex-tilde-in-bash
1014
REPOSITORY_PATH="${REPOSITORY_PATH/#\~/$HOME}"
1115

1216
echo "This script will tweet out your commits for "$REPOSITORY_PATH""
1317

14-
echo -n "Enter your Twitter consumer key and press [ENTER]: "
15-
read twitter_consumer_key
16-
echo -n "Enter your Twitter consumer secret and press [ENTER]: "
17-
read twitter_consumer_secret
1818

19-
echo -n "Enter your Twitter access token and press [ENTER]: "
20-
read twitter_access_token
2119

22-
echo -n "Enter your Twitter access token secret and press [ENTER]: "
23-
read twitter_access_token_secret
2420

2521
echo "Placing access keys & tokens in python script"
2622

@@ -54,4 +50,4 @@ echo "Making post commit bash script executable"
5450

5551
sudo chmod a+x "${REPOSITORY_PATH}.git/hooks/post-commit"
5652

57-
echo "Every Tweet From "${REPOSITORY_PATH}" will now be tweeted out!"
53+
echo "Every Tweet From "${REPOSITORY_PATH}" will now be tweeted out!">&2

0 commit comments

Comments
 (0)