Skip to content
This repository was archived by the owner on Jun 30, 2025. It is now read-only.

Commit a19f0b2

Browse files
Merge pull request #80 from kgashok/patch-1
Update first_timers.py
2 parents 0cfb916 + 363408d commit a19f0b2

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

first_timers/first_timers.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
from __future__ import print_function
33
import re
44
import warnings
5-
from datetime import datetime, timedelta
6-
5+
from datetime import datetime
76
import requests
87
import tweepy
98

@@ -28,17 +27,24 @@ def humanize_url(api_url):
2827

2928

3029
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+
"""
3233
items = []
3334
for query in queries:
3435
res = requests.get(query)
3536
if res.status_code == 403:
3637
warnings.warn('Rate limit reached')
3738
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)
4044
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+
)
4248
return items
4349

4450

@@ -50,7 +56,7 @@ def add_repo_languages(issues):
5056
if res.status_code == 403:
5157
warnings.warn('Rate limit reached getting languages')
5258
return issues
53-
elif res.ok:
59+
if res.ok:
5460
issue['languages'] = res.json()
5561
else:
5662
warnings.warn('Could not handle response: ' + str(res) + ' from the API.')
@@ -59,7 +65,7 @@ def add_repo_languages(issues):
5965

6066
def get_fresh(old_issue_list, new_issue_list):
6167
"""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}
6369
return [x for x in new_issue_list if x['url'] not in old_urls]
6470

6571

@@ -69,7 +75,6 @@ def tweet_issues(issues, creds, debug=False):
6975
Also takes a parameter 'debug', which can prevent actual tweeting.
7076
Returns a list of tweets.
7177
"""
72-
7378
if len(issues) == 0:
7479
return []
7580

@@ -93,12 +98,14 @@ def tweet_issues(issues, creds, debug=False):
9398
# Not encoding here because Twitter treats code points as 1 character.
9499
language_hashTags = ''
95100
title = issue['title']
96-
101+
97102
if len(title) > allowed_title_len:
98103
title = title[: allowed_title_len - 1] + ellipse
99104
else:
100105
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+
)
102109
hashTags = hashTags + language_hashTags
103110

104111
max_hashtags_len = MAX_TWEETS_LEN - (url_len + 1) - (len(title) + 1)

0 commit comments

Comments
 (0)