本文整理汇总了Python中arrow.get方法的典型用法代码示例。如果您正苦于以下问题:Python arrow.get方法的具体用法?Python arrow.get怎么用?Python arrow.get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类arrow
的用法示例。
在下文中一共展示了arrow.get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: start_data_processing
# 需要导入模块: import arrow [as 别名]
# 或者: from arrow import get [as 别名]
def start_data_processing(thread_number):
""" TODO: replace with your code.
Most work regarding sending to IF is abstracted away for you.
This function will get the data to send and prepare it for the API.
The general outline should be:
0. Define the project type in config.ini
1. Parse config options
2. Gather data
3. Parse each entry
4. Call the appropriate handoff function
metric_handoff()
log_handoff()
alert_handoff()
incident_handoff()
deployment_handoff()
See zipkin for an example that uses os.fork to send both metric and log data.
"""
示例2: reconfigure
# 需要导入模块: import arrow [as 别名]
# 或者: from arrow import get [as 别名]
def reconfigure(ctx):
"""
Reconfigure the chute without rebuilding.
"""
url = ctx.obj['chute_url'] + "/config"
if not os.path.exists("paradrop.yaml"):
raise Exception("No paradrop.yaml file found in working directory.")
with open("paradrop.yaml", "r") as source:
data = yaml.safe_load(source)
config = data.get('config', {})
res = router_request("PUT", url, json=config)
data = res.json()
ctx.invoke(watch, change_id=data['change_id'])
示例3: connect_snap_interfaces
# 需要导入模块: import arrow [as 别名]
# 或者: from arrow import get [as 别名]
def connect_snap_interfaces(ctx):
"""
Connect all interfaces for installed snaps.
"""
client = ctx.obj['client']
result = client.list_snap_interfaces()
for item in result['result']['plugs']:
connections = item.get('connections', [])
if len(connections) > 0:
continue
if item['plug'] == 'docker':
# The docker slot needs to be treated differently from core slots.
slot = {'snap': 'docker'}
elif item['plug'] == 'zerotier-control':
# TODO: This connection is failing, but I am not sure why.
slot = {'snap': 'zerotier-one', 'slot': 'zerotier-control'}
else:
# Most slots are provided by the core snap and specified this way.
slot = {'slot': item['interface']}
result = client.connect_snap_interface(slots=[slot], plugs=[{'snap':
item['snap'], 'plug': item['plug']}])
if result['type'] == 'error':
print(result['result']['message'])
示例4: edit_chute_variables
# 需要导入模块: import arrow [as 别名]
# 或者: from arrow import get [as 别名]
def edit_chute_variables(ctx, chute):
"""
Interactively edit a chute's environment variables and restart it.
CHUTE must be the name of an installed chute.
Open the text editor specified by the EDITOR environment variable
with the current chute environment variables. If you save and exit,
the new settings will be applied and the chute restarted.
"""
client = ctx.obj['client']
old_data = client.get_chute(chute).get('environment', {})
new_data, changed = util.open_yaml_editor(old_data, "chute " + chute)
if changed:
result = client.set_chute_variables(chute, new_data)
ctx.invoke(watch_change_logs, change_id=result['change_id'])
return new_data
示例5: watch_chute_logs
# 需要导入模块: import arrow [as 别名]
# 或者: from arrow import get [as 别名]
def watch_chute_logs(ctx, chute):
"""
Stream log messages from a running chute.
CHUTE must be the name of a running chute.
"""
url = "ws://{}/sockjs/logs/{}".format(ctx.obj['target'], chute)
def on_message(ws, message):
data = json.loads(message)
time = arrow.get(data['timestamp']).to('local').datetime
msg = data['message'].rstrip()
service = data.get("service", chute)
click.echo("[{}] {}: {}".format(service, time, msg))
client = ctx.obj['client']
client.ws_request(url, on_message=on_message)
示例6: jinja2_filter
# 需要导入模块: import arrow [as 别名]
# 或者: from arrow import get [as 别名]
def jinja2_filter(app):
def format_datetime(value):
dt = arrow.get(value)
return dt.humanize()
app.jinja_env.filters["dt"] = format_datetime
@app.context_processor
def inject_stage_and_region():
return dict(
YEAR=arrow.now().year,
URL=URL,
SENTRY_DSN=SENTRY_FRONT_END_DSN,
VERSION=SHA1,
FIRST_ALIAS_DOMAIN=FIRST_ALIAS_DOMAIN,
)
示例7: get_entity_data
# 需要导入模块: import arrow [as 别名]
# 或者: from arrow import get [as 别名]
def get_entity_data(cls, name, **kwargs):
account_uuid = kwargs.get("account_uuid", "")
if not account_uuid:
LOG.error("Account UUID not supplied for fetching subnet {}".format(name))
sys.exit(-1)
cluster_name = kwargs.get("cluster", "")
try:
if cluster_name:
entity = super().get(
cls.name == name,
cls.cluster == cluster_name,
cls.account_uuid == account_uuid,
)
else:
# The get() method is shorthand for selecting with a limit of 1
# If more than one row is found, the first row returned by the database cursor
entity = super().get(cls.name == name, cls.account_uuid == account_uuid)
return entity.get_detail_dict()
except DoesNotExist:
return None
示例8: get_entity_data_using_uuid
# 需要导入模块: import arrow [as 别名]
# 或者: from arrow import get [as 别名]
def get_entity_data_using_uuid(cls, uuid, **kwargs):
account_uuid = kwargs.get("account_uuid", "")
if not account_uuid:
LOG.error(
"Account UUID not supplied for fetching subnet with uuid {}".format(
uuid
)
)
sys.exit(-1)
try:
entity = super().get(cls.uuid == uuid, cls.account_uuid == account_uuid)
return entity.get_detail_dict()
except DoesNotExist:
return None
示例9: sync
# 需要导入模块: import arrow [as 别名]
# 或者: from arrow import get [as 别名]
def sync(cls):
"""sync the table data from server"""
# clear old data
cls.clear()
client = get_api_client()
payload = {"length": 250, "filter": "state==VERIFIED;type==nutanix_pc"}
account_name_uuid_map = client.account.get_name_uuid_map(payload)
AhvVmProvider = get_provider("AHV_VM")
AhvObj = AhvVmProvider.get_api_obj()
for e_name, e_uuid in account_name_uuid_map.items():
res = AhvObj.images(account_uuid=e_uuid)
for entity in res["entities"]:
name = entity["status"]["name"]
uuid = entity["metadata"]["uuid"]
# TODO add proper validation for karbon images
image_type = entity["status"]["resources"].get("image_type", "")
cls.create_entry(
name=name, uuid=uuid, image_type=image_type, account_uuid=e_uuid
)
示例10: show_data
# 需要导入模块: import arrow [as 别名]
# 或者: from arrow import get [as 别名]
def show_data(cls):
"""display stored data in table"""
if not len(cls.select()):
click.echo(highlight_text("No entry found !!!"))
return
table = PrettyTable()
table.field_names = ["NAME", "UUID", "LAST UPDATED"]
for entity in cls.select():
entity_data = entity.get_detail_dict()
last_update_time = arrow.get(
entity_data["last_update_time"].astimezone(datetime.timezone.utc)
).humanize()
table.add_row(
[
highlight_text(entity_data["name"]),
highlight_text(entity_data["uuid"]),
highlight_text(last_update_time),
]
)
click.echo(table)
示例11: get_blueprint
# 需要导入模块: import arrow [as 别名]
# 或者: from arrow import get [as 别名]
def get_blueprint(client, name, all=False):
# find bp
params = {"filter": "name=={}".format(name)}
if not all:
params["filter"] += ";state!=DELETED"
res, err = client.blueprint.list(params=params)
if err:
raise Exception("[{}] - {}".format(err["code"], err["error"]))
response = res.json()
entities = response.get("entities", None)
blueprint = None
if entities:
if len(entities) != 1:
raise Exception("More than one blueprint found - {}".format(entities))
LOG.info("{} found ".format(name))
blueprint = entities[0]
else:
raise Exception("No blueprint found with name {} found".format(name))
return blueprint
示例12: get_val_launch_runtime_vars
# 需要导入模块: import arrow [as 别名]
# 或者: from arrow import get [as 别名]
def get_val_launch_runtime_vars(launch_runtime_vars, field, path, context):
"""Returns value of variable from launch_runtime_vars(Non-interactive)"""
filtered_launch_runtime_vars = list(
filter(
lambda e: is_launch_runtime_vars_context_matching(e["context"], context)
and e["name"] == path,
launch_runtime_vars,
)
)
if len(filtered_launch_runtime_vars) > 1:
LOG.error(
"Unable to populate runtime editables: Multiple matches for name {} and context {}".format(
path, context
)
)
sys.exit(-1)
if len(filtered_launch_runtime_vars) == 1:
return filtered_launch_runtime_vars[0].get("value", {}).get(field, None)
return None
示例13: get_val_launch_runtime_substrates
# 需要导入模块: import arrow [as 别名]
# 或者: from arrow import get [as 别名]
def get_val_launch_runtime_substrates(launch_runtime_substrates, path, context):
"""Returns value of substrate from launch_runtime_substrates(Non-interactive)"""
filtered_launch_runtime_substrates = list(
filter(lambda e: e["name"] == path, launch_runtime_substrates,)
)
if len(filtered_launch_runtime_substrates) > 1:
LOG.error(
"Unable to populate runtime editables: Multiple matches for name {} and context {}".format(
path, context
)
)
sys.exit(-1)
if len(filtered_launch_runtime_substrates) == 1:
return filtered_launch_runtime_substrates[0].get("value", {})
return None
示例14: describe_aws_account
# 需要导入模块: import arrow [as 别名]
# 或者: from arrow import get [as 别名]
def describe_aws_account(spec):
click.echo("Access Key ID: {}".format(spec["access_key_id"]))
regions = spec["regions"]
click.echo("\nRegions:\n-------------- ")
for index, region in enumerate(regions):
click.echo("\t{}. {}".format(str(index + 1), highlight_text(region["name"])))
click.echo("\nPublic Images:\n-------------- ")
image_present = False
for region in regions:
if region.get("images"):
click.echo("\nRegion: {}".format(region["name"]))
click.echo("Images: ")
for index, image in enumerate(region["images"]):
image_present = True
click.echo(
"\t{}. {}".format(str(index + 1), highlight_text(image["name"]))
)
if not image_present:
click.echo("\t{}".format(highlight_text("No images provided")))
示例15: get_last_full_moon
# 需要导入模块: import arrow [as 别名]
# 或者: from arrow import get [as 别名]
def get_last_full_moon(d):
"""
Returns the last full moon for d
Raises ValueError if the d value is not between 2000 - 2099
"""
now = d.timestamp
idx = bisect.bisect_right(fullmoons, now)
if idx in [0, len(fullmoons)]:
raise ValueError(
u'watson has only full moon dates from year 2000 to 2099, not {}'
.format(d.year))
last = fullmoons[idx - 1]
return arrow.get(last)