def process_acm(self, hours): created_gt = timezone.now() - timezone.timedelta(hours=hours) created_lt = timezone.now() - timezone.timedelta(hours=0) non_terminal_states = ['pending', 'na', 'unknown'] for obj_type in all_sendcryptoasset_models(): sent_txs = obj_type.objects.filter( created_on__gt=created_gt, created_on__lt=created_lt, tx_status__in=non_terminal_states).exclude(txid='').exclude( txid='pending_celery') receive_txs = obj_type.objects.filter( created_on__gt=created_gt, created_on__lt=created_lt, receive_tx_status__in=non_terminal_states).exclude( txid='').exclude(receive_txid='').exclude( receive_txid='pending_celery') objects = (sent_txs | receive_txs).distinct('id') print(f"got {objects.count()} {obj_type} to try") for obj in objects: print(f"- syncing {obj_type} / {obj.pk} / {obj.network}") if obj.tx_status in non_terminal_states: obj.update_tx_status() print(f" -- updated {obj.txid} to {obj.tx_status}") if obj.receive_tx_status in non_terminal_states: obj.update_receive_tx_status() print( f" -- updated {obj.receive_txid} to {obj.receive_tx_status}" ) obj.save()
def process_acm(self): non_terminal_states = ['pending', 'na', 'unknown'] for obj_type in all_sendcryptoasset_models(): sent_txs = obj_type.objects.filter(tx_status__in=non_terminal_states).exclude(txid='').exclude(txid='pending_celery') receive_txs = obj_type.objects.filter(receive_tx_status__in=non_terminal_states).exclude(txid='').exclude(receive_txid='').exclude(receive_txid='pending_celery') objects = (sent_txs | receive_txs).distinct('id') for obj in objects: print(f"syncing {obj_type} / {obj.pk} / {obj.network}") if obj.tx_status in non_terminal_states: obj.update_tx_status() print(f" - updated {obj.txid} to {obj.tx_status}") if obj.receive_tx_status in non_terminal_states: obj.update_receive_tx_status() print(f" - updated {obj.receive_txid} to {obj.receive_tx_status}") obj.save()
def handle(self, *args, **options): bounties = Bounty.objects.prefetch_related('fulfillments').current().filter( network='mainnet', web3_created__gte=options['start_date'], web3_created__lte=options['end_date'] ).order_by('web3_created', 'id') formatted_bounties = imap(self.format_bounty, bounties) frs = FaucetRequest.objects.filter( created_on__gte=options['start_date'], created_on__lte=options['end_date'], fulfilled=True, ).order_by('created_on', 'id') formatted_frs = imap(self.format_faucet_distribution, frs) all_scram = [] for _class in all_sendcryptoasset_models(): objs = _class.objects.filter( network='mainnet', created_on__gte=options['start_date'], created_on__lte=options['end_date'] ).send_success().order_by('created_on', 'id') objs = imap(self.format_cryptoasset, objs) objs = [x for x in objs] all_scram += objs enssubregistrations = ENSSubdomainRegistration.objects.filter( created_on__gte=options['start_date'], created_on__lte=options['end_date'] ).order_by('created_on', 'id') formted_enssubreg = imap(self.format_ens_reg, enssubregistrations) # python3 list hack formatted_frs = [x for x in formatted_frs] formatted_bounties = [x for x in formatted_bounties] formateted_enssubregistrations = [x for x in formted_enssubreg] all_items = formatted_bounties + all_scram + formatted_frs + formateted_enssubregistrations csvfile = StringIO() csvwriter = csv.DictWriter(csvfile, fieldnames=[ 'type', 'created_on', 'last_activity', 'amount', 'denomination', 'amount_eth', 'amount_usdt', 'from_address', 'claimee_address', 'repo', 'from_username', 'fulfiller_github_username', 'status', 'comments', 'payee_bio', 'payee_location']) csvwriter.writeheader() items = sorted(all_items, key=lambda x: x['created_on']) has_rows = False for item in items: has_rows = True csvwriter.writerow(item) start = options['start_date'].strftime(DATE_FORMAT_HYPHENATED) end = options['end_date'].strftime(DATE_FORMAT_HYPHENATED) now = str(datetime.datetime.now()) if has_rows: subject = f'Gitcoin Activity report from {start} to {end}' url = self.upload_to_s3(f'activity_report_{start}_{end}_generated_on_{now}.csv', csvfile.getvalue()) body = f'<a href="{url}">{url}</a>' print(url) send_mail( settings.CONTACT_EMAIL, settings.CONTACT_EMAIL, subject, body='', html=body, categories=['admin', 'activity_report'], ) self.stdout.write( self.style.SUCCESS('Sent activity report from %s to %s to %s' % (start, end, settings.CONTACT_EMAIL)) ) else: self.stdout.write(self.style.WARNING('No activity from %s to %s to report' % (start, end)))