Skip to content

Instantly share code, notes, and snippets.

@jtallieu
Created August 4, 2014 21:11
Show Gist options
  • Save jtallieu/ee1fd2def497560c12e4 to your computer and use it in GitHub Desktop.
Save jtallieu/ee1fd2def497560c12e4 to your computer and use it in GitHub Desktop.
import os
import sys
import csv
path = os.path.normpath(os.path.join(os.getcwd(), '..'))
sys.path.append(path)
path = os.path.normpath(os.path.join(os.getcwd(), '..','possync'))
sys.path.append(path)
from django.core.management import setup_environ
import settings
setup_environ(settings)
from django.utils.timezone import datetime, utc, is_aware
from datetime import timedelta
from sync.models import *
fields = ["UUID", "email", "First Name", "Last Name", "Status",
"Active", "Trial", "Plan", "Cart", "Pos",
"Store Url", "Referral", "Created", "Renew Date"]
csvfile = open("accounts.csv", "wb")
report = csv.DictWriter(csvfile, fields, restval="", extrasaction="ignore")
report.writeheader()
for s in SyncProfile.objects.all():
account = {}
account["UUID"] = s.uuid
account["email"] = s.user.email
account["First Name"] = s.user.first_name
account["Last Name"] = s.user.last_name
account["Status"] = s.status
account["Active"] = "Yes" if s.is_plan_active else "No"
account["Trial"] = "Yes" if s.is_trial else "No"
account["Plan"] = s.plan
account["Cart"] = s.online_store.store_type
account["Pos"] = s.pos_app.store_type
account["Store Url"] = s.online_store.host
account["Referral"] = s.referral_code
account["Created"] = s.created.strftime("%Y-%m-%d")
account["Renew Date"] = s.renew_date.strftime("%Y-%m-%d")
print "Writing", account["email"]
try:
report.writerow(account)
except:
print "\tUnable to write", account["email"]
csvfile.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment