def get_local_time(dt: datetime, timezone_name: str) -> datetime:
"""Convert given time to timezone. Naive datetimes are assumed to be in UTC"""
tz = pytz.timezone(timezone_name)
return to_zoned_utc(dt).astimezone(tz)
Associated Context |
---|
#! -*- coding: utf-8 -*- | |
from resolution import to_text | |
def test_1(): | |
assert to_text(1) == 'jeden' | |
def test_12(): | |
assert to_text(12) == 'dwanaście' |
#!/bin/bash | |
UNITTEST_LOG=error_unittest_verify_pr.log | |
INTEGRATIONTEST_LOG=error_integrationtest_verify_pr.log | |
CURRENT_GIT_BRANCH=$(git name-rev --name-only HEAD) | |
# check argument | |
if [ -z "$1" ]; then | |
echo "$(tput setaf 1)Please supply name of the branch to verify" | |
exit 1 | |
fi |
from functools import wraps | |
def printer(f): | |
@wraps(f) | |
def wrapper(*args, **kwargs): | |
print(args) | |
return f(*args, **kwargs) | |
return wrapper |
def setUp(self): | |
post = partial( | |
self.client.post, | |
path='/api/task/', | |
content_type='application/json') | |
self.post = lambda data: post(data=json.dumps(data)) |
alias halt_all_vagrants="vagrant global-status | awk '/running/{print $1}' | xargs -r -d '\n' -n 1 -- vagrant halt" |
// Use Gists to store code you would like to remember later on | |
console.log(window); // log the "window" object to the console |
def kwargs_default(params): | |
"""Decorator for setting default keyword parameters | |
@kwargs_default((('number_of_chickens', 3),)) | |
will add param 'number_of_chickens' with value of 3 into kwargs. | |
:param params: tuple of tuples consiting of name of parameter and value | |
:type params: tuple of tuples with str and any ((str, any), (str, any), ...) | |
""" |
def retry(retries=3, callback_on_failure=None): | |
"""Retry requests method and run callback on failure | |
Decorator will retry the decorated function for specified number of times, | |
default is 3. If there is a callback passed, it will be called before | |
calling the decorated function again. Callback allows to perform cleanups, | |
clear the credentials, etc. | |
Decorator will only work with functions that return requests.Request | |
object, if decorated method returns other object result is returned with | |
out retrying. |
def get_version(): | |
local_vars = {} | |
try: | |
execfile('src/imagination/objectid_manager/__init__.py', | |
{}, | |
local_vars) | |
except NameError: | |
# python3.x does not provide execfile | |
with open('src/imagination/objectid_manager/__init__.py') as f: | |
exec(f.read(), {}, local_vars) |