Skip to content

Commit 4410e8e

Browse files
committed
management command to import council minutes links
1 parent 9a7cc83 commit 4410e8e

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
from django.conf import settings
2+
from django.core.management.base import BaseCommand
3+
4+
import pandas as pd
5+
6+
from crowdsourcer.models import AuthorityData, PublicAuthority
7+
8+
9+
class Command(BaseCommand):
10+
help = "import council minutes links"
11+
12+
data_file = settings.BASE_DIR / "data" / "council_minutes.csv"
13+
14+
def handle(self, *args, **kwargs):
15+
df = pd.read_csv(self.data_file)
16+
df = df.dropna(subset=["campaigns_lab_url"])
17+
18+
for _, row in df.iterrows():
19+
gss = row["gss-code"]
20+
if not pd.isna(gss):
21+
try:
22+
authority = PublicAuthority.objects.get(unique_id=gss)
23+
except PublicAuthority.DoesNotExist:
24+
self.stderr.write(
25+
f"could not find authority with GSS code {gss} ({row['official-name']}"
26+
)
27+
continue
28+
29+
ad, _ = AuthorityData.objects.update_or_create(
30+
authority=authority,
31+
data_name="council_minutes",
32+
defaults={
33+
"data_value": row["campaigns_lab_url"],
34+
},
35+
)
36+
print(authority.name)

0 commit comments

Comments
 (0)