Skip to content
This repository has been archived by the owner on Oct 23, 2022. It is now read-only.

Commit

Permalink
Merge pull request #26 from DevonWC/DevonWC-get_time()
Browse files Browse the repository at this point in the history
Update get_time() function.
  • Loading branch information
David Jetelina authored and David Jetelina committed Jun 7, 2016
2 parents 953a0e5 + b421f07 commit d89e75b
Showing 1 changed file with 12 additions and 29 deletions.
41 changes: 12 additions & 29 deletions cogs/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,36 +152,19 @@ async def _perth(self):

def get_time() -> dict:
"""
Function to get local time in cities
:return: Dictionary with {"city":"%H:%M"}
"""
fmt = '%H:%M'

Function to get local time in cities
:return: Dictionary with {"city":"%H:%M"}
"""
places = {'sf': 'US/Pacific', 'london': 'Europe/London', 'sydney': 'Australia/Sydney', 'perth': 'Australia/Perth', 'ny': 'US/Eastern'}
output = {}
now_utc = datetime.now(timezone('UTC'))

now_pacific = now_utc.astimezone(timezone('US/Pacific'))
sf = now_pacific.strftime(fmt)

now_london = now_utc.astimezone(timezone('Europe/London'))
london = now_london.strftime(fmt)

now_sydney = now_utc.astimezone(timezone('Australia/Sydney'))
sydney = now_sydney.strftime(fmt)

now_perth = now_utc.astimezone(timezone('Australia/Perth'))
perth = now_perth.strftime(fmt)

now_ny = now_utc.astimezone(timezone('US/Eastern'))
ny = now_ny.strftime(fmt)

return {
"sydney": sydney,
"london": london,
"ny": ny,
"sf": sf,
"perth": perth
}

for i in places:
time = now_utc.astimezone(timezone(places[i]))
fmttime = time.strftime('%H:%M')
output[i] = fmttime

return output


def setup(bot):
Expand Down

0 comments on commit d89e75b

Please sign in to comment.