Created
May 15, 2018 21:46
-
-
Save jobelenus/13d05981711cecded9c820e050d3e8aa to your computer and use it in GitHub Desktop.
What I just did as the final fix
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# STEP 1 REMOTE | |
import datetime | |
before = datetime.date(2018, 5, 15) | |
after = datetime.date(2018, 5, 1) | |
from shelby.models import Lead | |
qs = Lead.objects.filter(created_on__date__lt=before, created_on__date__gte=after, status=Lead.STATUS_NEW).values_list('id', flat=True) | |
for lead_id in qs: | |
print(lead_id) # copy that output into "new_leads.txt" | |
# STEP 2 - LOCAL w/ 5/15 1am backup db | |
from shelby.models import Lead | |
def fmtdate(d): | |
return d.isoformat() if d else 'None' | |
f = open('new_leads.txt', 'r') # open the leads from prod that are new | |
output = open('output_leads.txt', 'w') | |
lines = f.readlines() | |
for lead_id in lines: | |
lead = Lead.objects.get(id=lead_id) # look at 5/15 1am backup data | |
if lead.status != lead.STATUS_NEW: | |
line = "'{}^{}^{}^{}^{}^{}',\n".format(lead.id, lead.status, fmtdate(lead.reviewed_on), fmtdate(lead.bad_on), fmtdate(lead.na_on), fmtdate(lead.inactive_on)) | |
foo = output.write(line) | |
f.close() | |
output.close() | |
# STEP 3 - PROD REMOTE | |
lines = [ | |
# paste the contents of output.txt here | |
] | |
from shelby.models import Lead | |
import dateutil.parser | |
for line in lines: | |
data = line.split('^') | |
lead_id = data[0] | |
status = data[1] | |
reviewed_on = data[2] | |
bad_on = data[3] | |
na_on = data[4] | |
inactive_on = data[5] | |
lead = Lead.objects.get(id=lead_id) | |
lead.status = status | |
if reviewed_on != 'None': | |
lead.reviewed_on = dateutil.parser.parse(reviewed_on) | |
if bad_on != 'None': | |
lead.bad_on = dateutil.parser.parse(bad_on) | |
if na_on != 'None': | |
lead.na_on = dateutil.parser.parse(na_on) | |
if inactive_on != 'None': | |
lead.inactive_on = dateutil.parser.parse(inactive_on) | |
lead.save() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment