Add script to import old member counts from csv
This commit is contained in:
parent
8d4a63fbfc
commit
20c93cd5c4
1
apiserver/.gitignore
vendored
1
apiserver/.gitignore
vendored
|
@ -113,3 +113,4 @@ old_paypal/
|
|||
missing_paypal/
|
||||
backups/
|
||||
secrets.py
|
||||
old_counts.csv
|
||||
|
|
21
apiserver/import_member_counts.py
Executable file
21
apiserver/import_member_counts.py
Executable file
|
@ -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.')
|
Loading…
Reference in New Issue
Block a user