This repository has been archived by the owner on Jun 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
65 lines (54 loc) · 1.98 KB
/
main.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import datetime
import requests
import tweepy
from os import environ
def authenticate_twitter():
api_key = environ['TWITTER_API_KEY']
api_secret_key = environ['TWITTER_API_SECRET_KEY']
access_token = environ['TWITTER_ACCESS_TOKEN']
access_token_secret = environ['TWITTER_ACCESS_TOKEN_SECRET']
auth = tweepy.OAuthHandler(api_key, api_secret_key)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
try:
api.verify_credentials()
print("Authentication OK")
except:
print("Error during authentication")
return api
def get_repos():
repos = ''
with open('repos.txt') as f:
for line in f:
repos += ' repo:' + line.strip()
return repos
def get_matching_issues():
time = datetime.datetime.now() - datetime.timedelta(hours=48)
date = time.date()
repos = get_repos()
response = requests.get(f'https://api.github.com/search/issues?q={repos} created:>{date} label:"Good first issue"')
data = response.json()
return data['items']
def tweet_matching_issues(issues):
for issue in issues:
url = issue['html_url']
language = get_repo_language(issue)
if language is None:
api.update_status(f'A new beginner friendly #openSource issue is ready for you! {url}')
else:
api.update_status(f'Want to learn #{language}? A new beginner friendly #openSource issue is ready for you! {url}')
def get_repo_language(issue):
github_api_token = environ['API_TOKEN']
repository_url = issue['repository_url']
languages_url = f'{repository_url}/languages'
languages = requests.get(languages_url, headers={'Authorization': f'token {github_api_token}'})
data = languages.json()
if len(data) < 1:
return None
else:
language = list(data.keys())[0]
return language
if __name__ == '__main__':
api = authenticate_twitter()
issues = get_matching_issues()
tweet_matching_issues(issues)