Skip to content

Commit

Permalink
Add newsletter-widget-share folder contents
Browse files Browse the repository at this point in the history
Previously, the newsletter-widget-share folder was not published to this repo. This adds all files contained in that local folder.
  • Loading branch information
kklinges committed Jan 29, 2024
1 parent 44aed0e commit 0f3fb3c
Show file tree
Hide file tree
Showing 68 changed files with 20,004 additions and 1 deletion.
54 changes: 53 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,53 @@
# newsletter-upcoming-elections
# newsletter-upcoming-elections

Steps to create newsletter upcoming elections map

First time only
do: $git clone https://github.com/cicero-data/newsletter-upcoming-elections
this will create a copy of the newsletter-upcoming-elections folder/repo

1. run sql script in pgadmin
1a. export results as csv
1b. save csv in sql-script-output/ folder
1c. inspect csv, if you see chambers where "upcoming election" == NULL
A. either fix the election in Cicero and rerun the sql script
B. or remove the row from the csv

2. update variables in gentable_local_sql.py and run it
2a. SQL_FILEPATH should be the path the file saved in step 1b
2b. OUTPUTFOLDERNAME should be a folder where the script will write output
A. create 2 folders corresponding to OUTPUTFOLDERNAME in the project directory
1. 2022-3-22-output-tables
2. 2022-3-22-output-tables-geooutput
2c. EMAIL_DATE should be the date the email will be sent
2d. TODAY should be today's date
2e. run gentable_local_sql.py

3. convert script output to geojson
3a. open 2022-3-22-output-tables-geooutput/upcoming.csv
3b. remove duplicate elections in same locale (i.e. combine Mayor and City Council to one row)
3c. use csv2geojson to convert csv (https://github.com/mapbox/csv2geojson)
A. ex. $csv2geojson upcoming-dedupe.csv > 3-2022-upcoming-elections.geojson

4. upload geojson to github as gist
4a. go to your github account, create a new secret gist, give is a useful title like "3-2022-upcoming-elections.geojson"
4b. paste the geojson contents into the gist body, dont upload the file
4c. in step 5 you will click the "raw" button on the gist and grab the url to paste into the map code in index.html

5. create new copy of index.html
5a. the master copy of index.html that gets published lives in the folder newsletter-upcoming-elections/
A. this folder is the github repo
5b. it is good to keep a copy for each time we publish the map
A. ie. map-3-2022/index.html
5c. in index.html change the title of the map (look for <div class="header-subtitle">)
5d. also in index.html, change the url pointed to by "data" in the "elections" source to the gist url from step 4
5e. to inspect index.html, right click and select "open with firefox", this will open the file in your browser

6. update and push
6a. Once index.html looks good locally, put the file in newsletter-upcoming-elections/ (the github repo)
6b. run $git status to make sure the changes (should be just 2 lines) look alright
6b.1. you may needd to run $git add <upcoming_elections.csv> to add changes
6c. run $git commit -m 'march 2022 map' to commit the update
6d. run $git push origin master to push the update to the cicero data repo
6e. inspect the github pages url https://cicero-data.github.io/newsletter-upcoming-elections/
6f. we usually post a screenshot of the map in the newsletter, so take a screenshot and save it as a png and jpg
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,239 @@
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {
"name_formal": "Legislative Assembly of New Brunswick",
"state": "NB",
"gov_type": "STATE",
"country_code": "CA",
"official_count": "49",
"term_length": "",
"url": "https://www1.gnb.ca/legis/bios/59/index-e.asp",
"upcoming_election": "2020-09-14 05:00:00+00:00",
"ue_remarks": "",
"ue_url_1": "",
"special": "False",
"runoff": "False",
"ue_cicero_link": "https://cicero.azavea.com/v3.1/admin/webservice/electionevent/18256/change/",
"next_election_display": "Sep 14, 2020"
},
"geometry": {
"type": "Point",
"coordinates": [
-65.9339830999618,
46.3473324972309
]
}
},
{
"type": "Feature",
"properties": {
"name_formal": "Mississippi State Senate 39 Special Election",
"state": "MS",
"gov_type": "STATE",
"country_code": "US",
"official_count": "52",
"term_length": "4 years",
"url": "http://billstatus.ls.state.ms.us/",
"upcoming_election": "2020-09-22 05:00:00+00:00",
"ue_remarks": "District 39 (Special Election)",
"ue_url_1": "",
"special": "True",
"runoff": "False",
"ue_cicero_link": "https://cicero.azavea.com/v3.1/admin/webservice/electionevent/18233/change/",
"next_election_display": "Sep 22, 2020"
},
"geometry": {
"type": "Point",
"coordinates": [
-89.5912112276585,
32.6211429875054
]
}
},
{
"type": "Feature",
"properties": {
"name_formal": "United States House of Representatives GA-5 Special Election ",
"state": "",
"gov_type": "NATIONAL",
"country_code": "US",
"official_count": "441",
"term_length": "",
"url": "http://www.house.gov/",
"upcoming_election": "2020-09-29 05:00:00+00:00",
"ue_remarks": "GA-5 (Special Election)",
"ue_url_1": "",
"special": "True",
"runoff": "False",
"ue_cicero_link": "https://cicero.azavea.com/v3.1/admin/webservice/electionevent/18235/change/",
"next_election_display": "Sep 29, 2020"
},
"geometry": {
"type": "Point",
"coordinates": [
-84.33041,
33.39326
]
}
},
{
"type": "Feature",
"properties": {
"name_formal": "Halifax Mayor & Regional Council",
"state": "NS",
"gov_type": "LOCAL",
"country_code": "CA",
"official_count": "16",
"term_length": "4 years",
"url": "https://www.halifax.ca/city-hall/districts-councillors",
"upcoming_election": "2020-10-17 05:00:00+00:00",
"ue_remarks": "Mayor plus 16 Councillors",
"ue_url_1": "",
"special": "False",
"runoff": "False",
"ue_cicero_link": "https://cicero.azavea.com/v3.1/admin/webservice/electionevent/16544/change/",
"next_election_display": "Oct 17, 2020"
},
"geometry": {
"type": "Point",
"coordinates": [
-63.5273998452465,
44.7155662856456
]
}
},
{
"type": "Feature",
"properties": {
"name_formal": "New Zealand House of Representatives",
"state": "",
"gov_type": "NATIONAL",
"country_code": "NZ",
"official_count": "120",
"term_length": "3 years",
"url": "https://www.parliament.nz/en/mps-and-electorates/members-of-parliament/",
"upcoming_election": "2020-10-17 05:00:00+00:00",
"ue_remarks": "120 seats in the House of Representatives & 2 questions will be presented",
"ue_url_1": "https://en.wikipedia.org/wiki/2020_New_Zealand_general_election",
"special": "False",
"runoff": "False",
"ue_cicero_link": "https://cicero.azavea.com/v3.1/admin/webservice/electionevent/18254/change/",
"next_election_display": "Oct 17, 2020"
},
"geometry": {
"type": "Point",
"coordinates": [
169.178923477224,
-39.4935540437362
]
}
},
{
"type": "Feature",
"properties": {
"name_formal": "The Legislative Assembly for the Australian Capital Territory",
"state": "ACT",
"gov_type": "STATE",
"country_code": "AS",
"official_count": "25",
"term_length": "4 years",
"url": "https://www.parliament.act.gov.au/",
"upcoming_election": "2020-10-17 05:00:00+00:00",
"ue_remarks": "25 seats in the ACT Legislative Assembly",
"ue_url_1": "https://en.wikipedia.org/wiki/2020_Australian_Capital_Territory_general_election",
"special": "False",
"runoff": "False",
"ue_cicero_link": "https://cicero.azavea.com/v3.1/admin/webservice/electionevent/17877/change/",
"next_election_display": "Oct 17, 2020"
},
"geometry": {
"type": "Point",
"coordinates": [
149.061430298787,
-35.3247040947742
]
}
},
{
"type": "Feature",
"properties": {
"name_formal": "Saskatoon Mayor & City Council",
"state": "SK",
"gov_type": "LOCAL",
"country_code": "CA",
"official_count": "10",
"term_length": "4 years",
"url": "https://www.saskatoon.ca/city-hall/mayor-city-councillors/city-councillors",
"upcoming_election": "2020-10-28 05:00:00+00:00",
"ue_remarks": "Mayor and City Council",
"ue_url_1": "https://www.saskatoon.ca/city-hall/voting-elections",
"special": "False",
"runoff": "False",
"ue_cicero_link": "https://cicero.azavea.com/v3.1/admin/webservice/electionevent/16551/change/",
"next_election_display": "Oct 28, 2020"
},
"geometry": {
"type": "Point",
"coordinates": [
-106.64855065021,
52.1335337295638
]
}
},
{
"type": "Feature",
"properties": {
"name_formal": "Regina Mayor & City Council",
"state": "SK",
"gov_type": "LOCAL",
"country_code": "CA",
"official_count": "10",
"term_length": "4 years",
"url": "https://www.regina.ca/residents/council-committees/meet-city-council/",
"upcoming_election": "2020-10-28 05:00:00+00:00",
"ue_remarks": "Mayor and City Council",
"ue_url_1": "https://www.regina.ca/residents/city-administration/office-of-the-city-clerk/index.html",
"special": "False",
"runoff": "False",
"ue_cicero_link": "https://cicero.azavea.com/v3.1/admin/webservice/electionevent/16593/change/",
"next_election_display": "Oct 28, 2020"
},
"geometry": {
"type": "Point",
"coordinates": [
-104.620369161151,
50.4552830021253
]
}
},
{
"type": "Feature",
"properties": {
"name_formal": "Queensland Legislative Assembly",
"state": "QLD",
"gov_type": "STATE",
"country_code": "AS",
"official_count": "93",
"term_length": "3 years (approx)",
"url": "https://www.parliament.qld.gov.au/",
"upcoming_election": "2020-10-31 05:00:00+00:00",
"ue_remarks": "All 93 seats in the Legislative Assembly of the unicameral parliament will be up for election.",
"ue_url_1": "https://en.wikipedia.org/wiki/Queensland_state_election,_2020",
"special": "False",
"runoff": "False",
"ue_cicero_link": "https://cicero.azavea.com/v3.1/admin/webservice/electionevent/18063/change/",
"next_election_display": "Oct 31, 2020"
},
"geometry": {
"type": "Point",
"coordinates": [
151.726214223837,
-25.8384524819585
]
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
WITH elections AS (
SELECT
eec.chamber_id,
ee.election_expire_date as edate,
ee.remarks,
ee.url_1,
ee.id,
ee.is_by_election,
ee.is_runoff_election
FROM webservice_electionevent ee
LEFT JOIN webservice_electionevent_chambers eec
ON ee.id = eec.electionevent_id
INNER JOIN webservice_chamber c ON eec.chamber_id = c.id
INNER JOIN webservice_government g ON c.government_id = g.id
WHERE ee.trans_to IS null AND
(ee.election_expire_date > now() AND
ee.election_expire_date < now() + INTERVAL '120 day' )
AND NOT ee.is_primary_election
AND NOT ( (ee.is_local OR ee.is_state) AND g.type='NATIONAL')
GROUP BY ee.election_expire_date, eec.chamber_id, ee.remarks, ee.url_1, ee.id
),
chambers_with_officials AS (
SELECT c.id, c.sk, c.name_formal, g.state, g.type as gov_type, s.fips as country_code, c.official_count, c.term_length, c.url, c.election_frequency
FROM webservice_chamber c
LEFT JOIN webservice_official o ON c.id = o.chamber_id
INNER JOIN webservice_government g ON c.government_id = g.id
INNER JOIN webservice_country s ON g.country_id = s.id
WHERE o.trans_to IS null AND o.valid_to > now() AND c.trans_to IS null
GROUP BY c.id, c.sk, c.name_formal, g.state, gov_type, country_code, c.term_length
)
SELECT
c.id, c.sk, c.name_formal, state, gov_type, country_code, c.official_count, c.term_length, c.url,
ue.upcoming_election, ue.remarks as ue_remarks, ue.url_1 as ue_url_1, ue.is_by_election as special, ue.is_runoff_election as runoff,
CONCAT ('https://cicero.azavea.com/v3.1/admin/webservice/electionevent/', ue.id , '/change/') as ue_cicero_link
FROM chambers_with_officials c

RIGHT JOIN
(SELECT chamber_id, edate AS upcoming_election, remarks, url_1, id, is_by_election, is_runoff_election
FROM elections
ORDER BY chamber_id, edate DESC NULLS LAST, remarks, url_1, id, is_by_election, is_runoff_election) ue

ON c.id = ue.chamber_id
WHERE c.id IS NOT NULL
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name_formal,state,gov_type,country_code,official_count,term_length,url,upcoming_election,ue_remarks,ue_url_1,special,runoff,ue_cicero_link,lat,lon,next_election_display
Legislative Assembly of New Brunswick,NB,STATE,CA,49,,https://www1.gnb.ca/legis/bios/59/index-e.asp,2020-09-14 05:00:00+00:00,,,False,False,https://cicero.azavea.com/v3.1/admin/webservice/electionevent/18256/change/,46.3473324972309,-65.9339830999618,"Sep 14, 2020"
Mississippi State Senate 39 Special Election,MS,STATE,US,52,4 years,http://billstatus.ls.state.ms.us/,2020-09-22 05:00:00+00:00,District 39 (Special Election),,True,False,https://cicero.azavea.com/v3.1/admin/webservice/electionevent/18233/change/,32.6211429875054,-89.5912112276585,"Sep 22, 2020"
United States House of Representatives GA-5 Special Election ,,NATIONAL,US,441,,http://www.house.gov/,2020-09-29 05:00:00+00:00,GA-5 (Special Election),,True,False,https://cicero.azavea.com/v3.1/admin/webservice/electionevent/18235/change/,33.39326,-84.33041,"Sep 29, 2020"
Halifax Mayor & Regional Council,NS,LOCAL,CA,16,4 years,https://www.halifax.ca/city-hall/districts-councillors,2020-10-17 05:00:00+00:00,Mayor plus 16 Councillors,,False,False,https://cicero.azavea.com/v3.1/admin/webservice/electionevent/16544/change/,44.7155662856456,-63.5273998452465,"Oct 17, 2020"
New Zealand House of Representatives,,NATIONAL,NZ,120,3 years,https://www.parliament.nz/en/mps-and-electorates/members-of-parliament/,2020-10-17 05:00:00+00:00,120 seats in the House of Representatives & 2 questions will be presented,https://en.wikipedia.org/wiki/2020_New_Zealand_general_election,False,False,https://cicero.azavea.com/v3.1/admin/webservice/electionevent/18254/change/,-39.4935540437362,169.178923477224,"Oct 17, 2020"
The Legislative Assembly for the Australian Capital Territory,ACT,STATE,AS,25,4 years,https://www.parliament.act.gov.au/,2020-10-17 05:00:00+00:00,25 seats in the ACT Legislative Assembly,https://en.wikipedia.org/wiki/2020_Australian_Capital_Territory_general_election,False,False,https://cicero.azavea.com/v3.1/admin/webservice/electionevent/17877/change/,-35.3247040947742,149.061430298787,"Oct 17, 2020"
Saskatoon Mayor & City Council,SK,LOCAL,CA,10,4 years,https://www.saskatoon.ca/city-hall/mayor-city-councillors/city-councillors,2020-10-28 05:00:00+00:00,Mayor and City Council,https://www.saskatoon.ca/city-hall/voting-elections,False,False,https://cicero.azavea.com/v3.1/admin/webservice/electionevent/16551/change/,52.1335337295638,-106.64855065021,"Oct 28, 2020"
Regina Mayor & City Council,SK,LOCAL,CA,10,4 years,https://www.regina.ca/residents/council-committees/meet-city-council/,2020-10-28 05:00:00+00:00,Mayor and City Council,https://www.regina.ca/residents/city-administration/office-of-the-city-clerk/index.html,False,False,https://cicero.azavea.com/v3.1/admin/webservice/electionevent/16593/change/,50.4552830021253,-104.620369161151,"Oct 28, 2020"
Queensland Legislative Assembly,QLD,STATE,AS,93,3 years (approx),https://www.parliament.qld.gov.au/,2020-10-31 05:00:00+00:00,All 93 seats in the Legislative Assembly of the unicameral parliament will be up for election.,"https://en.wikipedia.org/wiki/Queensland_state_election,_2020",False,False,https://cicero.azavea.com/v3.1/admin/webservice/electionevent/18063/change/,-25.8384524819585,151.726214223837,"Oct 31, 2020"
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<html><table border="1">
<tr><th>Date</th><th>Chamber</th><th>Description</th></tr><tr><td>Sep 14, 2020</td><td><a href='https://www1.gnb.ca/legis/bios/59/index-e.asp' target='_blank'>Legislative Assembly of New Brunswick</a></td><td></td></tr><tr><td>Sep 22, 2020</td><td><a href='http://billstatus.ls.state.ms.us/' target='_blank'>Mississippi State Senate</a></td><td>District 39 (Special Election)</td></tr><tr><td>Sep 29, 2020</td><td><a href='http://www.house.gov/' target='_blank'>United States House of Representatives</a></td><td>GA-5 (Special Election)</td></tr><tr><td>Oct 17, 2020</td><td><a href='https://www.halifax.ca/city-hall/mayor-mike-savage' target='_blank'>Halifax Mayor</a></td><td>Mayor plus 16 Councillors</td></tr><tr><td>Oct 17, 2020</td><td><a href='https://www.halifax.ca/city-hall/districts-councillors' target='_blank'>Halifax Regional Council</a></td><td>Mayor plus 16 Councillors</td></tr><tr><td>Oct 17, 2020</td><td><a href='https://en.wikipedia.org/wiki/2020_New_Zealand_cannabis_referendum' target='_blank'>New Zealand House of Representatives</a></td><td>Two questions will be presented: legalisation of cannabis and legalisation of voluntary euthanasia for those with a terminal illness</td></tr><tr><td>Oct 17, 2020</td><td><a href='https://en.wikipedia.org/wiki/2020_New_Zealand_general_election' target='_blank'>New Zealand House of Representatives</a></td><td>120 seats in the House of Representatives</td></tr><tr><td>Oct 17, 2020</td><td><a href='https://en.wikipedia.org/wiki/2020_Australian_Capital_Territory_general_election' target='_blank'>The Legislative Assembly for the Australian Capital Territory</a></td><td>25 seats in the ACT Legislative Assembly</td></tr><tr><td>Oct 28, 2020</td><td><a href='https://www.regina.ca/residents/city-administration/office-of-the-city-clerk/index.html' target='_blank'>Regina Mayor</a></td><td>Mayor and City Council</td></tr><tr><td>Oct 28, 2020</td><td><a href='https://www.saskatoon.ca/city-hall/voting-elections' target='_blank'>Saskatoon Mayor</a></td><td></td></tr><tr><td>Oct 28, 2020</td><td><a href='https://www.saskatoon.ca/city-hall/voting-elections' target='_blank'>Saskatoon City Council</a></td><td></td></tr><tr><td>Oct 28, 2020</td><td><a href='https://www.regina.ca/residents/city-administration/office-of-the-city-clerk/index.html' target='_blank'>Regina City Council</a></td><td>Mayor and City Council</td></tr><tr><td>Oct 31, 2020</td><td><a href='https://en.wikipedia.org/wiki/Queensland_state_election,_2020' target='_blank'>Queensland Legislative Assembly</a></td><td>All 93 seats in the Legislative Assembly of the unicameral parliament will be up for election.</td></tr></table></html>
Loading

0 comments on commit 0f3fb3c

Please sign in to comment.