Skip to content

Commit

Permalink
Add timestamps to page
Browse files Browse the repository at this point in the history
  • Loading branch information
titanous committed Nov 6, 2020
1 parent ae2a0ea commit 6e7910b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
12 changes: 9 additions & 3 deletions battleground-state-changes.html.tmpl
Expand Up @@ -67,7 +67,7 @@
}
}
</style>
<title>Election 2020 | Last scrape: {% SCRAPE %}</title>
<title>Election 2020 Results</title>
</head>

<body>
Expand All @@ -78,13 +78,14 @@
This website is <a href="https://github.com/alex/nyt-2020-election-scraper">open source</a> and was written by <a href="https://github.com/alex/nyt-2020-election-scraper/graphs/contributors">these people</a>.
</p>

<p class="text-right">
<p class="float-left" id="timestamps">Last scrape: <span class="timestamp">{% SCRAPE_TIME %}</span> | Last batch: <span class="timestamp">{% BATCH_TIME %}</span></p>

<p class="float-right">
<button type='button' id='notification_button' class='btn btn-secondary'>Enable Notifications</button>
<button type='button' id='live_update_button' class='btn btn-secondary'>Enable Live Updates</button>
<button type='button' id='shrink_button' class='btn btn-secondary'>Shrink Tables</button>
</p>


{% TABLES %}

<script src="https://unpkg.com/dayjs@1.8.21/dayjs.min.js"
Expand Down Expand Up @@ -229,6 +230,11 @@
let newTable = newContent.getElementById(table.id);
table.parentNode.replaceChild(newTable, table);
});

let newTimestamps = newContent.getElementById("timestamps");
let currTimestamps = document.getElementById("timestamps");
currTimestamps.parentNode.replaceChild(newTimestamps, currTimestamps);

prettyTimestamps();
refreshFeature(shrinkTablesFeature);

Expand Down
2 changes: 1 addition & 1 deletion print-battleground-state-changes
Expand Up @@ -349,7 +349,7 @@ for (state, timestamped_results) in summarized.items():
html_chunks.append("</table><hr>")

with open("battleground-state-changes.html","w", encoding='utf8') as f:
html = html_template.replace('{% TABLES %}', "\n".join(html_chunks)).replace('{% SCRAPE %}', scrape_time.strftime("%c (UTC)"))
html = html_template.replace('{% TABLES %}', "\n".join(html_chunks)).replace('{% SCRAPE_TIME %}', scrape_time.strftime('%Y-%m-%d %H:%M:%S UTC')).replace('{% BATCH_TIME %}', batch_time.strftime('%Y-%m-%d %H:%M:%S UTC'))
f.write(html)

with open('battleground-state-changes.csv', 'w') as csvfile:
Expand Down

0 comments on commit 6e7910b

Please sign in to comment.