def handle(self, *args, **options): emailsubscribers = EmailSubscriber.objects.filter(github='') success = 0 exceptions = 0 for es in emailsubscribers: # print(es.email) try: es.github = get_github_user_from_DB(es.email) if not es.github: ghuser = get_github_user_from_github(es.email) es.github = ghuser['login'] if not es.keywords: es.keywords = profile_keywords_helper(es.github) es.save() # print(es.email, es.github, es.keywords) success += 1 except Exception: exceptions += 1 time.sleep(2) print("success: {}".format(success)) print("total: {}".format(emailsubscribers.count())) print("pct: {}".format(round(success / emailsubscribers.count(), 2))) print("exceptions: {}".format(exceptions)) print("total: {}".format(emailsubscribers.count())) print("pct: {}".format(round(exceptions / emailsubscribers.count(), 2)))
def handle(self, *args, **options): es_without_github = EmailSubscriber.objects.filter(github='') es_without_keywords = EmailSubscriber.objects.filter(keywords=[]) emailsubscribers = (es_without_github | es_without_keywords).distinct('pk').order_by('-pk') es_without_keywords_count = es_without_keywords.count() es_without_github_count = es_without_github.count() success = 0 exceptions = 0 for es in emailsubscribers: # print(es.email) try: if not es.github: es.github = get_github_user_from_DB(es.email) if not es.github: ghuser = get_github_user_from_github(es.email) es.github = ghuser['login'] if not es.keywords: es.keywords = profile_keywords_helper(es.github) if es.keywords: print(f"got keywords: {es.keywords}") es.save() # print(es.email, es.github, es.keywords) success += 1 except Exception: exceptions += 1 time.sleep(2) print("success: {}".format(success)) print("total: {}".format(emailsubscribers.count())) print("pct: {}".format(round(success / emailsubscribers.count(), 2))) print("exceptions: {}".format(exceptions)) print("total: {}".format(emailsubscribers.count())) print("pct: {}".format(round(exceptions / emailsubscribers.count(), 2))) print("===========================") print( f"es_without_keywords_count; before: {es_without_keywords_count}, after: {es_without_keywords.count()}" ) print( f"es_without_github_count; before: {es_without_github_count}, after: {es_without_github.count()}" )