From 6542cd02ace4c1f1cef8d19431521f8f026dbb7e Mon Sep 17 00:00:00 2001 From: Aditya Anand M C Date: Thu, 2 Sep 2021 21:08:12 +0530 Subject: [PATCH] remove twitter feed + slack post (#9424) --- app/dashboard/helpers.py | 6 +- app/dashboard/models.py | 4 +- app/dashboard/notifications.py | 192 ------------------ app/dashboard/tasks.py | 14 -- app/dashboard/utils.py | 3 - app/dashboard/views.py | 15 +- .../management/commands/hypercharge_mode.py | 9 +- .../management/commands/remarket_bounties.py | 47 ----- .../management/commands/share_activity.py | 60 ------ .../commands/test_remarket_tweet.py | 65 ------ scripts/crontab | 3 - 11 files changed, 5 insertions(+), 413 deletions(-) delete mode 100644 app/marketing/management/commands/remarket_bounties.py delete mode 100644 app/marketing/management/commands/share_activity.py delete mode 100644 app/marketing/tests/management/commands/test_remarket_tweet.py diff --git a/app/dashboard/helpers.py b/app/dashboard/helpers.py index b741ece2a0b..c8253b8f57b 100644 --- a/app/dashboard/helpers.py +++ b/app/dashboard/helpers.py @@ -36,7 +36,7 @@ HackathonEvent, UserAction, ) from dashboard.notifications import ( - maybe_market_to_email, maybe_market_to_github, maybe_market_to_slack, maybe_market_to_user_slack, + maybe_market_to_email, maybe_market_to_github, notify_of_lowball_bounty, ) from dashboard.tokens import addr_to_token @@ -960,8 +960,6 @@ def process_bounty_changes(old_bounty, new_bounty): # marketing if event_name != 'unknown_event': print("============ posting ==============") - did_post_to_slack = maybe_market_to_slack(new_bounty, event_name) - did_post_to_user_slack = maybe_market_to_user_slack(new_bounty, event_name) did_post_to_github = maybe_market_to_github(new_bounty, event_name, profile_pairs) did_post_to_email = maybe_market_to_email(new_bounty, event_name) print("============ done posting ==============") @@ -971,8 +969,6 @@ def process_bounty_changes(old_bounty, new_bounty): 'did_bsr': did_bsr, 'did_post_to_email': did_post_to_email, 'did_post_to_github': did_post_to_github, - 'did_post_to_slack': did_post_to_slack, - 'did_post_to_user_slack': did_post_to_user_slack, 'did_post_to_twitter': False, } diff --git a/app/dashboard/models.py b/app/dashboard/models.py index 010b8f60670..099dd633beb 100644 --- a/app/dashboard/models.py +++ b/app/dashboard/models.py @@ -71,7 +71,7 @@ from unidecode import unidecode from web3 import Web3 -from .notifications import maybe_market_to_github, maybe_market_to_slack, maybe_market_to_user_slack +from .notifications import maybe_market_to_github from .signals import m2m_changed_interested logger = logging.getLogger(__name__) @@ -2195,8 +2195,6 @@ def auto_user_approve(interest, bounty): interest.acceptance_date = timezone.now() start_work_approved(interest, bounty) maybe_market_to_github(bounty, 'work_started', profile_pairs=bounty.profile_pairs) - maybe_market_to_slack(bounty, 'worker_approved') - maybe_market_to_user_slack(bounty, 'worker_approved') @receiver(post_save, sender=Interest, dispatch_uid="psave_interest") diff --git a/app/dashboard/notifications.py b/app/dashboard/notifications.py index 2fc612758c8..0042119ee44 100644 --- a/app/dashboard/notifications.py +++ b/app/dashboard/notifications.py @@ -83,148 +83,6 @@ def github_org_to_twitter_tags(github_org): return twitter_tags -def maybe_market_to_twitter(bounty, event_name): - """Tweet the specified Bounty event. - - Args: - bounty (dashboard.models.Bounty): The Bounty to be marketed. - event_name (str): The name of the event. - - Returns: - bool: Whether or not the twitter notification was sent successfully. - - """ - if not bounty.is_notification_eligible(var_to_check=settings.TWITTER_CONSUMER_KEY): - return False - - api = twitter.Api( - consumer_key=settings.TWITTER_CONSUMER_KEY, - consumer_secret=settings.TWITTER_CONSUMER_SECRET, - access_token_key=settings.TWITTER_ACCESS_TOKEN, - access_token_secret=settings.TWITTER_ACCESS_SECRET, - ) - tweet_txts = [ - "Earn {} {} {} now by completing this task: \n\n{}", - "Oppy to earn {} {} {} for completing this task: \n\n{}", - "Is today the day you (a) boost your OSS rep (b) make some extra cash? 🤔 {} {} {} \n\n{}", - ] - if event_name == 'remarket_bounty': - tweet_txts = tweet_txts + [ - "Gitcoin open task of the day is worth {} {} {} ⚡️ \n\n{}", - "Task of the day 💰 {} {} {} ⚡️ \n\n{}", - ] - elif event_name == 'new_bounty': - tweet_txts = tweet_txts + [ - "Extra! Extra 🗞🗞 New Funded Issue, Read all about it 👇 {} {} {} \n\n{}", - "Hot off the blockchain! 🔥🔥🔥 There's a new task worth {} {} {} \n\n{}", - "💰 New Task Alert.. 💰 Earn {} {} {} for working on this 👇 \n\n{}", - ] - elif event_name == 'increased_bounty': - tweet_txts = [ - 'Increased Payout on {} {} {}\n{}' - ] - elif event_name == 'start_work': - tweet_txts = [ - 'Work started on {} {} {}\n{}' - ] - elif event_name == 'stop_work': - tweet_txts = [ - 'Work stopped on {} {} {}\n{}' - ] - elif event_name == 'work_done': - tweet_txts = [ - 'Work done on {} {} {}\n{}' - ] - elif event_name == 'work_submitted': - tweet_txts = [ - 'Work submitted on {} {} {}\n{}' - ] - elif event_name == 'killed_bounty': - tweet_txts = [ - 'Bounty killed on {} {} {}\n{}' - ] - elif event_name == 'worker_rejected': - tweet_txts = [ - 'Worked rejected on {} {} {}\n{}' - ] - elif event_name == 'worker_approved': - tweet_txts = [ - 'Worked approved on {} {} {}\n{}' - ] - - random.shuffle(tweet_txts) - tweet_txt = tweet_txts[0] - utm = '' - if bounty.metadata.get('hyper_tweet_counter', False): - utm = f'utm_source=hypercharge-auto&utm_medium=twitter&utm_campaign={bounty.title}' - - url = f'{bounty.get_absolute_url()}?{utm}' - is_short = False - for shortener in ['Tinyurl', 'Adfly', 'Isgd', 'QrCx']: - try: - if not is_short: - shortener = Shortener(shortener) - response = shortener.short(url) - if response != 'Error' and 'http' in response: - url = response - is_short = True - except Exception: - pass - - new_tweet = tweet_txt.format( - round(bounty.get_natural_value(), 4), - bounty.token_name, - f"({bounty.value_in_usdt_now} USD @ ${round(convert_token_to_usdt(bounty.token_name),2)}/{bounty.token_name})" if bounty.value_in_usdt_now else "", - url - ) - new_tweet = new_tweet + " " + github_org_to_twitter_tags(bounty.org_name) # twitter tags - if bounty.keywords: # hashtags - for keyword in bounty.keywords.split(','): - _new_tweet = new_tweet + " #" + str(keyword).lower().strip() - if len(_new_tweet) < 140: - new_tweet = _new_tweet - - try: - api.PostUpdate(new_tweet) - except Exception as e: - print(e) - return False - return True - - -def maybe_market_to_slack(bounty, event_name): - """Send a Slack message for the specified Bounty. - - Args: - bounty (dashboard.models.Bounty): The Bounty to be marketed. - event_name (str): The name of the event. - - Returns: - bool: Whether or not the Slack notification was sent successfully. - - """ - if not bounty.is_notification_eligible(var_to_check=settings.SLACK_TOKEN): - return False - - msg = build_message_for_integration(bounty, event_name) - if not msg: - return False - - try: - channel = 'notif-gitcoin' - sc = SlackClient(settings.SLACK_TOKEN) - sc.api_call( - "chat.postMessage", - channel=channel, - text=msg, - icon_url=settings.GITCOIN_SLACK_ICON_URL, - ) - except Exception as e: - print(e) - return False - return True - - def build_message_for_integration(bounty, event_name): """Build message to be posted to integrated service (e.g. slack). @@ -257,56 +115,6 @@ def build_message_for_integration(bounty, event_name): return msg -def maybe_market_to_user_slack(bounty, event_name): - from dashboard.tasks import maybe_market_to_user_slack - maybe_market_to_user_slack.delay(bounty.pk, event_name) - - -def maybe_market_to_user_slack_helper(bounty, event_name): - """Send a Slack message to the user's slack channel for the specified Bounty. - - Args: - bounty (dashboard.models.Bounty): The Bounty to be marketed. - event_name (str): The name of the event. - - Returns: - bool: Whether or not the Slack notification was sent successfully. - - """ - from dashboard.models import Profile - if bounty.get_natural_value() < 0.0001: - return False - if bounty.network != settings.ENABLE_NOTIFICATIONS_ON_NETWORK: - return False - - msg = build_message_for_integration(bounty, event_name) - if not msg: - return False - - url = bounty.github_url - sent = False - try: - repo = org_name(url) + '/' + repo_name(url) - subscribers = Profile.objects.filter(slack_repos__contains=[repo]) - subscribers = subscribers & Profile.objects.exclude(slack_token='', slack_channel='') - for subscriber in subscribers: - try: - sc = SlackClient(subscriber.slack_token) - sc.api_call( - "chat.postMessage", - channel=subscriber.slack_channel, - text=msg, - icon_url=settings.GITCOIN_SLACK_ICON_URL, - ) - sent = True - except Exception as e: - print(e) - except Exception as e: - print(e) - - return sent - - def maybe_market_tip_to_email(tip, emails): """Send an email for the specified Tip. diff --git a/app/dashboard/tasks.py b/app/dashboard/tasks.py index 3cd4ffe69b5..33870f9b41b 100644 --- a/app/dashboard/tasks.py +++ b/app/dashboard/tasks.py @@ -261,20 +261,6 @@ def update_trust_bonus(self, pk): profile.save() -@app.shared_task(bind=True) -def maybe_market_to_user_slack(self, bounty_pk, event_name, retry: bool = True) -> None: - """ - :param self: - :param bounty_pk: - :param event_name: - :return: - """ - with redis.lock("maybe_market_to_user_slack:bounty", timeout=LOCK_TIMEOUT): - bounty = Bounty.objects.get(pk=bounty_pk) - from dashboard.notifications import maybe_market_to_user_slack_helper - maybe_market_to_user_slack_helper(bounty, event_name) - - @app.shared_task(bind=True, soft_time_limit=600, time_limit=660, max_retries=3) def grant_update_email_task(self, pk, retry: bool = True) -> None: """ diff --git a/app/dashboard/utils.py b/app/dashboard/utils.py index 24cdd554203..ee435439ffa 100644 --- a/app/dashboard/utils.py +++ b/app/dashboard/utils.py @@ -65,7 +65,6 @@ from web3.middleware import geth_poa_middleware from .abi import erc20_abi -from .notifications import maybe_market_to_slack logger = logging.getLogger(__name__) @@ -1054,8 +1053,6 @@ def re_market_bounty(bounty, auto_save = True): if auto_save: bounty.save() - maybe_market_to_slack(bounty, 'issue_remarketed') - result_msg = 'The issue will appear at the top of the issue explorer. ' further_permitted_remarket_count = settings.RE_MARKET_LIMIT - bounty.remarketed_count if further_permitted_remarket_count >= 1: diff --git a/app/dashboard/views.py b/app/dashboard/views.py index 387c91d73c2..ddc3dfa315a 100644 --- a/app/dashboard/views.py +++ b/app/dashboard/views.py @@ -128,9 +128,7 @@ MediaFile, Option, Poll, PortfolioItem, Profile, ProfileSerializer, ProfileVerification, ProfileView, Question, SearchHistory, Sponsor, Tool, TribeMember, UserAction, UserVerificationModel, ) -from .notifications import ( - maybe_market_to_email, maybe_market_to_github, maybe_market_to_slack, maybe_market_to_user_slack, -) +from .notifications import maybe_market_to_email, maybe_market_to_github from .poh_utils import is_registered_on_poh from .router import HackathonEventSerializer, TribesSerializer from .utils import ( @@ -284,8 +282,6 @@ def create_new_interest_helper(bounty, user, issue_message): record_bounty_activity(bounty, user, 'start_work' if not approval_required else 'worker_applied', interest=interest) bounty.interested.add(interest) record_user_action(user, 'start_work', interest) - maybe_market_to_slack(bounty, 'start_work' if not approval_required else 'worker_applied') - maybe_market_to_user_slack(bounty, 'start_work' if not approval_required else 'worker_applied') return interest @@ -614,8 +610,6 @@ def remove_interest(request, bounty_id): bounty.interested.remove(interest) interest.delete() - maybe_market_to_slack(bounty, 'stop_work') - maybe_market_to_user_slack(bounty, 'stop_work') except Interest.DoesNotExist: return JsonResponse({ 'errors': [_('You haven\'t expressed interest on this bounty.')], @@ -768,8 +762,6 @@ def uninterested(request, bounty_id, profile_id): try: interest = Interest.objects.get(profile_id=profile_id, bounty=bounty) bounty.interested.remove(interest) - maybe_market_to_slack(bounty, 'stop_work') - maybe_market_to_user_slack(bounty, 'stop_work') if is_staff or is_moderator: event_name = "bounty_removed_slashed_by_staff" if slashed else "bounty_removed_by_staff" else: @@ -1846,9 +1838,7 @@ def helper_handle_approvals(request, bounty): start_work_approved(interest, bounty) maybe_market_to_github(bounty, 'work_started', profile_pairs=bounty.profile_pairs) - maybe_market_to_slack(bounty, 'worker_approved') record_bounty_activity(bounty, request.user, 'worker_approved', interest) - maybe_market_to_user_slack(bounty, 'worker_approved') else: start_work_rejected(interest, bounty) @@ -1856,9 +1846,6 @@ def helper_handle_approvals(request, bounty): bounty.interested.remove(interest) interest.delete() - maybe_market_to_slack(bounty, 'worker_rejected') - maybe_market_to_user_slack(bounty, 'worker_rejected') - messages.success(request, _(f'{worker} has been {mutate_worker_action_past_tense}')) else: messages.warning(request, _('Only the funder of this bounty may perform this action.')) diff --git a/app/marketing/management/commands/hypercharge_mode.py b/app/marketing/management/commands/hypercharge_mode.py index 88ccbe7b17d..af111092b93 100644 --- a/app/marketing/management/commands/hypercharge_mode.py +++ b/app/marketing/management/commands/hypercharge_mode.py @@ -25,7 +25,6 @@ from django.utils import timezone from dashboard.models import Bounty, BountyEvent, Profile -from dashboard.notifications import maybe_market_to_twitter from marketing.mails import bounty_hypercharged from townsquare.models import Offer @@ -75,19 +74,15 @@ def handle(self, *args, **options): offer_title = f'Work on "{bounty.title}" and receive {floatformat(bounty.value_true)} {bounty.token_name}' offer_desc = '' - event_name = '' counter = bounty.metadata['hyper_tweet_counter'] + # counter is 0 -> new_bounty + # counter is 1 -> remarket_bounty if counter == 0: - event_name = 'new_bounty' notify_previous_workers(bounty) make_secret_offer(profile, offer_title, offer_desc, bounty) - elif counter == 1: - event_name = 'remarket_bounty' elif counter % 2 == 0: make_secret_offer(profile, offer_title, offer_desc, bounty) bounty.metadata['hyper_tweet_counter'] += 1 bounty.hyper_next_publication = now + timedelta(hours=12) bounty.save() - - maybe_market_to_twitter(bounty, event_name) diff --git a/app/marketing/management/commands/remarket_bounties.py b/app/marketing/management/commands/remarket_bounties.py deleted file mode 100644 index da56e07c9e5..00000000000 --- a/app/marketing/management/commands/remarket_bounties.py +++ /dev/null @@ -1,47 +0,0 @@ -# -*- coding: utf-8 -*- -#!/usr/bin/env python3 -''' - Copyright (C) 2021 Gitcoin Core - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published - by the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . - -''' -from django.core.management.base import BaseCommand - -from dashboard.models import Bounty -from dashboard.notifications import maybe_market_to_slack, maybe_market_to_twitter - - -class Command(BaseCommand): - - help = 'sends bounties quotes to twitter' - - def handle(self, *args, **options): - bounties = Bounty.objects.current().filter( - network='mainnet', - idx_status='open') - if bounties.count() < 3: - print('count is only {}. exiting'.format(bounties.count())) - return - bounty = bounties.order_by('?').first() - - remarket_bounties = bounties.filter(admin_mark_as_remarket_ready=True) - if remarket_bounties.exists(): - bounty = remarket_bounties.order_by('?').first() - - print(bounty) - did_tweet = maybe_market_to_twitter(bounty, 'remarket_bounty') - did_slack = maybe_market_to_slack(bounty, 'this funded issue could use some action!') - print("did tweet", did_tweet) - print("did slack", did_slack) diff --git a/app/marketing/management/commands/share_activity.py b/app/marketing/management/commands/share_activity.py deleted file mode 100644 index 871dece87d5..00000000000 --- a/app/marketing/management/commands/share_activity.py +++ /dev/null @@ -1,60 +0,0 @@ -# -*- coding: utf-8 -*- -#!/usr/bin/env python3 -''' - Copyright (C) 2021 Gitcoin Core - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published - by the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . - -''' -from django.conf import settings -from django.core.management.base import BaseCommand -from django.utils import timezone - -import twitter -from dashboard.models import Activity - - -class Command(BaseCommand): - - help = 'sends activity feed to twitter' - - def handle(self, *args, **options): - - api = twitter.Api( - consumer_key=settings.TWITTER_CONSUMER_KEY, - consumer_secret=settings.TWITTER_CONSUMER_SECRET, - access_token_key=settings.TWITTER_ACCESS_TOKEN, - access_token_secret=settings.TWITTER_ACCESS_SECRET, - ) - - created_before = (timezone.now() - timezone.timedelta(minutes=1)) - if settings.DEBUG: - created_before = (timezone.now() - timezone.timedelta(days=20)) - activities = Activity.objects.filter(created_on__gt=created_before) - print(f" got {activities.count()} activities") - for activity in activities: - - txt = activity.text - - txt = f". {txt} {activity.action_url}" - - if 'made an update to' in txt: - continue - - try: - print(txt) - new_tweet = txt - api.PostUpdate(new_tweet) - except Exception as e: - print(e) diff --git a/app/marketing/tests/management/commands/test_remarket_tweet.py b/app/marketing/tests/management/commands/test_remarket_tweet.py deleted file mode 100644 index 75e1f0dc3a7..00000000000 --- a/app/marketing/tests/management/commands/test_remarket_tweet.py +++ /dev/null @@ -1,65 +0,0 @@ -# -*- coding: utf-8 -*- -"""Handle marketing commands related tests. - -Copyright (C) 2021 Gitcoin Core - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU Affero General Public License as published -by the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Affero General Public License for more details. - -You should have received a copy of the GNU Affero General Public License -along with this program. If not, see . - -""" -from unittest.mock import patch - -from marketing.management.commands.remarket_bounties import Command -from test_plus.test import TestCase - - -class TestRemarketTweet(TestCase): - """Define tests for remarket tweet.""" - - @patch('marketing.management.commands.remarket_bounties.maybe_market_to_twitter') - def test_handle_no_bounties(self, mock_func): - """Test command remarket tweet with no bounties.""" - Command().handle() - - assert mock_func.call_count == 0 - -#TODO: uncomment when remarket_tweet logic will be activated -# @patch('marketing.management.commands.remarket_tweet.maybe_market_to_twitter') -# def test_handle_with_bounties(self, mock_func): -# """Test command remarket tweet with bounties.""" -# for i in range(3): -# bounty = Bounty.objects.create( -# title='foo', -# value_in_token=3, -# token_name='USDT', -# web3_created=datetime(2008, 10, 31), -# github_url='https://github.com/gitcoinco/web', -# token_address='0x0', -# issue_description='hello world', -# bounty_owner_github_username='flintstone', -# is_open=True, -# accepted=True, -# expires_date=timezone.now() + timedelta(days=1, hours=1), -# idx_project_length=5, -# project_length='Months', -# bounty_type='Feature', -# experience_level='Intermediate', -# raw_data={}, -# idx_status='open', -# bounty_owner_email='john@bar.com', -# current_bounty=True, -# network='mainnet' -# ) -# Command().handle() -# -# assert mock_func.call_count == 1 diff --git a/scripts/crontab b/scripts/crontab index 1ec1dee1f79..6f5bb08ac50 100644 --- a/scripts/crontab +++ b/scripts/crontab @@ -70,9 +70,6 @@ PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/us 30 */6 * * * cd gitcoin/coin; bash scripts/run_management_command_if_not_already_running.bash process_pending_kudos_distributions 20 20 2 0 >> /var/log/gitcoin/process_pending_kudos_distributions.log 2>&1 0 0 * * * cd gitcoin/coin; bash scripts/run_management_command_if_not_already_running.bash create_offer_if_none_exists >> /var/log/gitcoin/create_offer_if_none_exists.log 2>&1 -* * * * * cd gitcoin/coin; bash scripts/run_management_command_if_not_already_running.bash share_activity >> /var/log/gitcoin/share_activity.log 2>&1 -35 14 * * 1,6 cd gitcoin/coin; bash scripts/run_management_command.bash remarket_bounties >> /var/log/gitcoin/remarket_bounties.log 2>&1 -35 11 * * 0,4 cd gitcoin/coin; bash scripts/run_management_command.bash remarket_bounties >> /var/log/gitcoin/remarket_bounties.log 2>&1 45 10 * * * cd gitcoin/coin; bash scripts/run_management_command.bash expiration >> /var/log/gitcoin/expiration_bounty.log 2>&1 15 10 * * * cd gitcoin/coin; bash scripts/run_management_command.bash expiration_start_work >> /var/log/gitcoin/expiration_start_work.log 2>&1 15 1 * * * cd gitcoin/coin; bash scripts/run_management_command.bash sync_keywords >> /var/log/gitcoin/sync_keywords.log 2>&1