def handle(self, *args, **options): if settings.DEBUG: print("not active in non prod environments") return hours_back = 24 eses = EmailSubscriber.objects.filter(active=True) print("got {} emails".format(eses.count())) for es in eses: try: keywords = es.keywords if not keywords: continue to_email = es.email bounties_pks = [] for keyword in keywords: for bounty in Bounty.objects.filter( network='mainnet', web3_created__gt=( timezone.now() - timezone.timedelta(hours=hours_back)), current_bounty=True, metadata__icontains=keyword, ): bounties_pks.append(bounty.pk) bounties = Bounty.objects.filter(pk__in=bounties_pks) #print("{}/{}: got {} bounties".format(to_email, keywords, bounties.count())) if bounties.count(): print(f"sent to {to_email}") new_bounty(bounties, [to_email]) except Exception as e: logging.exception(e) print(e)
def handle(self, *args, **options): for sub in Subscription.objects.all(): url = "https://gitcoin.co/" + sub.raw_data bounties_pks = [b['pk'] for b in requests.get(url).json()] for bounty in Bounty.objects.filter(pk__in=bounties_pks, idx_status='open'): if bounty.web3_created > (timezone.now() - timezone.timedelta(hours=24)): new_bounty(bounty, to_emails=[sub.email])
def maybe_market_to_email(b, event_name): from marketing.mails import new_work_submission, new_bounty_rejection, new_bounty_acceptance, new_bounty from marketing.models import EmailSubscriber to_emails = [] if b.network != settings.ENABLE_NOTIFICATIONS_ON_NETWORK: return False if event_name == 'new_bounty' and not settings.DEBUG: try: # this doesnt scale because there are typically like 600 matches.. need to move to a background job return keywords = b.keywords.split(',') for keyword in keywords: to_emails = to_emails + list( EmailSubscriber.objects.filter( keywords__contains=[keyword.strip()]).values_list( 'email', flat=True)) should_send_email = b.web3_created > (timezone.now() - timezone.timedelta(hours=15)) # only send if the bounty is reasonbly new if should_send_email: for to_email in set(to_emails): new_bounty(b, [to_email]) except Exception as e: logging.exception(e) print(e) elif event_name == 'work_submitted': try: to_emails = [b.bounty_owner_email] new_work_submission(b, to_emails) except Exception as e: logging.exception(e) print(e) elif event_name == 'work_done': accepted_fulfillment = b.fulfillments.filter( accepted=True).latest('modified_on') try: to_emails = [ b.bounty_owner_email, accepted_fulfillment.fulfiller_email ] new_bounty_acceptance(b, to_emails) except Exception as e: logging.exception(e) print(e) elif event_name == 'rejected_claim': try: rejected_fulfillment = b.fulfillments.filter( accepted=False).latest('modified_on') to_emails = [ b.bounty_owner_email, rejected_fulfillment.fulfiller_email ] new_bounty_rejection(b, to_emails) except Exception as e: logging.exception(e) return len(to_emails)
def maybe_market_to_email(b, event_name, txid): from marketing.mails import new_bounty_claim, new_bounty_rejection, new_bounty_acceptance, new_bounty from marketing.models import EmailSubscriber to_emails = [] if b.network != settings.ENABLE_NOTIFICATIONS_ON_NETWORK: return False if event_name == 'new_bounty' and not settings.DEBUG: try: to_emails = [] keywords = b.keywords.split(',') for keyword in keywords: to_emails = to_emails + list( EmailSubscriber.objects.filter( keywords__contains=[keyword.strip()]).values_list( 'email', flat=True)) for to_email in set(to_emails): new_bounty(b, [to_email]) except Exception as e: logging.exception(e) print(e) if event_name == 'new_claim': try: to_emails = [b.bounty_owner_email] new_bounty_claim(b, to_emails) except Exception as e: logging.exception(e) print(e) if event_name == 'approved_claim': try: to_emails = [b.bounty_owner_email, b.claimee_email] new_bounty_acceptance(b, to_emails) except Exception as e: logging.exception(e) print(e) if event_name == 'rejected_claim': try: to_emails = [b.bounty_owner_email, b.claimee_email] new_bounty_rejection(b, to_emails) except Exception as e: logging.exception(e) print(e) return len(to_emails)