Skip to content

Commit

Permalink
format poll dates as d/m/Y in slack messages
Browse files Browse the repository at this point in the history
  • Loading branch information
chris48s committed Aug 29, 2017
1 parent e16390c commit 0bdb81c
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion scraper.py
Expand Up @@ -54,6 +54,9 @@ def get_title():
'Elections coming up this month',
])

def format_date(d):
return datetime.datetime.strptime(d, "%Y-%m-%d").strftime("%d/%m/%Y")

def get_slack_message(elections):
# sort elections by date
elections = sorted(elections, key=lambda k: k['poll_open_date'])
Expand All @@ -62,7 +65,7 @@ def get_slack_message(elections):
slack_messages = [get_emoji() + ' *' + get_title() + '* ' + get_emoji()]
for election in elections:
message = "%s: <%s|%s>. known candidates: %s" % (
election['poll_open_date'],
format_date(election['poll_open_date']),
election['url'],
election['name'],
election['known_candidates'])
Expand Down

0 comments on commit 0bdb81c

Please sign in to comment.