2
2
from __future__ import print_function
3
3
import re
4
4
import warnings
5
- from datetime import datetime , timedelta
6
-
5
+ from datetime import datetime
7
6
import requests
8
7
import tweepy
9
8
@@ -28,17 +27,24 @@ def humanize_url(api_url):
28
27
29
28
30
29
def get_first_timer_issues (days_old = DAYS_OLD ):
31
- """Fetches the first page of issues with the label first-timers-label which are still open."""
30
+ """Fetches the first page of issues with the label first-timers-label
31
+ which are still open.
32
+ """
32
33
items = []
33
34
for query in queries :
34
35
res = requests .get (query )
35
36
if res .status_code == 403 :
36
37
warnings .warn ('Rate limit reached' )
37
38
return items
38
- elif res .ok :
39
- [items .append (item ) for item in res .json ()['items' ] if (datetime .now () - datetime .strptime (item ['created_at' ], "%Y-%m-%dT%H:%M:%SZ" )).days < days_old ]
39
+ if res .ok :
40
+ for item in res .json ()['items' ]:
41
+ created_at = datetime .strptime (item ['created_at' ], "%Y-%m-%dT%H:%M:%SZ" )
42
+ if (datetime .now () - created_at ).days < days_old :
43
+ items .append (item )
40
44
else :
41
- raise RuntimeError ('Could not handle response: ' + str (res ) + ' from the API.' )
45
+ raise RuntimeError (
46
+ 'Could not handle response: ' + str (res ) + ' from the API.'
47
+ )
42
48
return items
43
49
44
50
@@ -50,7 +56,7 @@ def add_repo_languages(issues):
50
56
if res .status_code == 403 :
51
57
warnings .warn ('Rate limit reached getting languages' )
52
58
return issues
53
- elif res .ok :
59
+ if res .ok :
54
60
issue ['languages' ] = res .json ()
55
61
else :
56
62
warnings .warn ('Could not handle response: ' + str (res ) + ' from the API.' )
@@ -59,7 +65,7 @@ def add_repo_languages(issues):
59
65
60
66
def get_fresh (old_issue_list , new_issue_list ):
61
67
"""Returns which issues are not present in the old list of issues."""
62
- old_urls = set ( x ['url' ] for x in old_issue_list )
68
+ old_urls = { x ['url' ] for x in old_issue_list }
63
69
return [x for x in new_issue_list if x ['url' ] not in old_urls ]
64
70
65
71
@@ -69,7 +75,6 @@ def tweet_issues(issues, creds, debug=False):
69
75
Also takes a parameter 'debug', which can prevent actual tweeting.
70
76
Returns a list of tweets.
71
77
"""
72
-
73
78
if len (issues ) == 0 :
74
79
return []
75
80
@@ -93,12 +98,14 @@ def tweet_issues(issues, creds, debug=False):
93
98
# Not encoding here because Twitter treats code points as 1 character.
94
99
language_hashTags = ''
95
100
title = issue ['title' ]
96
-
101
+
97
102
if len (title ) > allowed_title_len :
98
103
title = title [: allowed_title_len - 1 ] + ellipse
99
104
else :
100
105
if 'languages' in issue :
101
- language_hashTags = '' .join (' #{}' .format (lang ) for lang in issue ['languages' ])
106
+ language_hashTags = '' .join (
107
+ ' #{}' .format (lang ) for lang in issue ['languages' ]
108
+ )
102
109
hashTags = hashTags + language_hashTags
103
110
104
111
max_hashtags_len = MAX_TWEETS_LEN - (url_len + 1 ) - (len (title ) + 1 )
0 commit comments