repository_name stringlengths 7 55 | func_path_in_repository stringlengths 4 223 | func_name stringlengths 1 134 | whole_func_string stringlengths 75 104k | language stringclasses 1
value | func_code_string stringlengths 75 104k | func_code_tokens listlengths 19 28.4k | func_documentation_string stringlengths 1 46.9k | func_documentation_tokens listlengths 1 1.97k | split_name stringclasses 1
value | func_code_url stringlengths 87 315 |
|---|---|---|---|---|---|---|---|---|---|---|
scivision/pymap3d | pymap3d/lox.py | isometric | def isometric(lat: float, ell: Ellipsoid = None, deg: bool = True):
"""
computes isometric latitude of a point on an ellipsoid
Parameters
----------
lat : float or numpy.ndarray of float
geodetic latitude
ell : Ellipsoid, optional
reference ellipsoid (default WGS84)
... | python | def isometric(lat: float, ell: Ellipsoid = None, deg: bool = True):
"""
computes isometric latitude of a point on an ellipsoid
Parameters
----------
lat : float or numpy.ndarray of float
geodetic latitude
ell : Ellipsoid, optional
reference ellipsoid (default WGS84)
... | [
"def",
"isometric",
"(",
"lat",
":",
"float",
",",
"ell",
":",
"Ellipsoid",
"=",
"None",
",",
"deg",
":",
"bool",
"=",
"True",
")",
":",
"if",
"ell",
"is",
"None",
":",
"ell",
"=",
"Ellipsoid",
"(",
")",
"f",
"=",
"ell",
".",
"f",
"# flattening o... | computes isometric latitude of a point on an ellipsoid
Parameters
----------
lat : float or numpy.ndarray of float
geodetic latitude
ell : Ellipsoid, optional
reference ellipsoid (default WGS84)
deg : bool, optional
degrees input/output (False: radians in/out)
... | [
"computes",
"isometric",
"latitude",
"of",
"a",
"point",
"on",
"an",
"ellipsoid"
] | train | https://github.com/scivision/pymap3d/blob/c9cf676594611cdb52ff7e0eca6388c80ed4f63f/pymap3d/lox.py#L6-L58 |
scivision/pymap3d | pymap3d/lox.py | meridian_dist | def meridian_dist(lat: float, ell: Ellipsoid = None, deg: bool = True):
"""
computes the meridian distance on an ellipsoid *from the equator* to a latitude.
Parameters
----------
lat : float or numpy.ndarray of float
geodetic latitude
ell : Ellipsoid, optional
reference ellips... | python | def meridian_dist(lat: float, ell: Ellipsoid = None, deg: bool = True):
"""
computes the meridian distance on an ellipsoid *from the equator* to a latitude.
Parameters
----------
lat : float or numpy.ndarray of float
geodetic latitude
ell : Ellipsoid, optional
reference ellips... | [
"def",
"meridian_dist",
"(",
"lat",
":",
"float",
",",
"ell",
":",
"Ellipsoid",
"=",
"None",
",",
"deg",
":",
"bool",
"=",
"True",
")",
":",
"if",
"deg",
"is",
"True",
":",
"lat",
"=",
"np",
".",
"radians",
"(",
"lat",
")",
"# set ellipsoid paramet... | computes the meridian distance on an ellipsoid *from the equator* to a latitude.
Parameters
----------
lat : float or numpy.ndarray of float
geodetic latitude
ell : Ellipsoid, optional
reference ellipsoid (default WGS84)
deg : bool, optional
degrees input/output (False: ... | [
"computes",
"the",
"meridian",
"distance",
"on",
"an",
"ellipsoid",
"*",
"from",
"the",
"equator",
"*",
"to",
"a",
"latitude",
"."
] | train | https://github.com/scivision/pymap3d/blob/c9cf676594611cdb52ff7e0eca6388c80ed4f63f/pymap3d/lox.py#L61-L127 |
scivision/pymap3d | pymap3d/lox.py | loxodrome_inverse | def loxodrome_inverse(lat1: float, lon1: float, lat2: float, lon2: float,
ell: Ellipsoid = None, deg: bool = True):
"""
computes the arc length and azimuth of the loxodrome
between two points on the surface of the reference ellipsoid
Parameters
----------
lat1 : float or ... | python | def loxodrome_inverse(lat1: float, lon1: float, lat2: float, lon2: float,
ell: Ellipsoid = None, deg: bool = True):
"""
computes the arc length and azimuth of the loxodrome
between two points on the surface of the reference ellipsoid
Parameters
----------
lat1 : float or ... | [
"def",
"loxodrome_inverse",
"(",
"lat1",
":",
"float",
",",
"lon1",
":",
"float",
",",
"lat2",
":",
"float",
",",
"lon2",
":",
"float",
",",
"ell",
":",
"Ellipsoid",
"=",
"None",
",",
"deg",
":",
"bool",
"=",
"True",
")",
":",
"# set ellipsoid parame... | computes the arc length and azimuth of the loxodrome
between two points on the surface of the reference ellipsoid
Parameters
----------
lat1 : float or numpy.ndarray of float
geodetic latitude of first point
lon1 : float or numpy.ndarray of float
geodetic longitude of first point
... | [
"computes",
"the",
"arc",
"length",
"and",
"azimuth",
"of",
"the",
"loxodrome",
"between",
"two",
"points",
"on",
"the",
"surface",
"of",
"the",
"reference",
"ellipsoid"
] | train | https://github.com/scivision/pymap3d/blob/c9cf676594611cdb52ff7e0eca6388c80ed4f63f/pymap3d/lox.py#L130-L202 |
scivision/pymap3d | pymap3d/eci.py | eci2ecef | def eci2ecef(eci: np.ndarray,
time: datetime,
useastropy: bool = True) -> np.ndarray:
"""
Observer => Point ECI => ECEF
Parameters
----------
eci : tuple of float
Nx3 target ECI location (x,y,z) [meters]
time : datetime.datetime
time of obsevation (U... | python | def eci2ecef(eci: np.ndarray,
time: datetime,
useastropy: bool = True) -> np.ndarray:
"""
Observer => Point ECI => ECEF
Parameters
----------
eci : tuple of float
Nx3 target ECI location (x,y,z) [meters]
time : datetime.datetime
time of obsevation (U... | [
"def",
"eci2ecef",
"(",
"eci",
":",
"np",
".",
"ndarray",
",",
"time",
":",
"datetime",
",",
"useastropy",
":",
"bool",
"=",
"True",
")",
"->",
"np",
".",
"ndarray",
":",
"useastropy",
"=",
"useastropy",
"and",
"Time",
"if",
"useastropy",
":",
"gst",
... | Observer => Point ECI => ECEF
Parameters
----------
eci : tuple of float
Nx3 target ECI location (x,y,z) [meters]
time : datetime.datetime
time of obsevation (UTC)
useastropy : bool, optional
use AstroPy for conversion
Results
-------
x : float
target... | [
"Observer",
"=",
">",
"Point",
"ECI",
"=",
">",
"ECEF"
] | train | https://github.com/scivision/pymap3d/blob/c9cf676594611cdb52ff7e0eca6388c80ed4f63f/pymap3d/eci.py#L12-L58 |
scivision/pymap3d | pymap3d/eci.py | _rottrip | def _rottrip(ang: np.ndarray) -> np.ndarray:
"""
transformation matrix
Parameters
----------
ang : N x 3 numpy.ndarray
angle to transform (radians)
"""
ang = ang.squeeze()
if ang.size > 1:
raise ValueError('only one angle allowed at a time')
return np.array([[np.co... | python | def _rottrip(ang: np.ndarray) -> np.ndarray:
"""
transformation matrix
Parameters
----------
ang : N x 3 numpy.ndarray
angle to transform (radians)
"""
ang = ang.squeeze()
if ang.size > 1:
raise ValueError('only one angle allowed at a time')
return np.array([[np.co... | [
"def",
"_rottrip",
"(",
"ang",
":",
"np",
".",
"ndarray",
")",
"->",
"np",
".",
"ndarray",
":",
"ang",
"=",
"ang",
".",
"squeeze",
"(",
")",
"if",
"ang",
".",
"size",
">",
"1",
":",
"raise",
"ValueError",
"(",
"'only one angle allowed at a time'",
")",... | transformation matrix
Parameters
----------
ang : N x 3 numpy.ndarray
angle to transform (radians) | [
"transformation",
"matrix"
] | train | https://github.com/scivision/pymap3d/blob/c9cf676594611cdb52ff7e0eca6388c80ed4f63f/pymap3d/eci.py#L110-L126 |
scivision/pymap3d | pymap3d/timeconv.py | str2dt | def str2dt(time: datetime) -> np.ndarray:
"""
Converts times in string or list of strings to datetime(s)
Parameters
----------
time : str or datetime.datetime or numpy.datetime64
Results
-------
t : datetime.datetime
"""
if isinstance(time, datetime):
return time
... | python | def str2dt(time: datetime) -> np.ndarray:
"""
Converts times in string or list of strings to datetime(s)
Parameters
----------
time : str or datetime.datetime or numpy.datetime64
Results
-------
t : datetime.datetime
"""
if isinstance(time, datetime):
return time
... | [
"def",
"str2dt",
"(",
"time",
":",
"datetime",
")",
"->",
"np",
".",
"ndarray",
":",
"if",
"isinstance",
"(",
"time",
",",
"datetime",
")",
":",
"return",
"time",
"elif",
"isinstance",
"(",
"time",
",",
"str",
")",
":",
"return",
"parse",
"(",
"time"... | Converts times in string or list of strings to datetime(s)
Parameters
----------
time : str or datetime.datetime or numpy.datetime64
Results
-------
t : datetime.datetime | [
"Converts",
"times",
"in",
"string",
"or",
"list",
"of",
"strings",
"to",
"datetime",
"(",
"s",
")"
] | train | https://github.com/scivision/pymap3d/blob/c9cf676594611cdb52ff7e0eca6388c80ed4f63f/pymap3d/timeconv.py#L10-L44 |
Netflix-Skunkworks/historical | historical/vpc/differ.py | handler | def handler(event, context): # pylint: disable=W0613
"""
Historical security group event differ.
Listens to the Historical current table and determines if there are differences that need to be persisted in the
historical record.
"""
# De-serialize the records:
records = deserialize_records... | python | def handler(event, context): # pylint: disable=W0613
"""
Historical security group event differ.
Listens to the Historical current table and determines if there are differences that need to be persisted in the
historical record.
"""
# De-serialize the records:
records = deserialize_records... | [
"def",
"handler",
"(",
"event",
",",
"context",
")",
":",
"# pylint: disable=W0613",
"# De-serialize the records:",
"records",
"=",
"deserialize_records",
"(",
"event",
"[",
"'Records'",
"]",
")",
"for",
"record",
"in",
"records",
":",
"process_dynamodb_differ_record"... | Historical security group event differ.
Listens to the Historical current table and determines if there are differences that need to be persisted in the
historical record. | [
"Historical",
"security",
"group",
"event",
"differ",
"."
] | train | https://github.com/Netflix-Skunkworks/historical/blob/c3ebaa8388a3fe67e23a6c9c6b04c3e618497c4a/historical/vpc/differ.py#L23-L34 |
Netflix-Skunkworks/historical | historical/security_group/models.py | SecurityGroupPollingEventModel.serialize | def serialize(self, account, group, region):
"""Serializes the JSON for the Polling Event Model.
:param account:
:param group:
:param region:
:return:
"""
return self.dumps({
'account': account,
'detail': {
'request_paramet... | python | def serialize(self, account, group, region):
"""Serializes the JSON for the Polling Event Model.
:param account:
:param group:
:param region:
:return:
"""
return self.dumps({
'account': account,
'detail': {
'request_paramet... | [
"def",
"serialize",
"(",
"self",
",",
"account",
",",
"group",
",",
"region",
")",
":",
"return",
"self",
".",
"dumps",
"(",
"{",
"'account'",
":",
"account",
",",
"'detail'",
":",
"{",
"'request_parameters'",
":",
"{",
"'groupId'",
":",
"group",
"[",
... | Serializes the JSON for the Polling Event Model.
:param account:
:param group:
:param region:
:return: | [
"Serializes",
"the",
"JSON",
"for",
"the",
"Polling",
"Event",
"Model",
"."
] | train | https://github.com/Netflix-Skunkworks/historical/blob/c3ebaa8388a3fe67e23a6c9c6b04c3e618497c4a/historical/security_group/models.py#L82-L99 |
Netflix-Skunkworks/historical | historical/vpc/collector.py | describe_vpc | def describe_vpc(record):
"""Attempts to describe vpc ids."""
account_id = record['account']
vpc_name = cloudwatch.filter_request_parameters('vpcName', record)
vpc_id = cloudwatch.filter_request_parameters('vpcId', record)
try:
if vpc_id and vpc_name: # pylint: disable=R1705
re... | python | def describe_vpc(record):
"""Attempts to describe vpc ids."""
account_id = record['account']
vpc_name = cloudwatch.filter_request_parameters('vpcName', record)
vpc_id = cloudwatch.filter_request_parameters('vpcId', record)
try:
if vpc_id and vpc_name: # pylint: disable=R1705
re... | [
"def",
"describe_vpc",
"(",
"record",
")",
":",
"account_id",
"=",
"record",
"[",
"'account'",
"]",
"vpc_name",
"=",
"cloudwatch",
".",
"filter_request_parameters",
"(",
"'vpcName'",
",",
"record",
")",
"vpc_id",
"=",
"cloudwatch",
".",
"filter_request_parameters"... | Attempts to describe vpc ids. | [
"Attempts",
"to",
"describe",
"vpc",
"ids",
"."
] | train | https://github.com/Netflix-Skunkworks/historical/blob/c3ebaa8388a3fe67e23a6c9c6b04c3e618497c4a/historical/vpc/collector.py#L44-L75 |
Netflix-Skunkworks/historical | historical/vpc/collector.py | create_delete_model | def create_delete_model(record):
"""Create a vpc model from a record."""
data = cloudwatch.get_historical_base_info(record)
vpc_id = cloudwatch.filter_request_parameters('vpcId', record)
arn = get_arn(vpc_id, cloudwatch.get_region(record), record['account'])
LOG.debug(F'[-] Deleting Dynamodb Reco... | python | def create_delete_model(record):
"""Create a vpc model from a record."""
data = cloudwatch.get_historical_base_info(record)
vpc_id = cloudwatch.filter_request_parameters('vpcId', record)
arn = get_arn(vpc_id, cloudwatch.get_region(record), record['account'])
LOG.debug(F'[-] Deleting Dynamodb Reco... | [
"def",
"create_delete_model",
"(",
"record",
")",
":",
"data",
"=",
"cloudwatch",
".",
"get_historical_base_info",
"(",
"record",
")",
"vpc_id",
"=",
"cloudwatch",
".",
"filter_request_parameters",
"(",
"'vpcId'",
",",
"record",
")",
"arn",
"=",
"get_arn",
"(",
... | Create a vpc model from a record. | [
"Create",
"a",
"vpc",
"model",
"from",
"a",
"record",
"."
] | train | https://github.com/Netflix-Skunkworks/historical/blob/c3ebaa8388a3fe67e23a6c9c6b04c3e618497c4a/historical/vpc/collector.py#L78-L102 |
Netflix-Skunkworks/historical | historical/vpc/collector.py | capture_delete_records | def capture_delete_records(records):
"""Writes all of our delete events to DynamoDB."""
for record in records:
model = create_delete_model(record)
if model:
try:
model.delete(condition=(CurrentVPCModel.eventTime <= record['detail']['eventTime']))
except De... | python | def capture_delete_records(records):
"""Writes all of our delete events to DynamoDB."""
for record in records:
model = create_delete_model(record)
if model:
try:
model.delete(condition=(CurrentVPCModel.eventTime <= record['detail']['eventTime']))
except De... | [
"def",
"capture_delete_records",
"(",
"records",
")",
":",
"for",
"record",
"in",
"records",
":",
"model",
"=",
"create_delete_model",
"(",
"record",
")",
"if",
"model",
":",
"try",
":",
"model",
".",
"delete",
"(",
"condition",
"=",
"(",
"CurrentVPCModel",
... | Writes all of our delete events to DynamoDB. | [
"Writes",
"all",
"of",
"our",
"delete",
"events",
"to",
"DynamoDB",
"."
] | train | https://github.com/Netflix-Skunkworks/historical/blob/c3ebaa8388a3fe67e23a6c9c6b04c3e618497c4a/historical/vpc/collector.py#L105-L115 |
Netflix-Skunkworks/historical | historical/vpc/collector.py | capture_update_records | def capture_update_records(records):
"""Writes all updated configuration info to DynamoDB"""
for record in records:
data = cloudwatch.get_historical_base_info(record)
vpc = describe_vpc(record)
if len(vpc) > 1:
raise Exception(f'[X] Multiple vpcs found. Record: {record}')
... | python | def capture_update_records(records):
"""Writes all updated configuration info to DynamoDB"""
for record in records:
data = cloudwatch.get_historical_base_info(record)
vpc = describe_vpc(record)
if len(vpc) > 1:
raise Exception(f'[X] Multiple vpcs found. Record: {record}')
... | [
"def",
"capture_update_records",
"(",
"records",
")",
":",
"for",
"record",
"in",
"records",
":",
"data",
"=",
"cloudwatch",
".",
"get_historical_base_info",
"(",
"record",
")",
"vpc",
"=",
"describe_vpc",
"(",
"record",
")",
"if",
"len",
"(",
"vpc",
")",
... | Writes all updated configuration info to DynamoDB | [
"Writes",
"all",
"updated",
"configuration",
"info",
"to",
"DynamoDB"
] | train | https://github.com/Netflix-Skunkworks/historical/blob/c3ebaa8388a3fe67e23a6c9c6b04c3e618497c4a/historical/vpc/collector.py#L127-L161 |
Netflix-Skunkworks/historical | historical/vpc/collector.py | handler | def handler(event, context): # pylint: disable=W0613
"""
Historical vpc event collector.
This collector is responsible for processing Cloudwatch events and polling events.
"""
records = deserialize_records(event['Records'])
# Split records into two groups, update and delete.
# We don't wan... | python | def handler(event, context): # pylint: disable=W0613
"""
Historical vpc event collector.
This collector is responsible for processing Cloudwatch events and polling events.
"""
records = deserialize_records(event['Records'])
# Split records into two groups, update and delete.
# We don't wan... | [
"def",
"handler",
"(",
"event",
",",
"context",
")",
":",
"# pylint: disable=W0613",
"records",
"=",
"deserialize_records",
"(",
"event",
"[",
"'Records'",
"]",
")",
"# Split records into two groups, update and delete.",
"# We don't want to query for deleted records.",
"updat... | Historical vpc event collector.
This collector is responsible for processing Cloudwatch events and polling events. | [
"Historical",
"vpc",
"event",
"collector",
".",
"This",
"collector",
"is",
"responsible",
"for",
"processing",
"Cloudwatch",
"events",
"and",
"polling",
"events",
"."
] | train | https://github.com/Netflix-Skunkworks/historical/blob/c3ebaa8388a3fe67e23a6c9c6b04c3e618497c4a/historical/vpc/collector.py#L165-L183 |
Netflix-Skunkworks/historical | historical/common/dynamodb.py | default_diff | def default_diff(latest_config, current_config):
"""Determine if two revisions have actually changed."""
# Pop off the fields we don't care about:
pop_no_diff_fields(latest_config, current_config)
diff = DeepDiff(
latest_config,
current_config,
ignore_order=True
)
return... | python | def default_diff(latest_config, current_config):
"""Determine if two revisions have actually changed."""
# Pop off the fields we don't care about:
pop_no_diff_fields(latest_config, current_config)
diff = DeepDiff(
latest_config,
current_config,
ignore_order=True
)
return... | [
"def",
"default_diff",
"(",
"latest_config",
",",
"current_config",
")",
":",
"# Pop off the fields we don't care about:",
"pop_no_diff_fields",
"(",
"latest_config",
",",
"current_config",
")",
"diff",
"=",
"DeepDiff",
"(",
"latest_config",
",",
"current_config",
",",
... | Determine if two revisions have actually changed. | [
"Determine",
"if",
"two",
"revisions",
"have",
"actually",
"changed",
"."
] | train | https://github.com/Netflix-Skunkworks/historical/blob/c3ebaa8388a3fe67e23a6c9c6b04c3e618497c4a/historical/common/dynamodb.py#L33-L43 |
Netflix-Skunkworks/historical | historical/common/dynamodb.py | pop_no_diff_fields | def pop_no_diff_fields(latest_config, current_config):
"""Pops off fields that should not be included in the diff."""
for field in ['userIdentity', 'principalId', 'userAgent', 'sourceIpAddress', 'requestParameters', 'eventName']:
latest_config.pop(field, None)
current_config.pop(field, None) | python | def pop_no_diff_fields(latest_config, current_config):
"""Pops off fields that should not be included in the diff."""
for field in ['userIdentity', 'principalId', 'userAgent', 'sourceIpAddress', 'requestParameters', 'eventName']:
latest_config.pop(field, None)
current_config.pop(field, None) | [
"def",
"pop_no_diff_fields",
"(",
"latest_config",
",",
"current_config",
")",
":",
"for",
"field",
"in",
"[",
"'userIdentity'",
",",
"'principalId'",
",",
"'userAgent'",
",",
"'sourceIpAddress'",
",",
"'requestParameters'",
",",
"'eventName'",
"]",
":",
"latest_con... | Pops off fields that should not be included in the diff. | [
"Pops",
"off",
"fields",
"that",
"should",
"not",
"be",
"included",
"in",
"the",
"diff",
"."
] | train | https://github.com/Netflix-Skunkworks/historical/blob/c3ebaa8388a3fe67e23a6c9c6b04c3e618497c4a/historical/common/dynamodb.py#L46-L50 |
Netflix-Skunkworks/historical | historical/common/dynamodb.py | remove_current_specific_fields | def remove_current_specific_fields(obj):
"""Remove all fields that belong to the Current table -- that don't belong in the Durable table"""
obj = remove_global_dynamo_specific_fields(obj)
obj.pop("ttl", None)
obj.pop("eventSource", None)
return obj | python | def remove_current_specific_fields(obj):
"""Remove all fields that belong to the Current table -- that don't belong in the Durable table"""
obj = remove_global_dynamo_specific_fields(obj)
obj.pop("ttl", None)
obj.pop("eventSource", None)
return obj | [
"def",
"remove_current_specific_fields",
"(",
"obj",
")",
":",
"obj",
"=",
"remove_global_dynamo_specific_fields",
"(",
"obj",
")",
"obj",
".",
"pop",
"(",
"\"ttl\"",
",",
"None",
")",
"obj",
".",
"pop",
"(",
"\"eventSource\"",
",",
"None",
")",
"return",
"o... | Remove all fields that belong to the Current table -- that don't belong in the Durable table | [
"Remove",
"all",
"fields",
"that",
"belong",
"to",
"the",
"Current",
"table",
"--",
"that",
"don",
"t",
"belong",
"in",
"the",
"Durable",
"table"
] | train | https://github.com/Netflix-Skunkworks/historical/blob/c3ebaa8388a3fe67e23a6c9c6b04c3e618497c4a/historical/common/dynamodb.py#L63-L70 |
Netflix-Skunkworks/historical | historical/common/dynamodb.py | modify_record | def modify_record(durable_model, current_revision, arn, event_time, diff_func):
"""Handles a DynamoDB MODIFY event type."""
# We want the newest items first.
# See: http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Query.html
items = list(durable_model.query(
arn,
(durable_... | python | def modify_record(durable_model, current_revision, arn, event_time, diff_func):
"""Handles a DynamoDB MODIFY event type."""
# We want the newest items first.
# See: http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Query.html
items = list(durable_model.query(
arn,
(durable_... | [
"def",
"modify_record",
"(",
"durable_model",
",",
"current_revision",
",",
"arn",
",",
"event_time",
",",
"diff_func",
")",
":",
"# We want the newest items first.",
"# See: http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Query.html",
"items",
"=",
"list",
"(",... | Handles a DynamoDB MODIFY event type. | [
"Handles",
"a",
"DynamoDB",
"MODIFY",
"event",
"type",
"."
] | train | https://github.com/Netflix-Skunkworks/historical/blob/c3ebaa8388a3fe67e23a6c9c6b04c3e618497c4a/historical/common/dynamodb.py#L82-L108 |
Netflix-Skunkworks/historical | historical/common/dynamodb.py | delete_differ_record | def delete_differ_record(old_image, durable_model):
"""Handles a DynamoDB DELETE event type -- For the Differ."""
data = {}
for item in old_image:
data[item] = DESER.deserialize(old_image[item])
data['configuration'] = {}
# we give our own timestamps for TTL deletions
del data['eventTim... | python | def delete_differ_record(old_image, durable_model):
"""Handles a DynamoDB DELETE event type -- For the Differ."""
data = {}
for item in old_image:
data[item] = DESER.deserialize(old_image[item])
data['configuration'] = {}
# we give our own timestamps for TTL deletions
del data['eventTim... | [
"def",
"delete_differ_record",
"(",
"old_image",
",",
"durable_model",
")",
":",
"data",
"=",
"{",
"}",
"for",
"item",
"in",
"old_image",
":",
"data",
"[",
"item",
"]",
"=",
"DESER",
".",
"deserialize",
"(",
"old_image",
"[",
"item",
"]",
")",
"data",
... | Handles a DynamoDB DELETE event type -- For the Differ. | [
"Handles",
"a",
"DynamoDB",
"DELETE",
"event",
"type",
"--",
"For",
"the",
"Differ",
"."
] | train | https://github.com/Netflix-Skunkworks/historical/blob/c3ebaa8388a3fe67e23a6c9c6b04c3e618497c4a/historical/common/dynamodb.py#L111-L121 |
Netflix-Skunkworks/historical | historical/common/dynamodb.py | get_full_current_object | def get_full_current_object(arn, current_model):
"""
Utility method to fetch items from the Current table if they are too big for SNS/SQS.
:param record:
:param current_model:
:return:
"""
LOG.debug(f'[-->] Item with ARN: {arn} was too big for SNS -- fetching it from the Current table...')
... | python | def get_full_current_object(arn, current_model):
"""
Utility method to fetch items from the Current table if they are too big for SNS/SQS.
:param record:
:param current_model:
:return:
"""
LOG.debug(f'[-->] Item with ARN: {arn} was too big for SNS -- fetching it from the Current table...')
... | [
"def",
"get_full_current_object",
"(",
"arn",
",",
"current_model",
")",
":",
"LOG",
".",
"debug",
"(",
"f'[-->] Item with ARN: {arn} was too big for SNS -- fetching it from the Current table...'",
")",
"item",
"=",
"list",
"(",
"current_model",
".",
"query",
"(",
"arn",
... | Utility method to fetch items from the Current table if they are too big for SNS/SQS.
:param record:
:param current_model:
:return: | [
"Utility",
"method",
"to",
"fetch",
"items",
"from",
"the",
"Current",
"table",
"if",
"they",
"are",
"too",
"big",
"for",
"SNS",
"/",
"SQS",
"."
] | train | https://github.com/Netflix-Skunkworks/historical/blob/c3ebaa8388a3fe67e23a6c9c6b04c3e618497c4a/historical/common/dynamodb.py#L124-L143 |
Netflix-Skunkworks/historical | historical/common/dynamodb.py | get_full_durable_object | def get_full_durable_object(arn, event_time, durable_model):
"""
Utility method to fetch items from the Durable table if they are too big for SNS/SQS.
:param record:
:param durable_model:
:return:
"""
LOG.debug(f'[-->] Item with ARN: {arn} was too big for SNS -- fetching it from the Durable... | python | def get_full_durable_object(arn, event_time, durable_model):
"""
Utility method to fetch items from the Durable table if they are too big for SNS/SQS.
:param record:
:param durable_model:
:return:
"""
LOG.debug(f'[-->] Item with ARN: {arn} was too big for SNS -- fetching it from the Durable... | [
"def",
"get_full_durable_object",
"(",
"arn",
",",
"event_time",
",",
"durable_model",
")",
":",
"LOG",
".",
"debug",
"(",
"f'[-->] Item with ARN: {arn} was too big for SNS -- fetching it from the Durable table...'",
")",
"item",
"=",
"list",
"(",
"durable_model",
".",
"q... | Utility method to fetch items from the Durable table if they are too big for SNS/SQS.
:param record:
:param durable_model:
:return: | [
"Utility",
"method",
"to",
"fetch",
"items",
"from",
"the",
"Durable",
"table",
"if",
"they",
"are",
"too",
"big",
"for",
"SNS",
"/",
"SQS",
"."
] | train | https://github.com/Netflix-Skunkworks/historical/blob/c3ebaa8388a3fe67e23a6c9c6b04c3e618497c4a/historical/common/dynamodb.py#L146-L165 |
Netflix-Skunkworks/historical | historical/common/dynamodb.py | deserialize_current_record_to_durable_model | def deserialize_current_record_to_durable_model(record, current_model, durable_model):
"""
Utility function that will take a dynamo event record and turn it into the proper pynamo object.
This will properly deserialize the ugly Dynamo datatypes away.
:param record:
:param current_model:
:param ... | python | def deserialize_current_record_to_durable_model(record, current_model, durable_model):
"""
Utility function that will take a dynamo event record and turn it into the proper pynamo object.
This will properly deserialize the ugly Dynamo datatypes away.
:param record:
:param current_model:
:param ... | [
"def",
"deserialize_current_record_to_durable_model",
"(",
"record",
",",
"current_model",
",",
"durable_model",
")",
":",
"# Was the item in question too big for SNS? If so, then we need to fetch the item from the current Dynamo table:",
"if",
"record",
".",
"get",
"(",
"EVENT_TOO_B... | Utility function that will take a dynamo event record and turn it into the proper pynamo object.
This will properly deserialize the ugly Dynamo datatypes away.
:param record:
:param current_model:
:param durable_model:
:return: | [
"Utility",
"function",
"that",
"will",
"take",
"a",
"dynamo",
"event",
"record",
"and",
"turn",
"it",
"into",
"the",
"proper",
"pynamo",
"object",
"."
] | train | https://github.com/Netflix-Skunkworks/historical/blob/c3ebaa8388a3fe67e23a6c9c6b04c3e618497c4a/historical/common/dynamodb.py#L168-L203 |
Netflix-Skunkworks/historical | historical/common/dynamodb.py | deserialize_current_record_to_current_model | def deserialize_current_record_to_current_model(record, current_model):
"""
Utility function that will take a Dynamo event record and turn it into the proper Current Dynamo object.
This will remove the "current table" specific fields, and properly deserialize the ugly Dynamo datatypes away.
:param reco... | python | def deserialize_current_record_to_current_model(record, current_model):
"""
Utility function that will take a Dynamo event record and turn it into the proper Current Dynamo object.
This will remove the "current table" specific fields, and properly deserialize the ugly Dynamo datatypes away.
:param reco... | [
"def",
"deserialize_current_record_to_current_model",
"(",
"record",
",",
"current_model",
")",
":",
"# Was the item in question too big for SNS? If so, then we need to fetch the item from the current Dynamo table:",
"if",
"record",
".",
"get",
"(",
"EVENT_TOO_BIG_FLAG",
")",
":",
... | Utility function that will take a Dynamo event record and turn it into the proper Current Dynamo object.
This will remove the "current table" specific fields, and properly deserialize the ugly Dynamo datatypes away.
:param record:
:param current_model:
:return: | [
"Utility",
"function",
"that",
"will",
"take",
"a",
"Dynamo",
"event",
"record",
"and",
"turn",
"it",
"into",
"the",
"proper",
"Current",
"Dynamo",
"object",
"."
] | train | https://github.com/Netflix-Skunkworks/historical/blob/c3ebaa8388a3fe67e23a6c9c6b04c3e618497c4a/historical/common/dynamodb.py#L206-L226 |
Netflix-Skunkworks/historical | historical/common/dynamodb.py | deserialize_durable_record_to_durable_model | def deserialize_durable_record_to_durable_model(record, durable_model):
"""
Utility function that will take a Dynamo event record and turn it into the proper Durable Dynamo object.
This will properly deserialize the ugly Dynamo datatypes away.
:param record:
:param durable_model:
:return:
"... | python | def deserialize_durable_record_to_durable_model(record, durable_model):
"""
Utility function that will take a Dynamo event record and turn it into the proper Durable Dynamo object.
This will properly deserialize the ugly Dynamo datatypes away.
:param record:
:param durable_model:
:return:
"... | [
"def",
"deserialize_durable_record_to_durable_model",
"(",
"record",
",",
"durable_model",
")",
":",
"# Was the item in question too big for SNS? If so, then we need to fetch the item from the current Dynamo table:",
"if",
"record",
".",
"get",
"(",
"EVENT_TOO_BIG_FLAG",
")",
":",
... | Utility function that will take a Dynamo event record and turn it into the proper Durable Dynamo object.
This will properly deserialize the ugly Dynamo datatypes away.
:param record:
:param durable_model:
:return: | [
"Utility",
"function",
"that",
"will",
"take",
"a",
"Dynamo",
"event",
"record",
"and",
"turn",
"it",
"into",
"the",
"proper",
"Durable",
"Dynamo",
"object",
"."
] | train | https://github.com/Netflix-Skunkworks/historical/blob/c3ebaa8388a3fe67e23a6c9c6b04c3e618497c4a/historical/common/dynamodb.py#L229-L251 |
Netflix-Skunkworks/historical | historical/common/dynamodb.py | deserialize_durable_record_to_current_model | def deserialize_durable_record_to_current_model(record, current_model):
"""
Utility function that will take a Durable Dynamo event record and turn it into the proper Current Dynamo object.
This will properly deserialize the ugly Dynamo datatypes away.
:param record:
:param current_model:
:retur... | python | def deserialize_durable_record_to_current_model(record, current_model):
"""
Utility function that will take a Durable Dynamo event record and turn it into the proper Current Dynamo object.
This will properly deserialize the ugly Dynamo datatypes away.
:param record:
:param current_model:
:retur... | [
"def",
"deserialize_durable_record_to_current_model",
"(",
"record",
",",
"current_model",
")",
":",
"# Was the item in question too big for SNS? If so, then we need to fetch the item from the current Dynamo table:",
"if",
"record",
".",
"get",
"(",
"EVENT_TOO_BIG_FLAG",
")",
":",
... | Utility function that will take a Durable Dynamo event record and turn it into the proper Current Dynamo object.
This will properly deserialize the ugly Dynamo datatypes away.
:param record:
:param current_model:
:return: | [
"Utility",
"function",
"that",
"will",
"take",
"a",
"Durable",
"Dynamo",
"event",
"record",
"and",
"turn",
"it",
"into",
"the",
"proper",
"Current",
"Dynamo",
"object",
"."
] | train | https://github.com/Netflix-Skunkworks/historical/blob/c3ebaa8388a3fe67e23a6c9c6b04c3e618497c4a/historical/common/dynamodb.py#L254-L275 |
Netflix-Skunkworks/historical | historical/common/dynamodb.py | process_dynamodb_differ_record | def process_dynamodb_differ_record(record, current_model, durable_model, diff_func=None):
"""
Processes a DynamoDB NewImage record (for Differ events).
This will ONLY process the record if the record exists in one of the regions defined by the PROXY_REGIONS of
the current Proxy function.
"""
di... | python | def process_dynamodb_differ_record(record, current_model, durable_model, diff_func=None):
"""
Processes a DynamoDB NewImage record (for Differ events).
This will ONLY process the record if the record exists in one of the regions defined by the PROXY_REGIONS of
the current Proxy function.
"""
di... | [
"def",
"process_dynamodb_differ_record",
"(",
"record",
",",
"current_model",
",",
"durable_model",
",",
"diff_func",
"=",
"None",
")",
":",
"diff_func",
"=",
"diff_func",
"or",
"default_diff",
"# Nothing special needs to be done for deletions as far as items that are too big f... | Processes a DynamoDB NewImage record (for Differ events).
This will ONLY process the record if the record exists in one of the regions defined by the PROXY_REGIONS of
the current Proxy function. | [
"Processes",
"a",
"DynamoDB",
"NewImage",
"record",
"(",
"for",
"Differ",
"events",
")",
"."
] | train | https://github.com/Netflix-Skunkworks/historical/blob/c3ebaa8388a3fe67e23a6c9c6b04c3e618497c4a/historical/common/dynamodb.py#L278-L317 |
Netflix-Skunkworks/historical | historical/models.py | HistoricalPollerTaskEventModel.serialize_me | def serialize_me(self, account_id, region, next_token=None):
"""Dumps the proper JSON for the schema.
:param account_id:
:param region:
:param next_token:
:return:
"""
payload = {
'account_id': account_id,
'region': region
}
... | python | def serialize_me(self, account_id, region, next_token=None):
"""Dumps the proper JSON for the schema.
:param account_id:
:param region:
:param next_token:
:return:
"""
payload = {
'account_id': account_id,
'region': region
}
... | [
"def",
"serialize_me",
"(",
"self",
",",
"account_id",
",",
"region",
",",
"next_token",
"=",
"None",
")",
":",
"payload",
"=",
"{",
"'account_id'",
":",
"account_id",
",",
"'region'",
":",
"region",
"}",
"if",
"next_token",
":",
"payload",
"[",
"'next_tok... | Dumps the proper JSON for the schema.
:param account_id:
:param region:
:param next_token:
:return: | [
"Dumps",
"the",
"proper",
"JSON",
"for",
"the",
"schema",
"."
] | train | https://github.com/Netflix-Skunkworks/historical/blob/c3ebaa8388a3fe67e23a6c9c6b04c3e618497c4a/historical/models.py#L136-L152 |
Netflix-Skunkworks/historical | historical/models.py | SimpleDurableSchema.serialize_me | def serialize_me(self, arn, event_time, tech, item=None):
"""Dumps the proper JSON for the schema. If the event is too big, then don't include the item.
:param arn:
:param event_time:
:param tech:
:param item:
:return:
"""
payload = {
'arn': a... | python | def serialize_me(self, arn, event_time, tech, item=None):
"""Dumps the proper JSON for the schema. If the event is too big, then don't include the item.
:param arn:
:param event_time:
:param tech:
:param item:
:return:
"""
payload = {
'arn': a... | [
"def",
"serialize_me",
"(",
"self",
",",
"arn",
",",
"event_time",
",",
"tech",
",",
"item",
"=",
"None",
")",
":",
"payload",
"=",
"{",
"'arn'",
":",
"arn",
",",
"'event_time'",
":",
"event_time",
",",
"'tech'",
":",
"tech",
"}",
"if",
"item",
":",
... | Dumps the proper JSON for the schema. If the event is too big, then don't include the item.
:param arn:
:param event_time:
:param tech:
:param item:
:return: | [
"Dumps",
"the",
"proper",
"JSON",
"for",
"the",
"schema",
".",
"If",
"the",
"event",
"is",
"too",
"big",
"then",
"don",
"t",
"include",
"the",
"item",
"."
] | train | https://github.com/Netflix-Skunkworks/historical/blob/c3ebaa8388a3fe67e23a6c9c6b04c3e618497c4a/historical/models.py#L169-L190 |
Netflix-Skunkworks/historical | historical/attributes.py | decimal_default | def decimal_default(obj):
"""Properly parse out the Decimal datatypes into proper int/float types."""
if isinstance(obj, decimal.Decimal):
if obj % 1:
return float(obj)
return int(obj)
raise TypeError | python | def decimal_default(obj):
"""Properly parse out the Decimal datatypes into proper int/float types."""
if isinstance(obj, decimal.Decimal):
if obj % 1:
return float(obj)
return int(obj)
raise TypeError | [
"def",
"decimal_default",
"(",
"obj",
")",
":",
"if",
"isinstance",
"(",
"obj",
",",
"decimal",
".",
"Decimal",
")",
":",
"if",
"obj",
"%",
"1",
":",
"return",
"float",
"(",
"obj",
")",
"return",
"int",
"(",
"obj",
")",
"raise",
"TypeError"
] | Properly parse out the Decimal datatypes into proper int/float types. | [
"Properly",
"parse",
"out",
"the",
"Decimal",
"datatypes",
"into",
"proper",
"int",
"/",
"float",
"types",
"."
] | train | https://github.com/Netflix-Skunkworks/historical/blob/c3ebaa8388a3fe67e23a6c9c6b04c3e618497c4a/historical/attributes.py#L52-L58 |
Netflix-Skunkworks/historical | historical/attributes.py | fix_decimals | def fix_decimals(obj):
"""Removes the stupid Decimals
See: https://github.com/boto/boto3/issues/369#issuecomment-302137290
"""
if isinstance(obj, list):
for i in range(len(obj)):
obj[i] = fix_decimals(obj[i])
return obj
elif isinstance(obj, dict):
for key, value... | python | def fix_decimals(obj):
"""Removes the stupid Decimals
See: https://github.com/boto/boto3/issues/369#issuecomment-302137290
"""
if isinstance(obj, list):
for i in range(len(obj)):
obj[i] = fix_decimals(obj[i])
return obj
elif isinstance(obj, dict):
for key, value... | [
"def",
"fix_decimals",
"(",
"obj",
")",
":",
"if",
"isinstance",
"(",
"obj",
",",
"list",
")",
":",
"for",
"i",
"in",
"range",
"(",
"len",
"(",
"obj",
")",
")",
":",
"obj",
"[",
"i",
"]",
"=",
"fix_decimals",
"(",
"obj",
"[",
"i",
"]",
")",
"... | Removes the stupid Decimals
See: https://github.com/boto/boto3/issues/369#issuecomment-302137290 | [
"Removes",
"the",
"stupid",
"Decimals"
] | train | https://github.com/Netflix-Skunkworks/historical/blob/c3ebaa8388a3fe67e23a6c9c6b04c3e618497c4a/historical/attributes.py#L62-L84 |
Netflix-Skunkworks/historical | historical/attributes.py | EventTimeAttribute.serialize | def serialize(self, value):
"""Takes a datetime object and returns a string"""
if isinstance(value, str):
return value
return value.strftime(DATETIME_FORMAT) | python | def serialize(self, value):
"""Takes a datetime object and returns a string"""
if isinstance(value, str):
return value
return value.strftime(DATETIME_FORMAT) | [
"def",
"serialize",
"(",
"self",
",",
"value",
")",
":",
"if",
"isinstance",
"(",
"value",
",",
"str",
")",
":",
"return",
"value",
"return",
"value",
".",
"strftime",
"(",
"DATETIME_FORMAT",
")"
] | Takes a datetime object and returns a string | [
"Takes",
"a",
"datetime",
"object",
"and",
"returns",
"a",
"string"
] | train | https://github.com/Netflix-Skunkworks/historical/blob/c3ebaa8388a3fe67e23a6c9c6b04c3e618497c4a/historical/attributes.py#L45-L49 |
Netflix-Skunkworks/historical | historical/common/util.py | deserialize_records | def deserialize_records(records):
"""
This properly deserializes records depending on where they came from:
- SQS
- SNS
"""
native_records = []
for record in records:
parsed = json.loads(record['body'])
# Is this a DynamoDB stream event?
if isinstance(parsed,... | python | def deserialize_records(records):
"""
This properly deserializes records depending on where they came from:
- SQS
- SNS
"""
native_records = []
for record in records:
parsed = json.loads(record['body'])
# Is this a DynamoDB stream event?
if isinstance(parsed,... | [
"def",
"deserialize_records",
"(",
"records",
")",
":",
"native_records",
"=",
"[",
"]",
"for",
"record",
"in",
"records",
":",
"parsed",
"=",
"json",
".",
"loads",
"(",
"record",
"[",
"'body'",
"]",
")",
"# Is this a DynamoDB stream event?",
"if",
"isinstance... | This properly deserializes records depending on where they came from:
- SQS
- SNS | [
"This",
"properly",
"deserializes",
"records",
"depending",
"on",
"where",
"they",
"came",
"from",
":",
"-",
"SQS",
"-",
"SNS"
] | train | https://github.com/Netflix-Skunkworks/historical/blob/c3ebaa8388a3fe67e23a6c9c6b04c3e618497c4a/historical/common/util.py#L11-L36 |
Netflix-Skunkworks/historical | historical/common/util.py | pull_tag_dict | def pull_tag_dict(data):
"""This will pull out a list of Tag Name-Value objects, and return it as a dictionary.
:param data: The dict collected from the collector.
:returns dict: A dict of the tag names and their corresponding values.
"""
# If there are tags, set them to a normal dict, vs. a list o... | python | def pull_tag_dict(data):
"""This will pull out a list of Tag Name-Value objects, and return it as a dictionary.
:param data: The dict collected from the collector.
:returns dict: A dict of the tag names and their corresponding values.
"""
# If there are tags, set them to a normal dict, vs. a list o... | [
"def",
"pull_tag_dict",
"(",
"data",
")",
":",
"# If there are tags, set them to a normal dict, vs. a list of dicts:",
"tags",
"=",
"data",
".",
"pop",
"(",
"'Tags'",
",",
"{",
"}",
")",
"or",
"{",
"}",
"if",
"tags",
":",
"proper_tags",
"=",
"{",
"}",
"for",
... | This will pull out a list of Tag Name-Value objects, and return it as a dictionary.
:param data: The dict collected from the collector.
:returns dict: A dict of the tag names and their corresponding values. | [
"This",
"will",
"pull",
"out",
"a",
"list",
"of",
"Tag",
"Name",
"-",
"Value",
"objects",
"and",
"return",
"it",
"as",
"a",
"dictionary",
"."
] | train | https://github.com/Netflix-Skunkworks/historical/blob/c3ebaa8388a3fe67e23a6c9c6b04c3e618497c4a/historical/common/util.py#L39-L54 |
Netflix-Skunkworks/historical | historical/s3/collector.py | create_delete_model | def create_delete_model(record):
"""Create an S3 model from a record."""
arn = f"arn:aws:s3:::{cloudwatch.filter_request_parameters('bucketName', record)}"
LOG.debug(f'[-] Deleting Dynamodb Records. Hash Key: {arn}')
data = {
'arn': arn,
'principalId': cloudwatch.get_principal(record),
... | python | def create_delete_model(record):
"""Create an S3 model from a record."""
arn = f"arn:aws:s3:::{cloudwatch.filter_request_parameters('bucketName', record)}"
LOG.debug(f'[-] Deleting Dynamodb Records. Hash Key: {arn}')
data = {
'arn': arn,
'principalId': cloudwatch.get_principal(record),
... | [
"def",
"create_delete_model",
"(",
"record",
")",
":",
"arn",
"=",
"f\"arn:aws:s3:::{cloudwatch.filter_request_parameters('bucketName', record)}\"",
"LOG",
".",
"debug",
"(",
"f'[-] Deleting Dynamodb Records. Hash Key: {arn}'",
")",
"data",
"=",
"{",
"'arn'",
":",
"arn",
",... | Create an S3 model from a record. | [
"Create",
"an",
"S3",
"model",
"from",
"a",
"record",
"."
] | train | https://github.com/Netflix-Skunkworks/historical/blob/c3ebaa8388a3fe67e23a6c9c6b04c3e618497c4a/historical/s3/collector.py#L55-L74 |
Netflix-Skunkworks/historical | historical/s3/collector.py | process_delete_records | def process_delete_records(delete_records):
"""Process the requests for S3 bucket deletions"""
for rec in delete_records:
arn = f"arn:aws:s3:::{rec['detail']['requestParameters']['bucketName']}"
# Need to check if the event is NEWER than the previous event in case
# events are out of or... | python | def process_delete_records(delete_records):
"""Process the requests for S3 bucket deletions"""
for rec in delete_records:
arn = f"arn:aws:s3:::{rec['detail']['requestParameters']['bucketName']}"
# Need to check if the event is NEWER than the previous event in case
# events are out of or... | [
"def",
"process_delete_records",
"(",
"delete_records",
")",
":",
"for",
"rec",
"in",
"delete_records",
":",
"arn",
"=",
"f\"arn:aws:s3:::{rec['detail']['requestParameters']['bucketName']}\"",
"# Need to check if the event is NEWER than the previous event in case",
"# events are out of... | Process the requests for S3 bucket deletions | [
"Process",
"the",
"requests",
"for",
"S3",
"bucket",
"deletions"
] | train | https://github.com/Netflix-Skunkworks/historical/blob/c3ebaa8388a3fe67e23a6c9c6b04c3e618497c4a/historical/s3/collector.py#L77-L96 |
Netflix-Skunkworks/historical | historical/s3/collector.py | process_update_records | def process_update_records(update_records):
"""Process the requests for S3 bucket update requests"""
events = sorted(update_records, key=lambda x: x['account'])
# Group records by account for more efficient processing
for account_id, events in groupby(events, lambda x: x['account']):
events = l... | python | def process_update_records(update_records):
"""Process the requests for S3 bucket update requests"""
events = sorted(update_records, key=lambda x: x['account'])
# Group records by account for more efficient processing
for account_id, events in groupby(events, lambda x: x['account']):
events = l... | [
"def",
"process_update_records",
"(",
"update_records",
")",
":",
"events",
"=",
"sorted",
"(",
"update_records",
",",
"key",
"=",
"lambda",
"x",
":",
"x",
"[",
"'account'",
"]",
")",
"# Group records by account for more efficient processing",
"for",
"account_id",
"... | Process the requests for S3 bucket update requests | [
"Process",
"the",
"requests",
"for",
"S3",
"bucket",
"update",
"requests"
] | train | https://github.com/Netflix-Skunkworks/historical/blob/c3ebaa8388a3fe67e23a6c9c6b04c3e618497c4a/historical/s3/collector.py#L99-L179 |
Netflix-Skunkworks/historical | historical/s3/collector.py | handler | def handler(event, context): # pylint: disable=W0613
"""
Historical S3 event collector.
This collector is responsible for processing CloudWatch events and polling events.
"""
records = deserialize_records(event['Records'])
# Split records into two groups, update and delete.
# We don't wan... | python | def handler(event, context): # pylint: disable=W0613
"""
Historical S3 event collector.
This collector is responsible for processing CloudWatch events and polling events.
"""
records = deserialize_records(event['Records'])
# Split records into two groups, update and delete.
# We don't wan... | [
"def",
"handler",
"(",
"event",
",",
"context",
")",
":",
"# pylint: disable=W0613",
"records",
"=",
"deserialize_records",
"(",
"event",
"[",
"'Records'",
"]",
")",
"# Split records into two groups, update and delete.",
"# We don't want to query for deleted records.",
"updat... | Historical S3 event collector.
This collector is responsible for processing CloudWatch events and polling events. | [
"Historical",
"S3",
"event",
"collector",
"."
] | train | https://github.com/Netflix-Skunkworks/historical/blob/c3ebaa8388a3fe67e23a6c9c6b04c3e618497c4a/historical/s3/collector.py#L183-L203 |
Netflix-Skunkworks/historical | historical/historical-cookiecutter/historical_{{cookiecutter.technology_slug}}/{{cookiecutter.technology_slug}}/poller.py | handler | def handler(event, context):
"""
Historical {{cookiecutter.technology_name}} event poller.
This poller is run at a set interval in order to ensure that changes do not go undetected by historical.
Historical pollers generate `polling events` which simulate changes. These polling events contain configu... | python | def handler(event, context):
"""
Historical {{cookiecutter.technology_name}} event poller.
This poller is run at a set interval in order to ensure that changes do not go undetected by historical.
Historical pollers generate `polling events` which simulate changes. These polling events contain configu... | [
"def",
"handler",
"(",
"event",
",",
"context",
")",
":",
"log",
".",
"debug",
"(",
"'Running poller. Configuration: {}'",
".",
"format",
"(",
"event",
")",
")",
"for",
"account",
"in",
"get_historical_accounts",
"(",
")",
":",
"try",
":",
"# TODO describe all... | Historical {{cookiecutter.technology_name}} event poller.
This poller is run at a set interval in order to ensure that changes do not go undetected by historical.
Historical pollers generate `polling events` which simulate changes. These polling events contain configuration
data such as the account/regio... | [
"Historical",
"{{",
"cookiecutter",
".",
"technology_name",
"}}",
"event",
"poller",
"."
] | train | https://github.com/Netflix-Skunkworks/historical/blob/c3ebaa8388a3fe67e23a6c9c6b04c3e618497c4a/historical/historical-cookiecutter/historical_{{cookiecutter.technology_slug}}/{{cookiecutter.technology_slug}}/poller.py#L27-L56 |
Netflix-Skunkworks/historical | historical/common/accounts.py | get_historical_accounts | def get_historical_accounts():
"""Fetches valid accounts from SWAG if enabled or a list accounts."""
if os.environ.get('SWAG_BUCKET', False):
swag_opts = {
'swag.type': 's3',
'swag.bucket_name': os.environ['SWAG_BUCKET'],
'swag.data_file': os.environ.get('SWAG_DATA_FI... | python | def get_historical_accounts():
"""Fetches valid accounts from SWAG if enabled or a list accounts."""
if os.environ.get('SWAG_BUCKET', False):
swag_opts = {
'swag.type': 's3',
'swag.bucket_name': os.environ['SWAG_BUCKET'],
'swag.data_file': os.environ.get('SWAG_DATA_FI... | [
"def",
"get_historical_accounts",
"(",
")",
":",
"if",
"os",
".",
"environ",
".",
"get",
"(",
"'SWAG_BUCKET'",
",",
"False",
")",
":",
"swag_opts",
"=",
"{",
"'swag.type'",
":",
"'s3'",
",",
"'swag.bucket_name'",
":",
"os",
".",
"environ",
"[",
"'SWAG_BUCK... | Fetches valid accounts from SWAG if enabled or a list accounts. | [
"Fetches",
"valid",
"accounts",
"from",
"SWAG",
"if",
"enabled",
"or",
"a",
"list",
"accounts",
"."
] | train | https://github.com/Netflix-Skunkworks/historical/blob/c3ebaa8388a3fe67e23a6c9c6b04c3e618497c4a/historical/common/accounts.py#L26-L47 |
Netflix-Skunkworks/historical | historical/s3/poller.py | poller_processor_handler | def poller_processor_handler(event, context): # pylint: disable=W0613
"""
Historical S3 Poller Processor.
This will receive events from the Poller Tasker, and will list all objects of a given technology for an
account/region pair. This will generate `polling events` which simulate changes. These polli... | python | def poller_processor_handler(event, context): # pylint: disable=W0613
"""
Historical S3 Poller Processor.
This will receive events from the Poller Tasker, and will list all objects of a given technology for an
account/region pair. This will generate `polling events` which simulate changes. These polli... | [
"def",
"poller_processor_handler",
"(",
"event",
",",
"context",
")",
":",
"# pylint: disable=W0613",
"LOG",
".",
"debug",
"(",
"'[@] Running Poller...'",
")",
"queue_url",
"=",
"get_queue_url",
"(",
"os",
".",
"environ",
".",
"get",
"(",
"'POLLER_QUEUE_NAME'",
",... | Historical S3 Poller Processor.
This will receive events from the Poller Tasker, and will list all objects of a given technology for an
account/region pair. This will generate `polling events` which simulate changes. These polling events contain
configuration data such as the account/region defining where ... | [
"Historical",
"S3",
"Poller",
"Processor",
"."
] | train | https://github.com/Netflix-Skunkworks/historical/blob/c3ebaa8388a3fe67e23a6c9c6b04c3e618497c4a/historical/s3/poller.py#L58-L87 |
Netflix-Skunkworks/historical | historical/common/proxy.py | shrink_blob | def shrink_blob(record, deletion):
"""
Makes a shrunken blob to be sent to SNS/SQS (due to the 256KB size limitations of SNS/SQS messages).
This will essentially remove the "configuration" field such that the size of the SNS/SQS message remains under
256KB.
:param record:
:return:
"""
it... | python | def shrink_blob(record, deletion):
"""
Makes a shrunken blob to be sent to SNS/SQS (due to the 256KB size limitations of SNS/SQS messages).
This will essentially remove the "configuration" field such that the size of the SNS/SQS message remains under
256KB.
:param record:
:return:
"""
it... | [
"def",
"shrink_blob",
"(",
"record",
",",
"deletion",
")",
":",
"item",
"=",
"{",
"\"eventName\"",
":",
"record",
"[",
"\"eventName\"",
"]",
",",
"EVENT_TOO_BIG_FLAG",
":",
"(",
"not",
"deletion",
")",
"}",
"# To handle TTLs (if they happen)",
"if",
"record",
... | Makes a shrunken blob to be sent to SNS/SQS (due to the 256KB size limitations of SNS/SQS messages).
This will essentially remove the "configuration" field such that the size of the SNS/SQS message remains under
256KB.
:param record:
:return: | [
"Makes",
"a",
"shrunken",
"blob",
"to",
"be",
"sent",
"to",
"SNS",
"/",
"SQS",
"(",
"due",
"to",
"the",
"256KB",
"size",
"limitations",
"of",
"SNS",
"/",
"SQS",
"messages",
")",
".",
"This",
"will",
"essentially",
"remove",
"the",
"configuration",
"field... | train | https://github.com/Netflix-Skunkworks/historical/blob/c3ebaa8388a3fe67e23a6c9c6b04c3e618497c4a/historical/common/proxy.py#L34-L64 |
Netflix-Skunkworks/historical | historical/common/proxy.py | handler | def handler(event, context): # pylint: disable=W0613
"""Historical S3 DynamoDB Stream Forwarder (the 'Proxy').
Passes events from the Historical DynamoDB stream and passes it to SNS or SQS for additional events to trigger.
You can optionally use SNS or SQS. It is preferable to use SNS -> SQS, but in some... | python | def handler(event, context): # pylint: disable=W0613
"""Historical S3 DynamoDB Stream Forwarder (the 'Proxy').
Passes events from the Historical DynamoDB stream and passes it to SNS or SQS for additional events to trigger.
You can optionally use SNS or SQS. It is preferable to use SNS -> SQS, but in some... | [
"def",
"handler",
"(",
"event",
",",
"context",
")",
":",
"# pylint: disable=W0613",
"queue_url",
"=",
"os",
".",
"environ",
".",
"get",
"(",
"'PROXY_QUEUE_URL'",
")",
"topic_arn",
"=",
"os",
".",
"environ",
".",
"get",
"(",
"'PROXY_TOPIC_ARN'",
")",
"if",
... | Historical S3 DynamoDB Stream Forwarder (the 'Proxy').
Passes events from the Historical DynamoDB stream and passes it to SNS or SQS for additional events to trigger.
You can optionally use SNS or SQS. It is preferable to use SNS -> SQS, but in some cases, such as the Current stream
to the Differ, this wi... | [
"Historical",
"S3",
"DynamoDB",
"Stream",
"Forwarder",
"(",
"the",
"Proxy",
")",
"."
] | train | https://github.com/Netflix-Skunkworks/historical/blob/c3ebaa8388a3fe67e23a6c9c6b04c3e618497c4a/historical/common/proxy.py#L68-L123 |
Netflix-Skunkworks/historical | historical/common/proxy.py | detect_global_table_updates | def detect_global_table_updates(record):
"""This will detect DDB Global Table updates that are not relevant to application data updates. These need to be
skipped over as they are pure noise.
:param record:
:return:
"""
# This only affects MODIFY events.
if record['eventName'] == 'MODIFY'... | python | def detect_global_table_updates(record):
"""This will detect DDB Global Table updates that are not relevant to application data updates. These need to be
skipped over as they are pure noise.
:param record:
:return:
"""
# This only affects MODIFY events.
if record['eventName'] == 'MODIFY'... | [
"def",
"detect_global_table_updates",
"(",
"record",
")",
":",
"# This only affects MODIFY events.",
"if",
"record",
"[",
"'eventName'",
"]",
"==",
"'MODIFY'",
":",
"# Need to compare the old and new images to check for GT specific changes only (just pop off the GT fields)",
"old_ima... | This will detect DDB Global Table updates that are not relevant to application data updates. These need to be
skipped over as they are pure noise.
:param record:
:return: | [
"This",
"will",
"detect",
"DDB",
"Global",
"Table",
"updates",
"that",
"are",
"not",
"relevant",
"to",
"application",
"data",
"updates",
".",
"These",
"need",
"to",
"be",
"skipped",
"over",
"as",
"they",
"are",
"pure",
"noise",
"."
] | train | https://github.com/Netflix-Skunkworks/historical/blob/c3ebaa8388a3fe67e23a6c9c6b04c3e618497c4a/historical/common/proxy.py#L126-L142 |
Netflix-Skunkworks/historical | historical/common/proxy.py | make_proper_dynamodb_record | def make_proper_dynamodb_record(record, force_shrink=False):
"""Prepares and ships an individual DynamoDB record over to SNS/SQS for future processing.
:param record:
:param force_shrink:
:return:
"""
# Get the initial blob and determine if it is too big for SNS/SQS:
blob = json.dumps(recor... | python | def make_proper_dynamodb_record(record, force_shrink=False):
"""Prepares and ships an individual DynamoDB record over to SNS/SQS for future processing.
:param record:
:param force_shrink:
:return:
"""
# Get the initial blob and determine if it is too big for SNS/SQS:
blob = json.dumps(recor... | [
"def",
"make_proper_dynamodb_record",
"(",
"record",
",",
"force_shrink",
"=",
"False",
")",
":",
"# Get the initial blob and determine if it is too big for SNS/SQS:",
"blob",
"=",
"json",
".",
"dumps",
"(",
"record",
")",
"size",
"=",
"math",
".",
"ceil",
"(",
"sys... | Prepares and ships an individual DynamoDB record over to SNS/SQS for future processing.
:param record:
:param force_shrink:
:return: | [
"Prepares",
"and",
"ships",
"an",
"individual",
"DynamoDB",
"record",
"over",
"to",
"SNS",
"/",
"SQS",
"for",
"future",
"processing",
"."
] | train | https://github.com/Netflix-Skunkworks/historical/blob/c3ebaa8388a3fe67e23a6c9c6b04c3e618497c4a/historical/common/proxy.py#L145-L170 |
Netflix-Skunkworks/historical | historical/common/proxy.py | make_proper_simple_record | def make_proper_simple_record(record, force_shrink=False):
"""Prepares and ships an individual simplified durable table record over to SNS/SQS for future processing.
:param record:
:param force_shrink:
:return:
"""
# Convert to a simple object
item = {
'arn': record['dynamodb']['Key... | python | def make_proper_simple_record(record, force_shrink=False):
"""Prepares and ships an individual simplified durable table record over to SNS/SQS for future processing.
:param record:
:param force_shrink:
:return:
"""
# Convert to a simple object
item = {
'arn': record['dynamodb']['Key... | [
"def",
"make_proper_simple_record",
"(",
"record",
",",
"force_shrink",
"=",
"False",
")",
":",
"# Convert to a simple object",
"item",
"=",
"{",
"'arn'",
":",
"record",
"[",
"'dynamodb'",
"]",
"[",
"'Keys'",
"]",
"[",
"'arn'",
"]",
"[",
"'S'",
"]",
",",
"... | Prepares and ships an individual simplified durable table record over to SNS/SQS for future processing.
:param record:
:param force_shrink:
:return: | [
"Prepares",
"and",
"ships",
"an",
"individual",
"simplified",
"durable",
"table",
"record",
"over",
"to",
"SNS",
"/",
"SQS",
"for",
"future",
"processing",
"."
] | train | https://github.com/Netflix-Skunkworks/historical/blob/c3ebaa8388a3fe67e23a6c9c6b04c3e618497c4a/historical/common/proxy.py#L184-L217 |
Netflix-Skunkworks/historical | historical/s3/differ.py | handler | def handler(event, context): # pylint: disable=W0613
"""
Historical S3 event differ.
Listens to the Historical current table and determines if there are differences that need to be persisted in the
historical record.
"""
# De-serialize the records:
records = deserialize_records(event['Reco... | python | def handler(event, context): # pylint: disable=W0613
"""
Historical S3 event differ.
Listens to the Historical current table and determines if there are differences that need to be persisted in the
historical record.
"""
# De-serialize the records:
records = deserialize_records(event['Reco... | [
"def",
"handler",
"(",
"event",
",",
"context",
")",
":",
"# pylint: disable=W0613",
"# De-serialize the records:",
"records",
"=",
"deserialize_records",
"(",
"event",
"[",
"'Records'",
"]",
")",
"for",
"record",
"in",
"records",
":",
"process_dynamodb_differ_record"... | Historical S3 event differ.
Listens to the Historical current table and determines if there are differences that need to be persisted in the
historical record. | [
"Historical",
"S3",
"event",
"differ",
"."
] | train | https://github.com/Netflix-Skunkworks/historical/blob/c3ebaa8388a3fe67e23a6c9c6b04c3e618497c4a/historical/s3/differ.py#L26-L37 |
Netflix-Skunkworks/historical | historical/cli.py | new | def new():
"""Creates a new historical technology."""
dir_path = os.path.dirname(os.path.realpath(__file__))
cookiecutter(os.path.join(dir_path, 'historical-cookiecutter/')) | python | def new():
"""Creates a new historical technology."""
dir_path = os.path.dirname(os.path.realpath(__file__))
cookiecutter(os.path.join(dir_path, 'historical-cookiecutter/')) | [
"def",
"new",
"(",
")",
":",
"dir_path",
"=",
"os",
".",
"path",
".",
"dirname",
"(",
"os",
".",
"path",
".",
"realpath",
"(",
"__file__",
")",
")",
"cookiecutter",
"(",
"os",
".",
"path",
".",
"join",
"(",
"dir_path",
",",
"'historical-cookiecutter/'"... | Creates a new historical technology. | [
"Creates",
"a",
"new",
"historical",
"technology",
"."
] | train | https://github.com/Netflix-Skunkworks/historical/blob/c3ebaa8388a3fe67e23a6c9c6b04c3e618497c4a/historical/cli.py#L30-L33 |
Netflix-Skunkworks/historical | historical/security_group/poller.py | poller_processor_handler | def poller_processor_handler(event, context): # pylint: disable=W0613
"""
Historical Security Group Poller Processor.
This will receive events from the Poller Tasker, and will list all objects of a given technology for an
account/region pair. This will generate `polling events` which simulate changes.... | python | def poller_processor_handler(event, context): # pylint: disable=W0613
"""
Historical Security Group Poller Processor.
This will receive events from the Poller Tasker, and will list all objects of a given technology for an
account/region pair. This will generate `polling events` which simulate changes.... | [
"def",
"poller_processor_handler",
"(",
"event",
",",
"context",
")",
":",
"# pylint: disable=W0613",
"LOG",
".",
"debug",
"(",
"'[@] Running Poller...'",
")",
"collector_poller_queue_url",
"=",
"get_queue_url",
"(",
"os",
".",
"environ",
".",
"get",
"(",
"'POLLER_Q... | Historical Security Group Poller Processor.
This will receive events from the Poller Tasker, and will list all objects of a given technology for an
account/region pair. This will generate `polling events` which simulate changes. These polling events contain
configuration data such as the account/region def... | [
"Historical",
"Security",
"Group",
"Poller",
"Processor",
"."
] | train | https://github.com/Netflix-Skunkworks/historical/blob/c3ebaa8388a3fe67e23a6c9c6b04c3e618497c4a/historical/security_group/poller.py#L61-L118 |
Netflix-Skunkworks/historical | historical/vpc/poller.py | poller_tasker_handler | def poller_tasker_handler(event, context): # pylint: disable=W0613
"""
Historical VPC Poller Tasker.
The Poller is run at a set interval in order to ensure that changes do not go undetected by Historical.
Historical pollers generate `polling events` which simulate changes. These polling events contai... | python | def poller_tasker_handler(event, context): # pylint: disable=W0613
"""
Historical VPC Poller Tasker.
The Poller is run at a set interval in order to ensure that changes do not go undetected by Historical.
Historical pollers generate `polling events` which simulate changes. These polling events contai... | [
"def",
"poller_tasker_handler",
"(",
"event",
",",
"context",
")",
":",
"# pylint: disable=W0613",
"LOG",
".",
"debug",
"(",
"'[@] Running Poller Tasker...'",
")",
"queue_url",
"=",
"get_queue_url",
"(",
"os",
".",
"environ",
".",
"get",
"(",
"'POLLER_TASKER_QUEUE_N... | Historical VPC Poller Tasker.
The Poller is run at a set interval in order to ensure that changes do not go undetected by Historical.
Historical pollers generate `polling events` which simulate changes. These polling events contain configuration
data such as the account/region defining where the collector... | [
"Historical",
"VPC",
"Poller",
"Tasker",
"."
] | train | https://github.com/Netflix-Skunkworks/historical/blob/c3ebaa8388a3fe67e23a6c9c6b04c3e618497c4a/historical/vpc/poller.py#L30-L57 |
Netflix-Skunkworks/historical | historical/vpc/poller.py | poller_processor_handler | def poller_processor_handler(event, context): # pylint: disable=W0613
"""
Historical Security Group Poller Processor.
This will receive events from the Poller Tasker, and will list all objects of a given technology for an
account/region pair. This will generate `polling events` which simulate changes.... | python | def poller_processor_handler(event, context): # pylint: disable=W0613
"""
Historical Security Group Poller Processor.
This will receive events from the Poller Tasker, and will list all objects of a given technology for an
account/region pair. This will generate `polling events` which simulate changes.... | [
"def",
"poller_processor_handler",
"(",
"event",
",",
"context",
")",
":",
"# pylint: disable=W0613",
"LOG",
".",
"debug",
"(",
"'[@] Running Poller...'",
")",
"queue_url",
"=",
"get_queue_url",
"(",
"os",
".",
"environ",
".",
"get",
"(",
"'POLLER_QUEUE_NAME'",
",... | Historical Security Group Poller Processor.
This will receive events from the Poller Tasker, and will list all objects of a given technology for an
account/region pair. This will generate `polling events` which simulate changes. These polling events contain
configuration data such as the account/region def... | [
"Historical",
"Security",
"Group",
"Poller",
"Processor",
"."
] | train | https://github.com/Netflix-Skunkworks/historical/blob/c3ebaa8388a3fe67e23a6c9c6b04c3e618497c4a/historical/vpc/poller.py#L61-L90 |
Netflix-Skunkworks/historical | historical/common/sqs.py | chunks | def chunks(event_list, chunk_size):
"""Yield successive n-sized chunks from the event list."""
for i in range(0, len(event_list), chunk_size):
yield event_list[i:i + chunk_size] | python | def chunks(event_list, chunk_size):
"""Yield successive n-sized chunks from the event list."""
for i in range(0, len(event_list), chunk_size):
yield event_list[i:i + chunk_size] | [
"def",
"chunks",
"(",
"event_list",
",",
"chunk_size",
")",
":",
"for",
"i",
"in",
"range",
"(",
"0",
",",
"len",
"(",
"event_list",
")",
",",
"chunk_size",
")",
":",
"yield",
"event_list",
"[",
"i",
":",
"i",
"+",
"chunk_size",
"]"
] | Yield successive n-sized chunks from the event list. | [
"Yield",
"successive",
"n",
"-",
"sized",
"chunks",
"from",
"the",
"event",
"list",
"."
] | train | https://github.com/Netflix-Skunkworks/historical/blob/c3ebaa8388a3fe67e23a6c9c6b04c3e618497c4a/historical/common/sqs.py#L21-L24 |
Netflix-Skunkworks/historical | historical/common/sqs.py | get_queue_url | def get_queue_url(queue_name):
"""Get the URL of the SQS queue to send events to."""
client = boto3.client("sqs", CURRENT_REGION)
queue = client.get_queue_url(QueueName=queue_name)
return queue["QueueUrl"] | python | def get_queue_url(queue_name):
"""Get the URL of the SQS queue to send events to."""
client = boto3.client("sqs", CURRENT_REGION)
queue = client.get_queue_url(QueueName=queue_name)
return queue["QueueUrl"] | [
"def",
"get_queue_url",
"(",
"queue_name",
")",
":",
"client",
"=",
"boto3",
".",
"client",
"(",
"\"sqs\"",
",",
"CURRENT_REGION",
")",
"queue",
"=",
"client",
".",
"get_queue_url",
"(",
"QueueName",
"=",
"queue_name",
")",
"return",
"queue",
"[",
"\"QueueUr... | Get the URL of the SQS queue to send events to. | [
"Get",
"the",
"URL",
"of",
"the",
"SQS",
"queue",
"to",
"send",
"events",
"to",
"."
] | train | https://github.com/Netflix-Skunkworks/historical/blob/c3ebaa8388a3fe67e23a6c9c6b04c3e618497c4a/historical/common/sqs.py#L27-L32 |
Netflix-Skunkworks/historical | historical/common/sqs.py | produce_events | def produce_events(events, queue_url, batch_size=10, randomize_delay=0):
"""
Efficiently sends events to the SQS event queue.
Note: SQS has a max size of 10 items. Please be aware that this can make the messages go past size -- even
with shrinking messages!
Events can get randomized delays, maxim... | python | def produce_events(events, queue_url, batch_size=10, randomize_delay=0):
"""
Efficiently sends events to the SQS event queue.
Note: SQS has a max size of 10 items. Please be aware that this can make the messages go past size -- even
with shrinking messages!
Events can get randomized delays, maxim... | [
"def",
"produce_events",
"(",
"events",
",",
"queue_url",
",",
"batch_size",
"=",
"10",
",",
"randomize_delay",
"=",
"0",
")",
":",
"client",
"=",
"boto3",
".",
"client",
"(",
"'sqs'",
",",
"region_name",
"=",
"CURRENT_REGION",
")",
"for",
"chunk",
"in",
... | Efficiently sends events to the SQS event queue.
Note: SQS has a max size of 10 items. Please be aware that this can make the messages go past size -- even
with shrinking messages!
Events can get randomized delays, maximum of 900 seconds. Set that in `randomize_delay`
:param events:
:param queue_... | [
"Efficiently",
"sends",
"events",
"to",
"the",
"SQS",
"event",
"queue",
"."
] | train | https://github.com/Netflix-Skunkworks/historical/blob/c3ebaa8388a3fe67e23a6c9c6b04c3e618497c4a/historical/common/sqs.py#L55-L73 |
Netflix-Skunkworks/historical | historical/common/sqs.py | group_records_by_type | def group_records_by_type(records, update_events):
"""Break records into two lists; create/update events and delete events.
:param records:
:param update_events:
:return update_records, delete_records:
"""
update_records, delete_records = [], []
for record in records:
if record.get(... | python | def group_records_by_type(records, update_events):
"""Break records into two lists; create/update events and delete events.
:param records:
:param update_events:
:return update_records, delete_records:
"""
update_records, delete_records = [], []
for record in records:
if record.get(... | [
"def",
"group_records_by_type",
"(",
"records",
",",
"update_events",
")",
":",
"update_records",
",",
"delete_records",
"=",
"[",
"]",
",",
"[",
"]",
"for",
"record",
"in",
"records",
":",
"if",
"record",
".",
"get",
"(",
"\"detail-type\"",
",",
"\"\"",
"... | Break records into two lists; create/update events and delete events.
:param records:
:param update_events:
:return update_records, delete_records: | [
"Break",
"records",
"into",
"two",
"lists",
";",
"create",
"/",
"update",
"events",
"and",
"delete",
"events",
"."
] | train | https://github.com/Netflix-Skunkworks/historical/blob/c3ebaa8388a3fe67e23a6c9c6b04c3e618497c4a/historical/common/sqs.py#L76-L101 |
Netflix-Skunkworks/historical | historical/security_group/differ.py | handler | def handler(event, context): # pylint: disable=W0613
"""
Historical security group event differ.
Listens to the Historical current table and determines if there are differences that need to be persisted in the
historical record.
"""
# De-serialize the records:
records = deserialize_records... | python | def handler(event, context): # pylint: disable=W0613
"""
Historical security group event differ.
Listens to the Historical current table and determines if there are differences that need to be persisted in the
historical record.
"""
# De-serialize the records:
records = deserialize_records... | [
"def",
"handler",
"(",
"event",
",",
"context",
")",
":",
"# pylint: disable=W0613",
"# De-serialize the records:",
"records",
"=",
"deserialize_records",
"(",
"event",
"[",
"'Records'",
"]",
")",
"for",
"record",
"in",
"records",
":",
"process_dynamodb_differ_record"... | Historical security group event differ.
Listens to the Historical current table and determines if there are differences that need to be persisted in the
historical record. | [
"Historical",
"security",
"group",
"event",
"differ",
"."
] | train | https://github.com/Netflix-Skunkworks/historical/blob/c3ebaa8388a3fe67e23a6c9c6b04c3e618497c4a/historical/security_group/differ.py#L23-L34 |
Netflix-Skunkworks/historical | historical/historical-cookiecutter/historical_{{cookiecutter.technology_slug}}/{{cookiecutter.technology_slug}}/differ.py | handler | def handler(event, context):
"""
Historical security group event differ.
Listens to the Historical current table and determines if there are differences that need to be persisted in the
historical record.
"""
for record in event['Records']:
process_dynamodb_differ_record(record, Durable... | python | def handler(event, context):
"""
Historical security group event differ.
Listens to the Historical current table and determines if there are differences that need to be persisted in the
historical record.
"""
for record in event['Records']:
process_dynamodb_differ_record(record, Durable... | [
"def",
"handler",
"(",
"event",
",",
"context",
")",
":",
"for",
"record",
"in",
"event",
"[",
"'Records'",
"]",
":",
"process_dynamodb_differ_record",
"(",
"record",
",",
"Durable",
"{",
"{",
"cookiecutter",
".",
"technology_slug",
"|",
"titlecase",
"}",
"}... | Historical security group event differ.
Listens to the Historical current table and determines if there are differences that need to be persisted in the
historical record. | [
"Historical",
"security",
"group",
"event",
"differ",
"."
] | train | https://github.com/Netflix-Skunkworks/historical/blob/c3ebaa8388a3fe67e23a6c9c6b04c3e618497c4a/historical/historical-cookiecutter/historical_{{cookiecutter.technology_slug}}/{{cookiecutter.technology_slug}}/differ.py#L21-L29 |
Netflix-Skunkworks/historical | historical/historical-cookiecutter/historical_{{cookiecutter.technology_slug}}/{{cookiecutter.technology_slug}}/collector.py | group_records_by_type | def group_records_by_type(records):
"""Break records into two lists; create/update events and delete events."""
update_records, delete_records = [], []
for r in records:
if isinstance(r, str):
break
if r['detail']['eventName'] in UPDATE_EVENTS:
update_records.append(... | python | def group_records_by_type(records):
"""Break records into two lists; create/update events and delete events."""
update_records, delete_records = [], []
for r in records:
if isinstance(r, str):
break
if r['detail']['eventName'] in UPDATE_EVENTS:
update_records.append(... | [
"def",
"group_records_by_type",
"(",
"records",
")",
":",
"update_records",
",",
"delete_records",
"=",
"[",
"]",
",",
"[",
"]",
"for",
"r",
"in",
"records",
":",
"if",
"isinstance",
"(",
"r",
",",
"str",
")",
":",
"break",
"if",
"r",
"[",
"'detail'",
... | Break records into two lists; create/update events and delete events. | [
"Break",
"records",
"into",
"two",
"lists",
";",
"create",
"/",
"update",
"events",
"and",
"delete",
"events",
"."
] | train | https://github.com/Netflix-Skunkworks/historical/blob/c3ebaa8388a3fe67e23a6c9c6b04c3e618497c4a/historical/historical-cookiecutter/historical_{{cookiecutter.technology_slug}}/{{cookiecutter.technology_slug}}/collector.py#L47-L58 |
Netflix-Skunkworks/historical | historical/historical-cookiecutter/historical_{{cookiecutter.technology_slug}}/{{cookiecutter.technology_slug}}/collector.py | create_delete_model | def create_delete_model(record):
"""Create a {{cookiecutter.technology_name}} model from a record."""
data = cloudwatch.get_historical_base_info(record)
# TODO get tech ID
# Example::
# group_id = cloudwatch.filter_request_parameters('groupId', record)
# vpc_id = cloudwatch.filter_request... | python | def create_delete_model(record):
"""Create a {{cookiecutter.technology_name}} model from a record."""
data = cloudwatch.get_historical_base_info(record)
# TODO get tech ID
# Example::
# group_id = cloudwatch.filter_request_parameters('groupId', record)
# vpc_id = cloudwatch.filter_request... | [
"def",
"create_delete_model",
"(",
"record",
")",
":",
"data",
"=",
"cloudwatch",
".",
"get_historical_base_info",
"(",
"record",
")",
"# TODO get tech ID",
"# Example::",
"# group_id = cloudwatch.filter_request_parameters('groupId', record)",
"# vpc_id = cloudwatch.filter_re... | Create a {{cookiecutter.technology_name}} model from a record. | [
"Create",
"a",
"{{",
"cookiecutter",
".",
"technology_name",
"}}",
"model",
"from",
"a",
"record",
"."
] | train | https://github.com/Netflix-Skunkworks/historical/blob/c3ebaa8388a3fe67e23a6c9c6b04c3e618497c4a/historical/historical-cookiecutter/historical_{{cookiecutter.technology_slug}}/{{cookiecutter.technology_slug}}/collector.py#L105-L132 |
Netflix-Skunkworks/historical | historical/historical-cookiecutter/historical_{{cookiecutter.technology_slug}}/{{cookiecutter.technology_slug}}/collector.py | capture_delete_records | def capture_delete_records(records):
"""Writes all of our delete events to DynamoDB."""
for r in records:
model = create_delete_model(r)
if model:
try:
model.delete(eventTime__le=r['detail']['eventTime'])
except DeleteError as e:
log.warnin... | python | def capture_delete_records(records):
"""Writes all of our delete events to DynamoDB."""
for r in records:
model = create_delete_model(r)
if model:
try:
model.delete(eventTime__le=r['detail']['eventTime'])
except DeleteError as e:
log.warnin... | [
"def",
"capture_delete_records",
"(",
"records",
")",
":",
"for",
"r",
"in",
"records",
":",
"model",
"=",
"create_delete_model",
"(",
"r",
")",
"if",
"model",
":",
"try",
":",
"model",
".",
"delete",
"(",
"eventTime__le",
"=",
"r",
"[",
"'detail'",
"]",... | Writes all of our delete events to DynamoDB. | [
"Writes",
"all",
"of",
"our",
"delete",
"events",
"to",
"DynamoDB",
"."
] | train | https://github.com/Netflix-Skunkworks/historical/blob/c3ebaa8388a3fe67e23a6c9c6b04c3e618497c4a/historical/historical-cookiecutter/historical_{{cookiecutter.technology_slug}}/{{cookiecutter.technology_slug}}/collector.py#L135-L149 |
Netflix-Skunkworks/historical | historical/historical-cookiecutter/historical_{{cookiecutter.technology_slug}}/{{cookiecutter.technology_slug}}/collector.py | capture_update_records | def capture_update_records(records):
"""Writes all updated configuration info to DynamoDB"""
for record in records:
data = cloudwatch.get_historical_base_info(record)
items = describe_technology(record)
if len(items) > 1:
raise Exception('Multiple items found. Record: {recor... | python | def capture_update_records(records):
"""Writes all updated configuration info to DynamoDB"""
for record in records:
data = cloudwatch.get_historical_base_info(record)
items = describe_technology(record)
if len(items) > 1:
raise Exception('Multiple items found. Record: {recor... | [
"def",
"capture_update_records",
"(",
"records",
")",
":",
"for",
"record",
"in",
"records",
":",
"data",
"=",
"cloudwatch",
".",
"get_historical_base_info",
"(",
"record",
")",
"items",
"=",
"describe_technology",
"(",
"record",
")",
"if",
"len",
"(",
"items"... | Writes all updated configuration info to DynamoDB | [
"Writes",
"all",
"updated",
"configuration",
"info",
"to",
"DynamoDB"
] | train | https://github.com/Netflix-Skunkworks/historical/blob/c3ebaa8388a3fe67e23a6c9c6b04c3e618497c4a/historical/historical-cookiecutter/historical_{{cookiecutter.technology_slug}}/{{cookiecutter.technology_slug}}/collector.py#L152-L187 |
Netflix-Skunkworks/historical | historical/historical-cookiecutter/historical_{{cookiecutter.technology_slug}}/{{cookiecutter.technology_slug}}/collector.py | handler | def handler(event, context):
"""
Historical {{cookiecutter.technology_name}} event collector.
This collector is responsible for processing Cloudwatch events and polling events.
"""
records = deserialize_records(event['Records'])
# Split records into two groups, update and delete.
# We don't... | python | def handler(event, context):
"""
Historical {{cookiecutter.technology_name}} event collector.
This collector is responsible for processing Cloudwatch events and polling events.
"""
records = deserialize_records(event['Records'])
# Split records into two groups, update and delete.
# We don't... | [
"def",
"handler",
"(",
"event",
",",
"context",
")",
":",
"records",
"=",
"deserialize_records",
"(",
"event",
"[",
"'Records'",
"]",
")",
"# Split records into two groups, update and delete.",
"# We don't want to query for deleted records.",
"update_records",
",",
"delete_... | Historical {{cookiecutter.technology_name}} event collector.
This collector is responsible for processing Cloudwatch events and polling events. | [
"Historical",
"{{",
"cookiecutter",
".",
"technology_name",
"}}",
"event",
"collector",
".",
"This",
"collector",
"is",
"responsible",
"for",
"processing",
"Cloudwatch",
"events",
"and",
"polling",
"events",
"."
] | train | https://github.com/Netflix-Skunkworks/historical/blob/c3ebaa8388a3fe67e23a6c9c6b04c3e618497c4a/historical/historical-cookiecutter/historical_{{cookiecutter.technology_slug}}/{{cookiecutter.technology_slug}}/collector.py#L191-L209 |
Netflix-Skunkworks/historical | historical/security_group/collector.py | describe_group | def describe_group(record, region):
"""Attempts to describe group ids."""
account_id = record['account']
group_name = cloudwatch.filter_request_parameters('groupName', record)
vpc_id = cloudwatch.filter_request_parameters('vpcId', record)
group_id = cloudwatch.filter_request_parameters('groupId', r... | python | def describe_group(record, region):
"""Attempts to describe group ids."""
account_id = record['account']
group_name = cloudwatch.filter_request_parameters('groupName', record)
vpc_id = cloudwatch.filter_request_parameters('vpcId', record)
group_id = cloudwatch.filter_request_parameters('groupId', r... | [
"def",
"describe_group",
"(",
"record",
",",
"region",
")",
":",
"account_id",
"=",
"record",
"[",
"'account'",
"]",
"group_name",
"=",
"cloudwatch",
".",
"filter_request_parameters",
"(",
"'groupName'",
",",
"record",
")",
"vpc_id",
"=",
"cloudwatch",
".",
"f... | Attempts to describe group ids. | [
"Attempts",
"to",
"describe",
"group",
"ids",
"."
] | train | https://github.com/Netflix-Skunkworks/historical/blob/c3ebaa8388a3fe67e23a6c9c6b04c3e618497c4a/historical/security_group/collector.py#L47-L92 |
Netflix-Skunkworks/historical | historical/security_group/collector.py | create_delete_model | def create_delete_model(record):
"""Create a security group model from a record."""
data = cloudwatch.get_historical_base_info(record)
group_id = cloudwatch.filter_request_parameters('groupId', record)
# vpc_id = cloudwatch.filter_request_parameters('vpcId', record)
# group_name = cloudwatch.filter... | python | def create_delete_model(record):
"""Create a security group model from a record."""
data = cloudwatch.get_historical_base_info(record)
group_id = cloudwatch.filter_request_parameters('groupId', record)
# vpc_id = cloudwatch.filter_request_parameters('vpcId', record)
# group_name = cloudwatch.filter... | [
"def",
"create_delete_model",
"(",
"record",
")",
":",
"data",
"=",
"cloudwatch",
".",
"get_historical_base_info",
"(",
"record",
")",
"group_id",
"=",
"cloudwatch",
".",
"filter_request_parameters",
"(",
"'groupId'",
",",
"record",
")",
"# vpc_id = cloudwatch.filter_... | Create a security group model from a record. | [
"Create",
"a",
"security",
"group",
"model",
"from",
"a",
"record",
"."
] | train | https://github.com/Netflix-Skunkworks/historical/blob/c3ebaa8388a3fe67e23a6c9c6b04c3e618497c4a/historical/security_group/collector.py#L95-L119 |
Netflix-Skunkworks/historical | historical/security_group/collector.py | capture_delete_records | def capture_delete_records(records):
"""Writes all of our delete events to DynamoDB."""
for rec in records:
model = create_delete_model(rec)
if model:
try:
model.delete(condition=(CurrentSecurityGroupModel.eventTime <= rec['detail']['eventTime']))
except D... | python | def capture_delete_records(records):
"""Writes all of our delete events to DynamoDB."""
for rec in records:
model = create_delete_model(rec)
if model:
try:
model.delete(condition=(CurrentSecurityGroupModel.eventTime <= rec['detail']['eventTime']))
except D... | [
"def",
"capture_delete_records",
"(",
"records",
")",
":",
"for",
"rec",
"in",
"records",
":",
"model",
"=",
"create_delete_model",
"(",
"rec",
")",
"if",
"model",
":",
"try",
":",
"model",
".",
"delete",
"(",
"condition",
"=",
"(",
"CurrentSecurityGroupMode... | Writes all of our delete events to DynamoDB. | [
"Writes",
"all",
"of",
"our",
"delete",
"events",
"to",
"DynamoDB",
"."
] | train | https://github.com/Netflix-Skunkworks/historical/blob/c3ebaa8388a3fe67e23a6c9c6b04c3e618497c4a/historical/security_group/collector.py#L122-L132 |
Netflix-Skunkworks/historical | historical/security_group/collector.py | capture_update_records | def capture_update_records(records):
"""Writes all updated configuration info to DynamoDB"""
for rec in records:
data = cloudwatch.get_historical_base_info(rec)
group = describe_group(rec, cloudwatch.get_region(rec))
if len(group) > 1:
raise Exception(f'[X] Multiple groups f... | python | def capture_update_records(records):
"""Writes all updated configuration info to DynamoDB"""
for rec in records:
data = cloudwatch.get_historical_base_info(rec)
group = describe_group(rec, cloudwatch.get_region(rec))
if len(group) > 1:
raise Exception(f'[X] Multiple groups f... | [
"def",
"capture_update_records",
"(",
"records",
")",
":",
"for",
"rec",
"in",
"records",
":",
"data",
"=",
"cloudwatch",
".",
"get_historical_base_info",
"(",
"rec",
")",
"group",
"=",
"describe_group",
"(",
"rec",
",",
"cloudwatch",
".",
"get_region",
"(",
... | Writes all updated configuration info to DynamoDB | [
"Writes",
"all",
"updated",
"configuration",
"info",
"to",
"DynamoDB"
] | train | https://github.com/Netflix-Skunkworks/historical/blob/c3ebaa8388a3fe67e23a6c9c6b04c3e618497c4a/historical/security_group/collector.py#L135-L170 |
Netflix-Skunkworks/historical | historical/s3/models.py | S3PollingEventModel.serialize_me | def serialize_me(self, account, bucket_details):
"""Serializes the JSON for the Polling Event Model.
:param account:
:param bucket_details:
:return:
"""
return self.dumps({
"account": account,
"detail": {
"request_parameters": {
... | python | def serialize_me(self, account, bucket_details):
"""Serializes the JSON for the Polling Event Model.
:param account:
:param bucket_details:
:return:
"""
return self.dumps({
"account": account,
"detail": {
"request_parameters": {
... | [
"def",
"serialize_me",
"(",
"self",
",",
"account",
",",
"bucket_details",
")",
":",
"return",
"self",
".",
"dumps",
"(",
"{",
"\"account\"",
":",
"account",
",",
"\"detail\"",
":",
"{",
"\"request_parameters\"",
":",
"{",
"\"bucket_name\"",
":",
"bucket_detai... | Serializes the JSON for the Polling Event Model.
:param account:
:param bucket_details:
:return: | [
"Serializes",
"the",
"JSON",
"for",
"the",
"Polling",
"Event",
"Model",
"."
] | train | https://github.com/Netflix-Skunkworks/historical/blob/c3ebaa8388a3fe67e23a6c9c6b04c3e618497c4a/historical/s3/models.py#L94-L110 |
Netflix-Skunkworks/historical | historical/constants.py | extract_log_level_from_environment | def extract_log_level_from_environment(k, default):
"""Gets the log level from the environment variable."""
return LOG_LEVELS.get(os.environ.get(k)) or int(os.environ.get(k, default)) | python | def extract_log_level_from_environment(k, default):
"""Gets the log level from the environment variable."""
return LOG_LEVELS.get(os.environ.get(k)) or int(os.environ.get(k, default)) | [
"def",
"extract_log_level_from_environment",
"(",
"k",
",",
"default",
")",
":",
"return",
"LOG_LEVELS",
".",
"get",
"(",
"os",
".",
"environ",
".",
"get",
"(",
"k",
")",
")",
"or",
"int",
"(",
"os",
".",
"environ",
".",
"get",
"(",
"k",
",",
"defaul... | Gets the log level from the environment variable. | [
"Gets",
"the",
"log",
"level",
"from",
"the",
"environment",
"variable",
"."
] | train | https://github.com/Netflix-Skunkworks/historical/blob/c3ebaa8388a3fe67e23a6c9c6b04c3e618497c4a/historical/constants.py#L21-L23 |
Netflix-Skunkworks/historical | historical/common/cloudwatch.py | filter_request_parameters | def filter_request_parameters(field_name, msg, look_in_response=False):
"""
From an event, extract the field name from the message.
Different API calls put this information in different places, so check a few places.
"""
val = msg['detail'].get(field_name, None)
try:
if not val:
... | python | def filter_request_parameters(field_name, msg, look_in_response=False):
"""
From an event, extract the field name from the message.
Different API calls put this information in different places, so check a few places.
"""
val = msg['detail'].get(field_name, None)
try:
if not val:
... | [
"def",
"filter_request_parameters",
"(",
"field_name",
",",
"msg",
",",
"look_in_response",
"=",
"False",
")",
":",
"val",
"=",
"msg",
"[",
"'detail'",
"]",
".",
"get",
"(",
"field_name",
",",
"None",
")",
"try",
":",
"if",
"not",
"val",
":",
"val",
"=... | From an event, extract the field name from the message.
Different API calls put this information in different places, so check a few places. | [
"From",
"an",
"event",
"extract",
"the",
"field",
"name",
"from",
"the",
"message",
".",
"Different",
"API",
"calls",
"put",
"this",
"information",
"in",
"different",
"places",
"so",
"check",
"a",
"few",
"places",
"."
] | train | https://github.com/Netflix-Skunkworks/historical/blob/c3ebaa8388a3fe67e23a6c9c6b04c3e618497c4a/historical/common/cloudwatch.py#L14-L33 |
Netflix-Skunkworks/historical | historical/common/cloudwatch.py | get_historical_base_info | def get_historical_base_info(event):
"""Gets the base details from the CloudWatch Event."""
data = {
'principalId': get_principal(event),
'userIdentity': get_user_identity(event),
'accountId': event['account'],
'userAgent': event['detail'].get('userAgent'),
'sourceIpAddre... | python | def get_historical_base_info(event):
"""Gets the base details from the CloudWatch Event."""
data = {
'principalId': get_principal(event),
'userIdentity': get_user_identity(event),
'accountId': event['account'],
'userAgent': event['detail'].get('userAgent'),
'sourceIpAddre... | [
"def",
"get_historical_base_info",
"(",
"event",
")",
":",
"data",
"=",
"{",
"'principalId'",
":",
"get_principal",
"(",
"event",
")",
",",
"'userIdentity'",
":",
"get_user_identity",
"(",
"event",
")",
",",
"'accountId'",
":",
"event",
"[",
"'account'",
"]",
... | Gets the base details from the CloudWatch Event. | [
"Gets",
"the",
"base",
"details",
"from",
"the",
"CloudWatch",
"Event",
"."
] | train | https://github.com/Netflix-Skunkworks/historical/blob/c3ebaa8388a3fe67e23a6c9c6b04c3e618497c4a/historical/common/cloudwatch.py#L67-L87 |
desbma/GoogleSpeech | google_speech/__init__.py | Speech.findLastCharIndexMatching | def findLastCharIndexMatching(text, func):
""" Return index of last character in string for which func(char) evaluates to True. """
for i in range(len(text) - 1, -1, -1):
if func(text[i]):
return i | python | def findLastCharIndexMatching(text, func):
""" Return index of last character in string for which func(char) evaluates to True. """
for i in range(len(text) - 1, -1, -1):
if func(text[i]):
return i | [
"def",
"findLastCharIndexMatching",
"(",
"text",
",",
"func",
")",
":",
"for",
"i",
"in",
"range",
"(",
"len",
"(",
"text",
")",
"-",
"1",
",",
"-",
"1",
",",
"-",
"1",
")",
":",
"if",
"func",
"(",
"text",
"[",
"i",
"]",
")",
":",
"return",
"... | Return index of last character in string for which func(char) evaluates to True. | [
"Return",
"index",
"of",
"last",
"character",
"in",
"string",
"for",
"which",
"func",
"(",
"char",
")",
"evaluates",
"to",
"True",
"."
] | train | https://github.com/desbma/GoogleSpeech/blob/6d3ec62dc26400ccb4f2e77b8ccd4cb416141233/google_speech/__init__.py#L92-L96 |
desbma/GoogleSpeech | google_speech/__init__.py | Speech.splitText | def splitText(text):
""" Split text into sub segments of size not bigger than MAX_SEGMENT_SIZE. """
segments = []
remaining_text = __class__.cleanSpaces(text)
while len(remaining_text) > __class__.MAX_SEGMENT_SIZE:
cur_text = remaining_text[:__class__.MAX_SEGMENT_SIZE]
# try to split at pu... | python | def splitText(text):
""" Split text into sub segments of size not bigger than MAX_SEGMENT_SIZE. """
segments = []
remaining_text = __class__.cleanSpaces(text)
while len(remaining_text) > __class__.MAX_SEGMENT_SIZE:
cur_text = remaining_text[:__class__.MAX_SEGMENT_SIZE]
# try to split at pu... | [
"def",
"splitText",
"(",
"text",
")",
":",
"segments",
"=",
"[",
"]",
"remaining_text",
"=",
"__class__",
".",
"cleanSpaces",
"(",
"text",
")",
"while",
"len",
"(",
"remaining_text",
")",
">",
"__class__",
".",
"MAX_SEGMENT_SIZE",
":",
"cur_text",
"=",
"re... | Split text into sub segments of size not bigger than MAX_SEGMENT_SIZE. | [
"Split",
"text",
"into",
"sub",
"segments",
"of",
"size",
"not",
"bigger",
"than",
"MAX_SEGMENT_SIZE",
"."
] | train | https://github.com/desbma/GoogleSpeech/blob/6d3ec62dc26400ccb4f2e77b8ccd4cb416141233/google_speech/__init__.py#L99-L130 |
desbma/GoogleSpeech | google_speech/__init__.py | Speech.play | def play(self, sox_effects=()):
""" Play a speech. """
# build the segments
preloader_threads = []
if self.text != "-":
segments = list(self)
# start preloader thread(s)
preloader_threads = [PreloaderThread(name="PreloaderThread-%u" % (i)) for i in range(PRELOADER_THREAD_COUNT)]
... | python | def play(self, sox_effects=()):
""" Play a speech. """
# build the segments
preloader_threads = []
if self.text != "-":
segments = list(self)
# start preloader thread(s)
preloader_threads = [PreloaderThread(name="PreloaderThread-%u" % (i)) for i in range(PRELOADER_THREAD_COUNT)]
... | [
"def",
"play",
"(",
"self",
",",
"sox_effects",
"=",
"(",
")",
")",
":",
"# build the segments",
"preloader_threads",
"=",
"[",
"]",
"if",
"self",
".",
"text",
"!=",
"\"-\"",
":",
"segments",
"=",
"list",
"(",
"self",
")",
"# start preloader thread(s)",
"p... | Play a speech. | [
"Play",
"a",
"speech",
"."
] | train | https://github.com/desbma/GoogleSpeech/blob/6d3ec62dc26400ccb4f2e77b8ccd4cb416141233/google_speech/__init__.py#L138-L160 |
desbma/GoogleSpeech | google_speech/__init__.py | SpeechSegment.isInCache | def isInCache(self):
""" Return True if audio data for this segment is present in cache, False otherwise. """
url = self.buildUrl(cache_friendly=True)
return url in __class__.cache | python | def isInCache(self):
""" Return True if audio data for this segment is present in cache, False otherwise. """
url = self.buildUrl(cache_friendly=True)
return url in __class__.cache | [
"def",
"isInCache",
"(",
"self",
")",
":",
"url",
"=",
"self",
".",
"buildUrl",
"(",
"cache_friendly",
"=",
"True",
")",
"return",
"url",
"in",
"__class__",
".",
"cache"
] | Return True if audio data for this segment is present in cache, False otherwise. | [
"Return",
"True",
"if",
"audio",
"data",
"for",
"this",
"segment",
"is",
"present",
"in",
"cache",
"False",
"otherwise",
"."
] | train | https://github.com/desbma/GoogleSpeech/blob/6d3ec62dc26400ccb4f2e77b8ccd4cb416141233/google_speech/__init__.py#L207-L210 |
desbma/GoogleSpeech | google_speech/__init__.py | SpeechSegment.preLoad | def preLoad(self):
""" Store audio data in cache for fast playback. """
logging.getLogger().debug("Preloading segment '%s'" % (self))
real_url = self.buildUrl()
cache_url = self.buildUrl(cache_friendly=True)
audio_data = self.download(real_url)
assert(audio_data)
__class__.cache[cache_url] =... | python | def preLoad(self):
""" Store audio data in cache for fast playback. """
logging.getLogger().debug("Preloading segment '%s'" % (self))
real_url = self.buildUrl()
cache_url = self.buildUrl(cache_friendly=True)
audio_data = self.download(real_url)
assert(audio_data)
__class__.cache[cache_url] =... | [
"def",
"preLoad",
"(",
"self",
")",
":",
"logging",
".",
"getLogger",
"(",
")",
".",
"debug",
"(",
"\"Preloading segment '%s'\"",
"%",
"(",
"self",
")",
")",
"real_url",
"=",
"self",
".",
"buildUrl",
"(",
")",
"cache_url",
"=",
"self",
".",
"buildUrl",
... | Store audio data in cache for fast playback. | [
"Store",
"audio",
"data",
"in",
"cache",
"for",
"fast",
"playback",
"."
] | train | https://github.com/desbma/GoogleSpeech/blob/6d3ec62dc26400ccb4f2e77b8ccd4cb416141233/google_speech/__init__.py#L212-L219 |
desbma/GoogleSpeech | google_speech/__init__.py | SpeechSegment.getAudioData | def getAudioData(self):
""" Fetch the audio data. """
with self.preload_mutex:
cache_url = self.buildUrl(cache_friendly=True)
if cache_url in __class__.cache:
logging.getLogger().debug("Got data for URL '%s' from cache" % (cache_url))
audio_data = __class__.cache[cache_url]
a... | python | def getAudioData(self):
""" Fetch the audio data. """
with self.preload_mutex:
cache_url = self.buildUrl(cache_friendly=True)
if cache_url in __class__.cache:
logging.getLogger().debug("Got data for URL '%s' from cache" % (cache_url))
audio_data = __class__.cache[cache_url]
a... | [
"def",
"getAudioData",
"(",
"self",
")",
":",
"with",
"self",
".",
"preload_mutex",
":",
"cache_url",
"=",
"self",
".",
"buildUrl",
"(",
"cache_friendly",
"=",
"True",
")",
"if",
"cache_url",
"in",
"__class__",
".",
"cache",
":",
"logging",
".",
"getLogger... | Fetch the audio data. | [
"Fetch",
"the",
"audio",
"data",
"."
] | train | https://github.com/desbma/GoogleSpeech/blob/6d3ec62dc26400ccb4f2e77b8ccd4cb416141233/google_speech/__init__.py#L221-L234 |
desbma/GoogleSpeech | google_speech/__init__.py | SpeechSegment.play | def play(self, sox_effects=()):
""" Play the segment. """
audio_data = self.getAudioData()
logging.getLogger().info("Playing speech segment (%s): '%s'" % (self.lang, self))
cmd = ["sox", "-q", "-t", "mp3", "-"]
if sys.platform.startswith("win32"):
cmd.extend(("-t", "waveaudio"))
cmd.extend... | python | def play(self, sox_effects=()):
""" Play the segment. """
audio_data = self.getAudioData()
logging.getLogger().info("Playing speech segment (%s): '%s'" % (self.lang, self))
cmd = ["sox", "-q", "-t", "mp3", "-"]
if sys.platform.startswith("win32"):
cmd.extend(("-t", "waveaudio"))
cmd.extend... | [
"def",
"play",
"(",
"self",
",",
"sox_effects",
"=",
"(",
")",
")",
":",
"audio_data",
"=",
"self",
".",
"getAudioData",
"(",
")",
"logging",
".",
"getLogger",
"(",
")",
".",
"info",
"(",
"\"Playing speech segment (%s): '%s'\"",
"%",
"(",
"self",
".",
"l... | Play the segment. | [
"Play",
"the",
"segment",
"."
] | train | https://github.com/desbma/GoogleSpeech/blob/6d3ec62dc26400ccb4f2e77b8ccd4cb416141233/google_speech/__init__.py#L236-L252 |
desbma/GoogleSpeech | google_speech/__init__.py | SpeechSegment.buildUrl | def buildUrl(self, cache_friendly=False):
"""
Construct the URL to get the sound from Goggle API.
If cache_friendly is True, remove token from URL to use as a cache key.
"""
params = collections.OrderedDict()
params["client"] = "tw-ob"
params["ie"] = "UTF-8"
params["idx"] = str(self.seg... | python | def buildUrl(self, cache_friendly=False):
"""
Construct the URL to get the sound from Goggle API.
If cache_friendly is True, remove token from URL to use as a cache key.
"""
params = collections.OrderedDict()
params["client"] = "tw-ob"
params["ie"] = "UTF-8"
params["idx"] = str(self.seg... | [
"def",
"buildUrl",
"(",
"self",
",",
"cache_friendly",
"=",
"False",
")",
":",
"params",
"=",
"collections",
".",
"OrderedDict",
"(",
")",
"params",
"[",
"\"client\"",
"]",
"=",
"\"tw-ob\"",
"params",
"[",
"\"ie\"",
"]",
"=",
"\"UTF-8\"",
"params",
"[",
... | Construct the URL to get the sound from Goggle API.
If cache_friendly is True, remove token from URL to use as a cache key. | [
"Construct",
"the",
"URL",
"to",
"get",
"the",
"sound",
"from",
"Goggle",
"API",
"."
] | train | https://github.com/desbma/GoogleSpeech/blob/6d3ec62dc26400ccb4f2e77b8ccd4cb416141233/google_speech/__init__.py#L254-L270 |
desbma/GoogleSpeech | google_speech/__init__.py | SpeechSegment.download | def download(self, url):
""" Download a sound file. """
logging.getLogger().debug("Downloading '%s'..." % (url))
response = __class__.session.get(url,
headers={"User-Agent": "Mozilla/5.0"},
timeout=3.1)
response.raise_for_status()... | python | def download(self, url):
""" Download a sound file. """
logging.getLogger().debug("Downloading '%s'..." % (url))
response = __class__.session.get(url,
headers={"User-Agent": "Mozilla/5.0"},
timeout=3.1)
response.raise_for_status()... | [
"def",
"download",
"(",
"self",
",",
"url",
")",
":",
"logging",
".",
"getLogger",
"(",
")",
".",
"debug",
"(",
"\"Downloading '%s'...\"",
"%",
"(",
"url",
")",
")",
"response",
"=",
"__class__",
".",
"session",
".",
"get",
"(",
"url",
",",
"headers",
... | Download a sound file. | [
"Download",
"a",
"sound",
"file",
"."
] | train | https://github.com/desbma/GoogleSpeech/blob/6d3ec62dc26400ccb4f2e77b8ccd4cb416141233/google_speech/__init__.py#L272-L279 |
gtalarico/airtable-python-wrapper | airtable/params.py | _BaseObjectArrayParam.to_param_dict | def to_param_dict(self):
""" Sorts to ensure Order is consistent for Testing """
param_dict = {}
for index, dictionary in enumerate(self.value):
for key, value in dictionary.items():
param_name = '{param_name}[{index}][{key}]'.format(
... | python | def to_param_dict(self):
""" Sorts to ensure Order is consistent for Testing """
param_dict = {}
for index, dictionary in enumerate(self.value):
for key, value in dictionary.items():
param_name = '{param_name}[{index}][{key}]'.format(
... | [
"def",
"to_param_dict",
"(",
"self",
")",
":",
"param_dict",
"=",
"{",
"}",
"for",
"index",
",",
"dictionary",
"in",
"enumerate",
"(",
"self",
".",
"value",
")",
":",
"for",
"key",
",",
"value",
"in",
"dictionary",
".",
"items",
"(",
")",
":",
"param... | Sorts to ensure Order is consistent for Testing | [
"Sorts",
"to",
"ensure",
"Order",
"is",
"consistent",
"for",
"Testing"
] | train | https://github.com/gtalarico/airtable-python-wrapper/blob/48b2d806178085b52a31817571e5a1fc3dce4045/airtable/params.py#L68-L78 |
gtalarico/airtable-python-wrapper | airtable/params.py | AirtableParams._discover_params | def _discover_params(cls):
"""
Returns a dict where filter keyword is key, and class is value.
To handle param alias (maxRecords or max_records), both versions are
added.
"""
try:
return cls.filters
except AttributeError:
filters... | python | def _discover_params(cls):
"""
Returns a dict where filter keyword is key, and class is value.
To handle param alias (maxRecords or max_records), both versions are
added.
"""
try:
return cls.filters
except AttributeError:
filters... | [
"def",
"_discover_params",
"(",
"cls",
")",
":",
"try",
":",
"return",
"cls",
".",
"filters",
"except",
"AttributeError",
":",
"filters",
"=",
"{",
"}",
"for",
"param_class_name",
"in",
"dir",
"(",
"cls",
")",
":",
"param_class",
"=",
"getattr",
"(",
"cl... | Returns a dict where filter keyword is key, and class is value.
To handle param alias (maxRecords or max_records), both versions are
added. | [
"Returns",
"a",
"dict",
"where",
"filter",
"keyword",
"is",
"key",
"and",
"class",
"is",
"value",
".",
"To",
"handle",
"param",
"alias",
"(",
"maxRecords",
"or",
"max_records",
")",
"both",
"versions",
"are",
"added",
"."
] | train | https://github.com/gtalarico/airtable-python-wrapper/blob/48b2d806178085b52a31817571e5a1fc3dce4045/airtable/params.py#L342-L359 |
gtalarico/airtable-python-wrapper | airtable/params.py | AirtableParams._get | def _get(cls, kwarg_name):
""" Returns a Param Class Instance, by its kwarg or param name """
param_classes = cls._discover_params()
try:
param_class = param_classes[kwarg_name]
except KeyError:
raise ValueError('invalid param keyword {}'.format(kwarg_name))... | python | def _get(cls, kwarg_name):
""" Returns a Param Class Instance, by its kwarg or param name """
param_classes = cls._discover_params()
try:
param_class = param_classes[kwarg_name]
except KeyError:
raise ValueError('invalid param keyword {}'.format(kwarg_name))... | [
"def",
"_get",
"(",
"cls",
",",
"kwarg_name",
")",
":",
"param_classes",
"=",
"cls",
".",
"_discover_params",
"(",
")",
"try",
":",
"param_class",
"=",
"param_classes",
"[",
"kwarg_name",
"]",
"except",
"KeyError",
":",
"raise",
"ValueError",
"(",
"'invalid ... | Returns a Param Class Instance, by its kwarg or param name | [
"Returns",
"a",
"Param",
"Class",
"Instance",
"by",
"its",
"kwarg",
"or",
"param",
"name"
] | train | https://github.com/gtalarico/airtable-python-wrapper/blob/48b2d806178085b52a31817571e5a1fc3dce4045/airtable/params.py#L362-L370 |
gtalarico/airtable-python-wrapper | airtable/airtable.py | Airtable._process_params | def _process_params(self, params):
"""
Process params names or values as needed using filters
"""
new_params = OrderedDict()
for param_name, param_value in sorted(params.items()):
param_value = params[param_name]
ParamClass = AirtableParams._get(par... | python | def _process_params(self, params):
"""
Process params names or values as needed using filters
"""
new_params = OrderedDict()
for param_name, param_value in sorted(params.items()):
param_value = params[param_name]
ParamClass = AirtableParams._get(par... | [
"def",
"_process_params",
"(",
"self",
",",
"params",
")",
":",
"new_params",
"=",
"OrderedDict",
"(",
")",
"for",
"param_name",
",",
"param_value",
"in",
"sorted",
"(",
"params",
".",
"items",
"(",
")",
")",
":",
"param_value",
"=",
"params",
"[",
"para... | Process params names or values as needed using filters | [
"Process",
"params",
"names",
"or",
"values",
"as",
"needed",
"using",
"filters"
] | train | https://github.com/gtalarico/airtable-python-wrapper/blob/48b2d806178085b52a31817571e5a1fc3dce4045/airtable/airtable.py#L141-L150 |
gtalarico/airtable-python-wrapper | airtable/airtable.py | Airtable.get | def get(self, record_id):
"""
Retrieves a record by its id
>>> record = airtable.get('recwPQIfs4wKPyc9D')
Args:
record_id(``str``): Airtable record id
Returns:
record (``dict``): Record
"""
record_url = self.record_url(record... | python | def get(self, record_id):
"""
Retrieves a record by its id
>>> record = airtable.get('recwPQIfs4wKPyc9D')
Args:
record_id(``str``): Airtable record id
Returns:
record (``dict``): Record
"""
record_url = self.record_url(record... | [
"def",
"get",
"(",
"self",
",",
"record_id",
")",
":",
"record_url",
"=",
"self",
".",
"record_url",
"(",
"record_id",
")",
"return",
"self",
".",
"_get",
"(",
"record_url",
")"
] | Retrieves a record by its id
>>> record = airtable.get('recwPQIfs4wKPyc9D')
Args:
record_id(``str``): Airtable record id
Returns:
record (``dict``): Record | [
"Retrieves",
"a",
"record",
"by",
"its",
"id",
">>>",
"record",
"=",
"airtable",
".",
"get",
"(",
"recwPQIfs4wKPyc9D",
")",
"Args",
":",
"record_id",
"(",
"str",
")",
":",
"Airtable",
"record",
"id",
"Returns",
":",
"record",
"(",
"dict",
")",
":",
"Re... | train | https://github.com/gtalarico/airtable-python-wrapper/blob/48b2d806178085b52a31817571e5a1fc3dce4045/airtable/airtable.py#L202-L215 |
gtalarico/airtable-python-wrapper | airtable/airtable.py | Airtable.get_iter | def get_iter(self, **options):
"""
Record Retriever Iterator
Returns iterator with lists in batches according to pageSize.
To get all records at once use :any:`get_all`
>>> for page in airtable.get_iter():
... for record in page:
... print(r... | python | def get_iter(self, **options):
"""
Record Retriever Iterator
Returns iterator with lists in batches according to pageSize.
To get all records at once use :any:`get_all`
>>> for page in airtable.get_iter():
... for record in page:
... print(r... | [
"def",
"get_iter",
"(",
"self",
",",
"*",
"*",
"options",
")",
":",
"offset",
"=",
"None",
"while",
"True",
":",
"data",
"=",
"self",
".",
"_get",
"(",
"self",
".",
"url_table",
",",
"offset",
"=",
"offset",
",",
"*",
"*",
"options",
")",
"records"... | Record Retriever Iterator
Returns iterator with lists in batches according to pageSize.
To get all records at once use :any:`get_all`
>>> for page in airtable.get_iter():
... for record in page:
... print(record)
[{'fields': ... }, ...]
Ke... | [
"Record",
"Retriever",
"Iterator",
"Returns",
"iterator",
"with",
"lists",
"in",
"batches",
"according",
"to",
"pageSize",
".",
"To",
"get",
"all",
"records",
"at",
"once",
"use",
":",
"any",
":",
"get_all",
">>>",
"for",
"page",
"in",
"airtable",
".",
"ge... | train | https://github.com/gtalarico/airtable-python-wrapper/blob/48b2d806178085b52a31817571e5a1fc3dce4045/airtable/airtable.py#L217-L256 |
gtalarico/airtable-python-wrapper | airtable/airtable.py | Airtable.get_all | def get_all(self, **options):
"""
Retrieves all records repetitively and returns a single list.
>>> airtable.get_all()
>>> airtable.get_all(view='MyView', fields=['ColA', '-ColB'])
>>> airtable.get_all(maxRecords=50)
[{'fields': ... }, ...]
Keyword Args... | python | def get_all(self, **options):
"""
Retrieves all records repetitively and returns a single list.
>>> airtable.get_all()
>>> airtable.get_all(view='MyView', fields=['ColA', '-ColB'])
>>> airtable.get_all(maxRecords=50)
[{'fields': ... }, ...]
Keyword Args... | [
"def",
"get_all",
"(",
"self",
",",
"*",
"*",
"options",
")",
":",
"all_records",
"=",
"[",
"]",
"for",
"records",
"in",
"self",
".",
"get_iter",
"(",
"*",
"*",
"options",
")",
":",
"all_records",
".",
"extend",
"(",
"records",
")",
"return",
"all_re... | Retrieves all records repetitively and returns a single list.
>>> airtable.get_all()
>>> airtable.get_all(view='MyView', fields=['ColA', '-ColB'])
>>> airtable.get_all(maxRecords=50)
[{'fields': ... }, ...]
Keyword Args:
max_records (``int``, optional): The ... | [
"Retrieves",
"all",
"records",
"repetitively",
"and",
"returns",
"a",
"single",
"list",
".",
">>>",
"airtable",
".",
"get_all",
"()",
">>>",
"airtable",
".",
"get_all",
"(",
"view",
"=",
"MyView",
"fields",
"=",
"[",
"ColA",
"-",
"ColB",
"]",
")",
">>>",... | train | https://github.com/gtalarico/airtable-python-wrapper/blob/48b2d806178085b52a31817571e5a1fc3dce4045/airtable/airtable.py#L258-L288 |
gtalarico/airtable-python-wrapper | airtable/airtable.py | Airtable.match | def match(self, field_name, field_value, **options):
"""
Returns first match found in :any:`get_all`
>>> airtable.match('Name', 'John')
{'fields': {'Name': 'John'} }
Args:
field_name (``str``): Name of field to match (column name).
field_value (... | python | def match(self, field_name, field_value, **options):
"""
Returns first match found in :any:`get_all`
>>> airtable.match('Name', 'John')
{'fields': {'Name': 'John'} }
Args:
field_name (``str``): Name of field to match (column name).
field_value (... | [
"def",
"match",
"(",
"self",
",",
"field_name",
",",
"field_value",
",",
"*",
"*",
"options",
")",
":",
"from_name_and_value",
"=",
"AirtableParams",
".",
"FormulaParam",
".",
"from_name_and_value",
"formula",
"=",
"from_name_and_value",
"(",
"field_name",
",",
... | Returns first match found in :any:`get_all`
>>> airtable.match('Name', 'John')
{'fields': {'Name': 'John'} }
Args:
field_name (``str``): Name of field to match (column name).
field_value (``str``): Value of field to match.
Keyword Args:
ma... | [
"Returns",
"first",
"match",
"found",
"in",
":",
"any",
":",
"get_all",
">>>",
"airtable",
".",
"match",
"(",
"Name",
"John",
")",
"{",
"fields",
":",
"{",
"Name",
":",
"John",
"}",
"}",
"Args",
":",
"field_name",
"(",
"str",
")",
":",
"Name",
"of"... | train | https://github.com/gtalarico/airtable-python-wrapper/blob/48b2d806178085b52a31817571e5a1fc3dce4045/airtable/airtable.py#L290-L320 |
gtalarico/airtable-python-wrapper | airtable/airtable.py | Airtable.search | def search(self, field_name, field_value, record=None, **options):
"""
Returns all matching records found in :any:`get_all`
>>> airtable.search('Gender', 'Male')
[{'fields': {'Name': 'John', 'Gender': 'Male'}, ... ]
Args:
field_name (``str``): Name of field ... | python | def search(self, field_name, field_value, record=None, **options):
"""
Returns all matching records found in :any:`get_all`
>>> airtable.search('Gender', 'Male')
[{'fields': {'Name': 'John', 'Gender': 'Male'}, ... ]
Args:
field_name (``str``): Name of field ... | [
"def",
"search",
"(",
"self",
",",
"field_name",
",",
"field_value",
",",
"record",
"=",
"None",
",",
"*",
"*",
"options",
")",
":",
"records",
"=",
"[",
"]",
"from_name_and_value",
"=",
"AirtableParams",
".",
"FormulaParam",
".",
"from_name_and_value",
"for... | Returns all matching records found in :any:`get_all`
>>> airtable.search('Gender', 'Male')
[{'fields': {'Name': 'John', 'Gender': 'Male'}, ... ]
Args:
field_name (``str``): Name of field to match (column name).
field_value (``str``): Value of field to match.
... | [
"Returns",
"all",
"matching",
"records",
"found",
"in",
":",
"any",
":",
"get_all",
">>>",
"airtable",
".",
"search",
"(",
"Gender",
"Male",
")",
"[",
"{",
"fields",
":",
"{",
"Name",
":",
"John",
"Gender",
":",
"Male",
"}",
"...",
"]",
"Args",
":",
... | train | https://github.com/gtalarico/airtable-python-wrapper/blob/48b2d806178085b52a31817571e5a1fc3dce4045/airtable/airtable.py#L322-L352 |
gtalarico/airtable-python-wrapper | airtable/airtable.py | Airtable.insert | def insert(self, fields, typecast=False):
"""
Inserts a record
>>> record = {'Name': 'John'}
>>> airtable.insert(record)
Args:
fields(``dict``): Fields to insert.
Must be dictionary with Column names as Key.
typecast(``boolean``... | python | def insert(self, fields, typecast=False):
"""
Inserts a record
>>> record = {'Name': 'John'}
>>> airtable.insert(record)
Args:
fields(``dict``): Fields to insert.
Must be dictionary with Column names as Key.
typecast(``boolean``... | [
"def",
"insert",
"(",
"self",
",",
"fields",
",",
"typecast",
"=",
"False",
")",
":",
"return",
"self",
".",
"_post",
"(",
"self",
".",
"url_table",
",",
"json_data",
"=",
"{",
"\"fields\"",
":",
"fields",
",",
"\"typecast\"",
":",
"typecast",
"}",
")"... | Inserts a record
>>> record = {'Name': 'John'}
>>> airtable.insert(record)
Args:
fields(``dict``): Fields to insert.
Must be dictionary with Column names as Key.
typecast(``boolean``): Automatic data conversion from string values.
Retu... | [
"Inserts",
"a",
"record",
">>>",
"record",
"=",
"{",
"Name",
":",
"John",
"}",
">>>",
"airtable",
".",
"insert",
"(",
"record",
")",
"Args",
":",
"fields",
"(",
"dict",
")",
":",
"Fields",
"to",
"insert",
".",
"Must",
"be",
"dictionary",
"with",
"Col... | train | https://github.com/gtalarico/airtable-python-wrapper/blob/48b2d806178085b52a31817571e5a1fc3dce4045/airtable/airtable.py#L354-L370 |
gtalarico/airtable-python-wrapper | airtable/airtable.py | Airtable._batch_request | def _batch_request(self, func, iterable):
""" Internal Function to limit batch calls to API limit """
responses = []
for item in iterable:
responses.append(func(item))
time.sleep(self.API_LIMIT)
return responses | python | def _batch_request(self, func, iterable):
""" Internal Function to limit batch calls to API limit """
responses = []
for item in iterable:
responses.append(func(item))
time.sleep(self.API_LIMIT)
return responses | [
"def",
"_batch_request",
"(",
"self",
",",
"func",
",",
"iterable",
")",
":",
"responses",
"=",
"[",
"]",
"for",
"item",
"in",
"iterable",
":",
"responses",
".",
"append",
"(",
"func",
"(",
"item",
")",
")",
"time",
".",
"sleep",
"(",
"self",
".",
... | Internal Function to limit batch calls to API limit | [
"Internal",
"Function",
"to",
"limit",
"batch",
"calls",
"to",
"API",
"limit"
] | train | https://github.com/gtalarico/airtable-python-wrapper/blob/48b2d806178085b52a31817571e5a1fc3dce4045/airtable/airtable.py#L372-L378 |
gtalarico/airtable-python-wrapper | airtable/airtable.py | Airtable.batch_insert | def batch_insert(self, records, typecast=False):
"""
Calls :any:`insert` repetitively, following set API Rate Limit (5/sec)
To change the rate limit use ``airtable.API_LIMIT = 0.2``
(5 per second)
>>> records = [{'Name': 'John'}, {'Name': 'Marc'}]
>>> airtable.bat... | python | def batch_insert(self, records, typecast=False):
"""
Calls :any:`insert` repetitively, following set API Rate Limit (5/sec)
To change the rate limit use ``airtable.API_LIMIT = 0.2``
(5 per second)
>>> records = [{'Name': 'John'}, {'Name': 'Marc'}]
>>> airtable.bat... | [
"def",
"batch_insert",
"(",
"self",
",",
"records",
",",
"typecast",
"=",
"False",
")",
":",
"return",
"self",
".",
"_batch_request",
"(",
"self",
".",
"insert",
",",
"records",
")"
] | Calls :any:`insert` repetitively, following set API Rate Limit (5/sec)
To change the rate limit use ``airtable.API_LIMIT = 0.2``
(5 per second)
>>> records = [{'Name': 'John'}, {'Name': 'Marc'}]
>>> airtable.batch_insert(records)
Args:
records(``list``): Rec... | [
"Calls",
":",
"any",
":",
"insert",
"repetitively",
"following",
"set",
"API",
"Rate",
"Limit",
"(",
"5",
"/",
"sec",
")",
"To",
"change",
"the",
"rate",
"limit",
"use",
"airtable",
".",
"API_LIMIT",
"=",
"0",
".",
"2",
"(",
"5",
"per",
"second",
")"... | train | https://github.com/gtalarico/airtable-python-wrapper/blob/48b2d806178085b52a31817571e5a1fc3dce4045/airtable/airtable.py#L380-L397 |
gtalarico/airtable-python-wrapper | airtable/airtable.py | Airtable.update | def update(self, record_id, fields, typecast=False):
"""
Updates a record by its record id.
Only Fields passed are updated, the rest are left as is.
>>> record = airtable.match('Employee Id', 'DD13332454')
>>> fields = {'Status': 'Fired'}
>>> airtable.update(recor... | python | def update(self, record_id, fields, typecast=False):
"""
Updates a record by its record id.
Only Fields passed are updated, the rest are left as is.
>>> record = airtable.match('Employee Id', 'DD13332454')
>>> fields = {'Status': 'Fired'}
>>> airtable.update(recor... | [
"def",
"update",
"(",
"self",
",",
"record_id",
",",
"fields",
",",
"typecast",
"=",
"False",
")",
":",
"record_url",
"=",
"self",
".",
"record_url",
"(",
"record_id",
")",
"return",
"self",
".",
"_patch",
"(",
"record_url",
",",
"json_data",
"=",
"{",
... | Updates a record by its record id.
Only Fields passed are updated, the rest are left as is.
>>> record = airtable.match('Employee Id', 'DD13332454')
>>> fields = {'Status': 'Fired'}
>>> airtable.update(record['id'], fields)
Args:
record_id(``str``): Id of Re... | [
"Updates",
"a",
"record",
"by",
"its",
"record",
"id",
".",
"Only",
"Fields",
"passed",
"are",
"updated",
"the",
"rest",
"are",
"left",
"as",
"is",
".",
">>>",
"record",
"=",
"airtable",
".",
"match",
"(",
"Employee",
"Id",
"DD13332454",
")",
">>>",
"f... | train | https://github.com/gtalarico/airtable-python-wrapper/blob/48b2d806178085b52a31817571e5a1fc3dce4045/airtable/airtable.py#L399-L418 |
gtalarico/airtable-python-wrapper | airtable/airtable.py | Airtable.update_by_field | def update_by_field(self, field_name, field_value, fields, typecast=False, **options):
"""
Updates the first record to match field name and value.
Only Fields passed are updated, the rest are left as is.
>>> record = {'Name': 'John', 'Tel': '540-255-5522'}
>>> airtable.upd... | python | def update_by_field(self, field_name, field_value, fields, typecast=False, **options):
"""
Updates the first record to match field name and value.
Only Fields passed are updated, the rest are left as is.
>>> record = {'Name': 'John', 'Tel': '540-255-5522'}
>>> airtable.upd... | [
"def",
"update_by_field",
"(",
"self",
",",
"field_name",
",",
"field_value",
",",
"fields",
",",
"typecast",
"=",
"False",
",",
"*",
"*",
"options",
")",
":",
"record",
"=",
"self",
".",
"match",
"(",
"field_name",
",",
"field_value",
",",
"*",
"*",
"... | Updates the first record to match field name and value.
Only Fields passed are updated, the rest are left as is.
>>> record = {'Name': 'John', 'Tel': '540-255-5522'}
>>> airtable.update_by_field('Name', 'John', record)
Args:
field_name (``str``): Name of field to mat... | [
"Updates",
"the",
"first",
"record",
"to",
"match",
"field",
"name",
"and",
"value",
".",
"Only",
"Fields",
"passed",
"are",
"updated",
"the",
"rest",
"are",
"left",
"as",
"is",
".",
">>>",
"record",
"=",
"{",
"Name",
":",
"John",
"Tel",
":",
"540",
... | train | https://github.com/gtalarico/airtable-python-wrapper/blob/48b2d806178085b52a31817571e5a1fc3dce4045/airtable/airtable.py#L420-L445 |
gtalarico/airtable-python-wrapper | airtable/airtable.py | Airtable.replace | def replace(self, record_id, fields, typecast=False):
"""
Replaces a record by its record id.
All Fields are updated to match the new ``fields`` provided.
If a field is not included in ``fields``, value will bet set to null.
To update only selected fields, use :any:`update`.... | python | def replace(self, record_id, fields, typecast=False):
"""
Replaces a record by its record id.
All Fields are updated to match the new ``fields`` provided.
If a field is not included in ``fields``, value will bet set to null.
To update only selected fields, use :any:`update`.... | [
"def",
"replace",
"(",
"self",
",",
"record_id",
",",
"fields",
",",
"typecast",
"=",
"False",
")",
":",
"record_url",
"=",
"self",
".",
"record_url",
"(",
"record_id",
")",
"return",
"self",
".",
"_put",
"(",
"record_url",
",",
"json_data",
"=",
"{",
... | Replaces a record by its record id.
All Fields are updated to match the new ``fields`` provided.
If a field is not included in ``fields``, value will bet set to null.
To update only selected fields, use :any:`update`.
>>> record = airtable.match('Seat Number', '22A')
>>> f... | [
"Replaces",
"a",
"record",
"by",
"its",
"record",
"id",
".",
"All",
"Fields",
"are",
"updated",
"to",
"match",
"the",
"new",
"fields",
"provided",
".",
"If",
"a",
"field",
"is",
"not",
"included",
"in",
"fields",
"value",
"will",
"bet",
"set",
"to",
"n... | train | https://github.com/gtalarico/airtable-python-wrapper/blob/48b2d806178085b52a31817571e5a1fc3dce4045/airtable/airtable.py#L447-L468 |
gtalarico/airtable-python-wrapper | airtable/airtable.py | Airtable.replace_by_field | def replace_by_field(self, field_name, field_value, fields, typecast=False, **options):
"""
Replaces the first record to match field name and value.
All Fields are updated to match the new ``fields`` provided.
If a field is not included in ``fields``, value will bet set to null.
... | python | def replace_by_field(self, field_name, field_value, fields, typecast=False, **options):
"""
Replaces the first record to match field name and value.
All Fields are updated to match the new ``fields`` provided.
If a field is not included in ``fields``, value will bet set to null.
... | [
"def",
"replace_by_field",
"(",
"self",
",",
"field_name",
",",
"field_value",
",",
"fields",
",",
"typecast",
"=",
"False",
",",
"*",
"*",
"options",
")",
":",
"record",
"=",
"self",
".",
"match",
"(",
"field_name",
",",
"field_value",
",",
"*",
"*",
... | Replaces the first record to match field name and value.
All Fields are updated to match the new ``fields`` provided.
If a field is not included in ``fields``, value will bet set to null.
To update only selected fields, use :any:`update`.
Args:
field_name (``str``): Na... | [
"Replaces",
"the",
"first",
"record",
"to",
"match",
"field",
"name",
"and",
"value",
".",
"All",
"Fields",
"are",
"updated",
"to",
"match",
"the",
"new",
"fields",
"provided",
".",
"If",
"a",
"field",
"is",
"not",
"included",
"in",
"fields",
"value",
"w... | train | https://github.com/gtalarico/airtable-python-wrapper/blob/48b2d806178085b52a31817571e5a1fc3dce4045/airtable/airtable.py#L470-L494 |
gtalarico/airtable-python-wrapper | airtable/airtable.py | Airtable.delete | def delete(self, record_id):
"""
Deletes a record by its id
>>> record = airtable.match('Employee Id', 'DD13332454')
>>> airtable.delete(record['id'])
Args:
record_id(``str``): Airtable record id
Returns:
record (``dict``): Deleted Re... | python | def delete(self, record_id):
"""
Deletes a record by its id
>>> record = airtable.match('Employee Id', 'DD13332454')
>>> airtable.delete(record['id'])
Args:
record_id(``str``): Airtable record id
Returns:
record (``dict``): Deleted Re... | [
"def",
"delete",
"(",
"self",
",",
"record_id",
")",
":",
"record_url",
"=",
"self",
".",
"record_url",
"(",
"record_id",
")",
"return",
"self",
".",
"_delete",
"(",
"record_url",
")"
] | Deletes a record by its id
>>> record = airtable.match('Employee Id', 'DD13332454')
>>> airtable.delete(record['id'])
Args:
record_id(``str``): Airtable record id
Returns:
record (``dict``): Deleted Record | [
"Deletes",
"a",
"record",
"by",
"its",
"id",
">>>",
"record",
"=",
"airtable",
".",
"match",
"(",
"Employee",
"Id",
"DD13332454",
")",
">>>",
"airtable",
".",
"delete",
"(",
"record",
"[",
"id",
"]",
")",
"Args",
":",
"record_id",
"(",
"str",
")",
":... | train | https://github.com/gtalarico/airtable-python-wrapper/blob/48b2d806178085b52a31817571e5a1fc3dce4045/airtable/airtable.py#L496-L510 |
gtalarico/airtable-python-wrapper | airtable/airtable.py | Airtable.delete_by_field | def delete_by_field(self, field_name, field_value, **options):
"""
Deletes first record to match provided ``field_name`` and
``field_value``.
>>> record = airtable.delete_by_field('Employee Id', 'DD13332454')
Args:
field_name (``str``): Name of field to mat... | python | def delete_by_field(self, field_name, field_value, **options):
"""
Deletes first record to match provided ``field_name`` and
``field_value``.
>>> record = airtable.delete_by_field('Employee Id', 'DD13332454')
Args:
field_name (``str``): Name of field to mat... | [
"def",
"delete_by_field",
"(",
"self",
",",
"field_name",
",",
"field_value",
",",
"*",
"*",
"options",
")",
":",
"record",
"=",
"self",
".",
"match",
"(",
"field_name",
",",
"field_value",
",",
"*",
"*",
"options",
")",
"record_url",
"=",
"self",
".",
... | Deletes first record to match provided ``field_name`` and
``field_value``.
>>> record = airtable.delete_by_field('Employee Id', 'DD13332454')
Args:
field_name (``str``): Name of field to match (column name).
field_value (``str``): Value of field to match.
... | [
"Deletes",
"first",
"record",
"to",
"match",
"provided",
"field_name",
"and",
"field_value",
".",
">>>",
"record",
"=",
"airtable",
".",
"delete_by_field",
"(",
"Employee",
"Id",
"DD13332454",
")",
"Args",
":",
"field_name",
"(",
"str",
")",
":",
"Name",
"of... | train | https://github.com/gtalarico/airtable-python-wrapper/blob/48b2d806178085b52a31817571e5a1fc3dce4045/airtable/airtable.py#L512-L534 |
gtalarico/airtable-python-wrapper | airtable/airtable.py | Airtable.mirror | def mirror(self, records, **options):
"""
Deletes all records on table or view and replaces with records.
>>> records = [{'Name': 'John'}, {'Name': 'Marc'}]
>>> record = airtable.,mirror(records)
If view options are provided, only records visible on that view will
... | python | def mirror(self, records, **options):
"""
Deletes all records on table or view and replaces with records.
>>> records = [{'Name': 'John'}, {'Name': 'Marc'}]
>>> record = airtable.,mirror(records)
If view options are provided, only records visible on that view will
... | [
"def",
"mirror",
"(",
"self",
",",
"records",
",",
"*",
"*",
"options",
")",
":",
"all_record_ids",
"=",
"[",
"r",
"[",
"'id'",
"]",
"for",
"r",
"in",
"self",
".",
"get_all",
"(",
"*",
"*",
"options",
")",
"]",
"deleted_records",
"=",
"self",
".",
... | Deletes all records on table or view and replaces with records.
>>> records = [{'Name': 'John'}, {'Name': 'Marc'}]
>>> record = airtable.,mirror(records)
If view options are provided, only records visible on that view will
be deleted.
>>> record = airtable.mirror(rec... | [
"Deletes",
"all",
"records",
"on",
"table",
"or",
"view",
"and",
"replaces",
"with",
"records",
".",
">>>",
"records",
"=",
"[",
"{",
"Name",
":",
"John",
"}",
"{",
"Name",
":",
"Marc",
"}",
"]",
">>>",
"record",
"=",
"airtable",
".",
"mirror",
"(",
... | train | https://github.com/gtalarico/airtable-python-wrapper/blob/48b2d806178085b52a31817571e5a1fc3dce4045/airtable/airtable.py#L554-L584 |
siznax/wptools | wptools/category.py | WPToolsCategory._add_members | def _add_members(self, catmembers):
"""
Adds category members and subcategories to data
"""
members = [x for x in catmembers if x['ns'] == 0]
subcats = [x for x in catmembers if x['ns'] == 14]
if 'members' in self.data:
self.data['members'].extend(members)
... | python | def _add_members(self, catmembers):
"""
Adds category members and subcategories to data
"""
members = [x for x in catmembers if x['ns'] == 0]
subcats = [x for x in catmembers if x['ns'] == 14]
if 'members' in self.data:
self.data['members'].extend(members)
... | [
"def",
"_add_members",
"(",
"self",
",",
"catmembers",
")",
":",
"members",
"=",
"[",
"x",
"for",
"x",
"in",
"catmembers",
"if",
"x",
"[",
"'ns'",
"]",
"==",
"0",
"]",
"subcats",
"=",
"[",
"x",
"for",
"x",
"in",
"catmembers",
"if",
"x",
"[",
"'ns... | Adds category members and subcategories to data | [
"Adds",
"category",
"members",
"and",
"subcategories",
"to",
"data"
] | train | https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/category.py#L74-L90 |
siznax/wptools | wptools/category.py | WPToolsCategory._query | def _query(self, action, qobj):
"""
Form query to enumerate category
"""
title = self.params.get('title')
pageid = self.params.get('pageid')
if action == 'random':
return qobj.random(namespace=14)
elif action == 'category':
return qobj.cat... | python | def _query(self, action, qobj):
"""
Form query to enumerate category
"""
title = self.params.get('title')
pageid = self.params.get('pageid')
if action == 'random':
return qobj.random(namespace=14)
elif action == 'category':
return qobj.cat... | [
"def",
"_query",
"(",
"self",
",",
"action",
",",
"qobj",
")",
":",
"title",
"=",
"self",
".",
"params",
".",
"get",
"(",
"'title'",
")",
"pageid",
"=",
"self",
".",
"params",
".",
"get",
"(",
"'pageid'",
")",
"if",
"action",
"==",
"'random'",
":",... | Form query to enumerate category | [
"Form",
"query",
"to",
"enumerate",
"category"
] | train | https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/category.py#L92-L102 |
siznax/wptools | wptools/category.py | WPToolsCategory._set_data | def _set_data(self, action):
"""
Set category member data from API response
"""
data = self._load_response(action)
self._handle_continuations(data, 'category')
if action == 'category':
members = data.get('query').get('categorymembers')
if members... | python | def _set_data(self, action):
"""
Set category member data from API response
"""
data = self._load_response(action)
self._handle_continuations(data, 'category')
if action == 'category':
members = data.get('query').get('categorymembers')
if members... | [
"def",
"_set_data",
"(",
"self",
",",
"action",
")",
":",
"data",
"=",
"self",
".",
"_load_response",
"(",
"action",
")",
"self",
".",
"_handle_continuations",
"(",
"data",
",",
"'category'",
")",
"if",
"action",
"==",
"'category'",
":",
"members",
"=",
... | Set category member data from API response | [
"Set",
"category",
"member",
"data",
"from",
"API",
"response"
] | train | https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/category.py#L104-L122 |
siznax/wptools | wptools/category.py | WPToolsCategory.get_members | def get_members(self, show=True, proxy=None, timeout=0):
"""
GET Mediawiki:API (action=query) category members
https://www.mediawiki.org/wiki/API:Categorymembers
Required {params}: title OR pageid
- title: <str> article title
- pageid: <int> Wikipedia database ID
... | python | def get_members(self, show=True, proxy=None, timeout=0):
"""
GET Mediawiki:API (action=query) category members
https://www.mediawiki.org/wiki/API:Categorymembers
Required {params}: title OR pageid
- title: <str> article title
- pageid: <int> Wikipedia database ID
... | [
"def",
"get_members",
"(",
"self",
",",
"show",
"=",
"True",
",",
"proxy",
"=",
"None",
",",
"timeout",
"=",
"0",
")",
":",
"title",
"=",
"self",
".",
"params",
".",
"get",
"(",
"'title'",
")",
"pageid",
"=",
"self",
".",
"params",
".",
"get",
"(... | GET Mediawiki:API (action=query) category members
https://www.mediawiki.org/wiki/API:Categorymembers
Required {params}: title OR pageid
- title: <str> article title
- pageid: <int> Wikipedia database ID
Optional arguments:
- [show]: <bool> echo page data if true
... | [
"GET",
"Mediawiki",
":",
"API",
"(",
"action",
"=",
"query",
")",
"category",
"members",
"https",
":",
"//",
"www",
".",
"mediawiki",
".",
"org",
"/",
"wiki",
"/",
"API",
":",
"Categorymembers"
] | train | https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/category.py#L124-L152 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.