Skip to content

Commit

Permalink
Check elections results against bot csv
Browse files Browse the repository at this point in the history
  • Loading branch information
VirginiaDooley committed May 4, 2022
1 parent 3eb7637 commit b307ba9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ <h2><a href="{{ group.grouper.get_absolute_url }}">{{ group.grouper }}</a></h2>
<li>
<a href="{{ ballot.get_absolute_url }}">{{ ballot.post.label }}</a>
<a href="{% url "ballot_paper_results_form" ballot.ballot_paper_id %}" class="button tiny">Add results</a>
{% if ballot.results_by_bot %}
<p>馃 A robot will likely import these results. Skip me for now.</p>
{% endif %}
</li>
{% endfor %}
</ul>
Expand Down
25 changes: 25 additions & 0 deletions ynr/apps/uk_results/views/base_views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import csv
from datetime import date
import os

from braces.views import LoginRequiredMixin
from django.http import HttpResponse
Expand All @@ -10,6 +11,7 @@
from popolo.models import Membership
from results.models import ResultEvent
from uk_results.forms import ResultSetForm
from ynr.apps import resultsbot


class ResultsHomeView(TemplateView):
Expand Down Expand Up @@ -80,6 +82,29 @@ def get_context_data(self, **kwargs):

return context

def get_ballot_paper_ids_from_csv(self):
path = os.path.join(
os.path.dirname(resultsbot.__file__), "election_id_to_url.csv"
)
with open(path) as f:
csv_file = csv.reader(f)
ballot_paper_ids = []
for row in csv_file:
try:
ballot_paper_ids.append(row[0])
except IndexError:
continue
return ballot_paper_ids

def results_by_bot(self):
elections = self.context["elections"]
ballot_paper_ids = self.get_ballot_paper_ids_from_csv()
for election in elections:
if election.ballot_paper_id in ballot_paper_ids:
return True
else:
return False


class Parl19ResultsCSVView(TemplateView):
"""
Expand Down

0 comments on commit b307ba9

Please sign in to comment.