def get_count(cls, table: Table, privacy_group: str) -> int:
     response = table.get_item(Key={
         "PK": cls._get_pkey(),
         "SK": cls._get_skey(privacy_group)
     })
     return ("Item" in response
             and int(t.cast(Decimal, response["Item"]["WriteCount"])) or 0)
Esempio n. 2
0
def get_item_exists(table: Table, wizard: str) -> bool:
    try:
        db_response = table.get_item(Key={'username': wizard})
        item = db_response['Item']
        return True
    except Exception as e:
        print("Something went wrong: ", e)
        return False
 def get_from_signal_and_ds_id(
         cls, table: Table, signal_id: t.Union[str, int],
         signal_source: str, ds_id: str) -> t.Optional["PDQSignalMetadata"]:
     item = table.get_item(Key={
         "PK":
         cls.get_dynamodb_signal_key(signal_source, signal_id),
         "SK":
         cls.DATASET_PREFIX + ds_id,
     }, ).get("Item")
     return cls._result_item_to_metadata(item) if item else None
Esempio n. 4
0
 def get_value(self, table: Table) -> int:
     """
     Get current value for the counter.
     """
     return t.cast(
         int,
         table.get_item(Key={"PK": self.get_pkey(), "SK": self.get_skey()})
         .get("Item", {})
         .get("CurrentCount", 0),
     )
Esempio n. 5
0
    def get_from_signal_and_privacy_group(
        cls, table: Table, signal_id: t.Union[str, int], privacy_group_id: str
    ) -> t.Optional["ThreatExchangeSignalMetadata"]:
        """
        Load object for this signal and privacy_group combination.
        """
        pk = cls.get_dynamodb_signal_key(cls.SIGNAL_SOURCE_SHORTCODE, signal_id)
        sk = cls.get_sort_key(privacy_group_id)

        item = table.get_item(Key={"PK": pk, "SK": sk})
        return "Item" in item and cls._result_item_to_metadata(item["Item"]) or None
Esempio n. 6
0
def get_item_info(table: Table, wizard: str) -> Dict[Any, Any]:
    try:
        db_response = table.get_item(Key={'username': wizard})
        item = db_response['Item']
        return item
    except Exception as e:
        print("Something went wrong: ", e)
        message = {
            'text':
            f'Witch/wizard _*{wizard}*_ is not listed as a *Hogwarts Alumni*, most likely to be enrolled in _Beauxbatons_ or _Durmstrang_'
        }
        return message
Esempio n. 7
0
 def get_from_content_id(
     cls, table: Table, content_id: str,
     signal_type_mapping: HMASignalTypeMapping
 ) -> t.Optional["ContentObject"]:
     if not content_id:
         return None
     item = table.get_item(
         Key={
             "PK": cls.get_dynamodb_content_key(content_id),
             "SK": cls.get_dynamodb_content_type_key(),
         }).get("Item", None)
     if item:
         return cls._result_item_to_object(item, signal_type_mapping)
     return None
 def get_from_content_id(
     cls,
     table: Table,
     content_id: str,
     content_type: ContentType = ContentType.PHOTO,
 ) -> t.Optional["ContentObject"]:
     if not content_id:
         return None
     item = table.get_item(
         Key={
             "PK": cls.get_dynamodb_content_key(content_id),
             "SK": cls.get_dynamodb_content_type_key(content_type),
         }).get("Item", None)
     if item:
         return cls._result_item_to_object(item)
     return None
Esempio n. 9
0
def _get_reverse_edge(schema_table: Table, schema: BaseSchema, f_edge) -> str:
    edge_res = schema_table.get_item(Key={"f_edge": f_edge})["Item"]
    return edge_res["r_edge"]
Esempio n. 10
0
def meta_into_edge(schema_table: Table, schema: Schema, f_edge) -> EdgeT:
    edge_res = schema_table.get_item(Key={"f_edge": f_edge})["Item"]
    edge_t = schema.edges[f_edge][0]  # type: EdgeT

    return EdgeT(type(schema), edge_t.dest, EdgeRelationship(edge_res["relationship"]))