Repository: AlexsLemonade/refinebio

Issue:
Engagement bot summary doesn't seem to be working
### Context

https://github.com/AlexsLemonade/refinebio/issues/2140

### Problem or idea

Tested today and reported no downloads in the last 7 days.

> **EngagementBot**
> There were no downloads in the last 7 days.

However there were a few that should have been counted:

```
data_refinery=> select id, created_at from data_refinery_common_dataset where is_processed='t' and email_address is not NULL order by created_at desc limit 10;
                  id                  |          created_at           
--------------------------------------+-------------------------------
 381e86b9-aea2-4d9a-8a61-338b111fe54d | 2020-03-29 13:06:28.954778+00
 eb726da7-8006-46c4-95ba-8a3bcecbd6f1 | 2020-03-26 02:26:35.196333+00
 099e7b58-dce6-4d5c-a4b6-f4d049dad866 | 2020-03-25 16:19:14.656207+00
 c4c086ef-6963-4fd8-b4e2-a7cf09c9eb68 | 2020-03-25 16:18:03.158765+00
 0716857b-211f-484c-9e2b-3e447dd5cdaf | 2020-03-25 15:34:20.155269+00
 2e7c1e1c-138b-43b1-9463-0113c64e7edb | 2020-03-25 15:19:23.577922+00
 4a2ac1ef-4e9e-4945-bdf8-00d595f99c4c | 2020-03-25 15:18:21.49652+00
 bbb30f4e-7b5f-4595-a47d-25f8d72e4a7c | 2020-03-25 15:03:55.391917+00
 eff9cbe4-c4f5-43a6-b004-6cd36f10ea15 | 2020-03-24 22:41:51.185922+00
```

### Solution or next step

Investigate why these downloads are not being reported.



Discussion:

Resolving patch:
diff --git a/api/data_refinery_api/management/commands/post_downloads_summary.py b/api/data_refinery_api/management/commands/post_downloads_summary.py
--- a/api/data_refinery_api/management/commands/post_downloads_summary.py
+++ b/api/data_refinery_api/management/commands/post_downloads_summary.py
@@ -28,7 +28,7 @@ def add_arguments(self, parser):
 
     def handle(self, *args, **options):
         days = options["days"]
-        start_time = timezone.now() - datetime.timedelta(days=-days)
+        start_time = timezone.now() - datetime.timedelta(days=days)
 
         annotation_queryset = DatasetAnnotation.objects.filter(
             created_at__gt=start_time
@@ -105,16 +105,15 @@ def should_display_email(email: str) -> bool:
     """ Returns true if the given email is not associated with the CCDL suers """
     if not email:
         return False
-
     return not (
         email.startswith("cansav09")
         or email.startswith("arielsvn")
         or email.startswith("jaclyn.n.taroni")
         or email.startswith("kurt.wheeler")
         or email.startswith("greenescientist")
-        or "@alexslemonade.org" not in email
         or email.startswith("miserlou")
         or email.startswith("d.prasad")
+        or email.endswith("@alexslemonade.org")
         or email is ("daniel.himmelstein@gmail.com")
         or email is ("dv.prasad991@gmail.com")
     )
@@ -122,7 +121,7 @@ def should_display_email(email: str) -> bool:
 
 def get_ip_location(remote_ip):
     try:
-        city = requests.get("https://ipapi.co/" + remote_ip + "/json/", timeout=10).json()["city"]
+        data = requests.get("https://ipapi.co/" + remote_ip + "/json/", timeout=10).json()
+        return "{0}, {1}".format(data["city"], data["country_name"])
     except Exception:
-        city = remote_ip
-    return city
+        return remote_ip


Test patch: