Skip to content

Commit

Permalink
Update import hustings for 2022 elections
Browse files Browse the repository at this point in the history
- Update the urls
- Allow urls to be specified as an argument when running command
- Add lambda event to run every hour
  • Loading branch information
michaeljcollinsuk committed Feb 8, 2022
1 parent 567141f commit 7cfc1e6
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
7 changes: 7 additions & 0 deletions sam-template.yaml
Expand Up @@ -124,6 +124,13 @@ Resources:
Name: batch-feedback-to-slack
Description: Send feedback entries for the last week to slack
Input: '{"command": "batch_feedback_to_slack", "args": ["--hours=168"]}'
ImportHustings:
Type: Schedule
Properties:
Schedule: rate(1 hour)
Name: import-hustings
Description: Import hustings from google spreadsheets
Input: '{"command": "import_hustings"}'

WCIVFCodeDeployApp:
Type: AWS::CodeDeploy::Application
Expand Down
32 changes: 23 additions & 9 deletions wcivf/apps/hustings/management/commands/import_hustings.py
Expand Up @@ -57,14 +57,19 @@ def set_time_string_on_datetime(dt, time_string):

class Command(BaseCommand):

GOOGLE_SHEET_URL = "https://docs.google.com/spreadsheets/d/e/2PACX-1vQIvJtlR9j6BaOuLjd501W4mPznJX41k1LalgkXvwRLj0d90lyFaW3PoVLzLvw5K4Kvv4lETQIJyzdL/"
URLS = [
f"{GOOGLE_SHEET_URL}pub?gid=0&single=true&output=csv",
f"{GOOGLE_SHEET_URL}pub?gid=742711428&single=true&output=csv",
f"{GOOGLE_SHEET_URL}pub?gid=908428564&single=true&output=csv",
f"{GOOGLE_SHEET_URL}pub?gid=1265695055&single=true&output=csv",
f"{GOOGLE_SHEET_URL}pub?gid=668485812&single=true&output=csv",
f"{GOOGLE_SHEET_URL}pub?gid=1596983142&single=true&output=csv",
# NI
"https://docs.google.com/spreadsheets/d/e/2PACX-1vT_VvyPiJA75yOCv7j_E0PjZe3yFy77C9RH9ucb1bM2_QBhSIWSRKsF3_qhcukrxQsRMu9SRyNXWX05/pub?gid=372490874&single=true&output=csv",
# ENG MAYORS
"https://docs.google.com/spreadsheets/d/e/2PACX-1vT_VvyPiJA75yOCv7j_E0PjZe3yFy77C9RH9ucb1bM2_QBhSIWSRKsF3_qhcukrxQsRMu9SRyNXWX05/pub?gid=1086162179&single=true&output=csv",
# ENG LOCALS
"https://docs.google.com/spreadsheets/d/e/2PACX-1vT_VvyPiJA75yOCv7j_E0PjZe3yFy77C9RH9ucb1bM2_QBhSIWSRKsF3_qhcukrxQsRMu9SRyNXWX05/pub?gid=1180606386&single=true&output=csv",
# SCOT LOCALS
"https://docs.google.com/spreadsheets/d/e/2PACX-1vT_VvyPiJA75yOCv7j_E0PjZe3yFy77C9RH9ucb1bM2_QBhSIWSRKsF3_qhcukrxQsRMu9SRyNXWX05/pub?gid=976193034&single=true&output=csv",
# WALES LOCALS
"https://docs.google.com/spreadsheets/d/e/2PACX-1vT_VvyPiJA75yOCv7j_E0PjZe3yFy77C9RH9ucb1bM2_QBhSIWSRKsF3_qhcukrxQsRMu9SRyNXWX05/pub?gid=2061283903&single=true&output=csv",
# BY-ELECTIONS
"https://docs.google.com/spreadsheets/d/e/2PACX-1vT_VvyPiJA75yOCv7j_E0PjZe3yFy77C9RH9ucb1bM2_QBhSIWSRKsF3_qhcukrxQsRMu9SRyNXWX05/pub?gid=1279122722&single=true&output=csv",
]

def add_arguments(self, parser):
Expand All @@ -80,6 +85,14 @@ def add_arguments(self, parser):
default=False,
help="Only output errors",
)
parser.add_argument(
"--urls",
"-u",
dest="urls",
nargs="+",
required=False,
help="Specify a URLs to a google sheet to import from",
)

def create_husting(self, row):
"""
Expand Down Expand Up @@ -136,7 +149,7 @@ def import_hustings(self):
self.hustings_counter += 1
self.stdout.write(
"Created husting {0} <{1}>".format(
self.hustings_counter, husting
self.hustings_counter, husting.post_election.ballot_paper_id
)
)

Expand Down Expand Up @@ -164,6 +177,7 @@ def handle(self, **options):
self.importer = HustingImporter(file_path=options["filename"])
return self.import_hustings()

for url in self.URLS:
urls = options["urls"] or self.URLS
for url in urls:
self.importer = HustingImporter(url=url)
self.import_hustings()

0 comments on commit 7cfc1e6

Please sign in to comment.