From 3d85448b0e2c81eecff00d7f02ce52c2724f4303 Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Sun, 26 Apr 2020 03:36:59 +0000 Subject: [PATCH] Add script to import old member signup counts --- apiserver/import_signup_counts.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100755 apiserver/import_signup_counts.py diff --git a/apiserver/import_signup_counts.py b/apiserver/import_signup_counts.py new file mode 100755 index 0000000..f2681fe --- /dev/null +++ b/apiserver/import_signup_counts.py @@ -0,0 +1,22 @@ +# Expects a old_counts.csv of the historical counts in format: +# month,signup_count +# month in YYYY-MM format + +import django, sys, os +os.environ['DJANGO_SETTINGS_MODULE'] = 'apiserver.settings' +django.setup() + +import csv +from apiserver.api import models + +with open('old_counts.csv', newline='') as csvfile: + reader = csv.DictReader(csvfile) + for row in reader: + print('Adding', row['month'], row['signup_count']) + + models.StatsMemberSignup.objects.update_or_create( + month=row['month']+'-01', + defaults=dict(signup_count=row['signup_count']), + ) + +print('Done.')