From 20c93cd5c4c2a5502ea18957b34df85224867309 Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Tue, 21 Apr 2020 05:46:40 +0000 Subject: [PATCH] Add script to import old member counts from csv --- apiserver/.gitignore | 1 + apiserver/import_member_counts.py | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100755 apiserver/import_member_counts.py diff --git a/apiserver/.gitignore b/apiserver/.gitignore index e1e3561..cd3de99 100644 --- a/apiserver/.gitignore +++ b/apiserver/.gitignore @@ -113,3 +113,4 @@ old_paypal/ missing_paypal/ backups/ secrets.py +old_counts.csv diff --git a/apiserver/import_member_counts.py b/apiserver/import_member_counts.py new file mode 100755 index 0000000..7792168 --- /dev/null +++ b/apiserver/import_member_counts.py @@ -0,0 +1,21 @@ +# Expects a old_counts.csv of the historical counts in format: +# date,member_count,green_count + +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['date'], row['member_count'], row['green_count']) + + models.StatsMemberCount.objects.update_or_create( + date=row['date'], + defaults=dict(member_count=row['member_count'], green_count=row['green_count']), + ) + +print('Done.')