Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Script logging #94

Merged
merged 2 commits into from
Sep 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/bitcoin_acks/github_data/pull_request_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from bitcoin_acks.github_data.polling_data import PollingData
from bitcoin_acks.github_data.pull_requests_data import PullRequestsData
from bitcoin_acks.github_data.repositories_data import RepositoriesData
from bitcoin_acks.logging import log


class PullRequestEvents(RepositoriesData):
Expand Down Expand Up @@ -52,8 +53,15 @@ def get(self):


if __name__ == '__main__':
import os

repository_path = 'bitcoin'
repository_name = 'bitcoin'
log.debug('Running pull request events update script',
path=os.path.realpath(__file__),
repository_name=repository_name,
repository_path=repository_path
)
create_or_update_database()
pr_events = PullRequestEvents(repository_path=repository_path,
repository_name=repository_name)
Expand All @@ -68,6 +76,7 @@ def get(self):
time.sleep(math.ceil(sleep_time)+5)

now = datetime.utcnow()
log.debug('In while True loop', sleep_time=sleep_time, now=now, last_update=pr_events.last_update)
if pr_events.last_update.day != now.day:
pr_data.update_all(state=PullRequestState.OPEN)
# polling_data.update(last_open_update=True)
Expand Down
6 changes: 6 additions & 0 deletions src/bitcoin_acks/scripts/send_tweet.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from twython import Twython

from bitcoin_acks.database.session import session_scope
from bitcoin_acks.logging import log
from bitcoin_acks.models import PullRequests
from bitcoin_acks.models.tweets import Tweets

Expand Down Expand Up @@ -36,10 +37,12 @@ def send_tweet(pull_request_number=None):
.first()
)
if next_pull_request is None:
log.debug('No pull requests found.')
return
commits_url = 'https://api.github.com/repos/bitcoin/bitcoin/commits'
params = {'author': next_pull_request.author.login}
response = requests.get(commits_url, params=params)
log.debug('github response', response=response)
response_json = response.json()
author_name = next_pull_request.author.name or next_pull_request.author.login
if len(response_json) > 1 and next_pull_request.number != 14802:
Expand All @@ -53,7 +56,9 @@ def send_tweet(pull_request_number=None):
Congratulations! 🎉🍾🎆
'''.format(author_name,
next_pull_request.html_url)
log.debug('tweet status', status=status)
tweet = twitter.update_status(status=status)
log.debug('tweet', tweet=tweet)
new_tweet = Tweets()
new_tweet.id = tweet['id']
new_tweet.pull_request_id = next_pull_request.number
Expand All @@ -69,4 +74,5 @@ def send_tweet(pull_request_number=None):
type=int,
default=None)
args = parser.parse_args()
log.debug(f'sending tweet for {args.pr_number}')
send_tweet(pull_request_number=args.pr_number)