How to use the followthemoney.util.defer function in followthemoney

To help you get started, we’ve selected a few followthemoney examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github alephdata / followthemoney / followthemoney / types / topic.py View on Github external
"corp.offshore": _("Offshore"),
        "corp.shell": _("Shell company"),
        "gov": _("Government"),
        "gov.national": _("National government"),
        "gov.state": _("State government"),
        "gov.muni": _("Municipal government"),
        "gov.soe": _("State-owned enterprise"),
        "gov.igo": _("Intergovernmental organization"),
        "fin": _("Financial services"),
        "fin.bank": _("Bank"),
        "fin.fund": _("Fund"),
        "fin.adivsor": _("Financial advisor"),
        "role.pep": _("Politician"),  # don't FATF-splain me, bro.
        "role.rca": _("Associate"),
        "role.judge": _("Judge"),
        "role.civil": _("Civil servant"),
        "role.diplo": _("Diplomat"),
        "role.lawyer": _("Lawyer"),
        "role.acct": _("Accountant"),
        "role.spy": _("Spy"),
        "role.journo": _("Journalist"),
        "role.act": _("Activist"),
        "pol.party": _("Political party"),
        "pol.union": _("Union"),
        "rel": _("Religion"),
        "mil": _("Military"),
        "asset.frozen": _("Frozen asset"),
        "ctx.sanctioned": _("Sanctioned entity"),
        "ctx.poi": _("Person of interest"),
    }

    def _locale_names(self, locale):
github alephdata / followthemoney / followthemoney / types / topic.py View on Github external
"crime.terror": _("Terrorism"),
        "crime.traffick": _("Trafficking"),
        "crime.traffick.drug": _("Drug trafficking"),
        "crime.traffick.human": _("Human trafficking"),
        "corp.offshore": _("Offshore"),
        "corp.shell": _("Shell company"),
        "gov": _("Government"),
        "gov.national": _("National government"),
        "gov.state": _("State government"),
        "gov.muni": _("Municipal government"),
        "gov.soe": _("State-owned enterprise"),
        "gov.igo": _("Intergovernmental organization"),
        "fin": _("Financial services"),
        "fin.bank": _("Bank"),
        "fin.fund": _("Fund"),
        "fin.adivsor": _("Financial advisor"),
        "role.pep": _("Politician"),  # don't FATF-splain me, bro.
        "role.rca": _("Associate"),
        "role.judge": _("Judge"),
        "role.civil": _("Civil servant"),
        "role.diplo": _("Diplomat"),
        "role.lawyer": _("Lawyer"),
        "role.acct": _("Accountant"),
        "role.spy": _("Spy"),
        "role.journo": _("Journalist"),
        "role.act": _("Activist"),
        "pol.party": _("Political party"),
        "pol.union": _("Union"),
        "rel": _("Religion"),
        "mil": _("Military"),
        "asset.frozen": _("Frozen asset"),
        "ctx.sanctioned": _("Sanctioned entity"),
github alephdata / followthemoney / followthemoney / types / text.py View on Github external
from followthemoney.types.common import PropertyType
from followthemoney.util import defer as _
from followthemoney.util import MEGABYTE


class TextType(PropertyType):
    name = 'text'
    label = _('Text')
    matchable = False
    max_size = 20 * MEGABYTE
github alephdata / followthemoney / followthemoney / types / entity.py View on Github external
import re
from rdflib import URIRef  # type: ignore

from followthemoney.types.common import PropertyType
from followthemoney.util import get_entity_id, sanitize_text
from followthemoney.util import defer as _


class EntityType(PropertyType):
    ID_RE = re.compile(r"^[0-9a-zA-Z]([0-9a-zA-Z\.\-]*[0-9a-zA-Z])?$")
    name = "entity"
    group = "entities"
    label = _("Entity")
    plural = _("Entities")
    matchable = True
    pivot = True

    def validate(self, text, **kwargs):
        text = sanitize_text(text)
        if text is None:
            return False
        return self.ID_RE.match(text) is not None

    def clean(self, text, **kwargs):
        entity_id = get_entity_id(text)
        if entity_id is None:
            return
        entity_id = str(entity_id)
        if self.ID_RE.match(entity_id) is not None:
github alephdata / followthemoney / followthemoney / types / topic.py View on Github external
name = "topic"
    group = "topics"
    label = _("Topic")
    plural = _("Topics")
    matchable = False

    _TOPICS = {
        "crime": _("Crime"),
        "crime.fraud": _("Fraud"),
        "crime.cyber": _("Cybercrime"),
        "crime.fin": _("Financial crime"),
        "crime.theft": _("Theft"),
        "crime.war": _("War crimes"),
        "crime.boss": _("Criminal leadership"),
        "crime.terror": _("Terrorism"),
        "crime.traffick": _("Trafficking"),
        "crime.traffick.drug": _("Drug trafficking"),
        "crime.traffick.human": _("Human trafficking"),
        "corp.offshore": _("Offshore"),
        "corp.shell": _("Shell company"),
        "gov": _("Government"),
        "gov.national": _("National government"),
        "gov.state": _("State government"),
        "gov.muni": _("Municipal government"),
        "gov.soe": _("State-owned enterprise"),
        "gov.igo": _("Intergovernmental organization"),
        "fin": _("Financial services"),
        "fin.bank": _("Bank"),
        "fin.fund": _("Fund"),
        "fin.adivsor": _("Financial advisor"),
        "role.pep": _("Politician"),  # don't FATF-splain me, bro.
        "role.rca": _("Associate"),
github alephdata / followthemoney / followthemoney / types / mimetype.py View on Github external
from rdflib import URIRef  # type: ignore
from pantomime import normalize_mimetype, parse_mimetype  # type: ignore
from pantomime import DEFAULT  # type: ignore

from followthemoney.types.common import PropertyType
from followthemoney.util import defer as _


class MimeType(PropertyType):
    name = "mimetype"
    group = "mimetypes"
    label = _("MIME-Type")
    plural = _("MIME-Types")
    matchable = False

    def clean_text(self, text, **kwargs):
        text = normalize_mimetype(text)
        if text != DEFAULT:
            return text

    def rdf(self, value):
        return URIRef("urn:mimetype:%s" % value)

    def caption(self, value):
        return parse_mimetype(value).label
github alephdata / followthemoney / followthemoney / types / ip.py View on Github external
from rdflib import URIRef  # type: ignore
from ipaddress import ip_address  # type: ignore

from followthemoney.types.common import PropertyType
from followthemoney.util import defer as _


class IpType(PropertyType):
    name = "ip"
    group = "ips"
    label = _("IP-Address")
    plural = _("IP-Addresses")
    matchable = True

    def validate(self, ip, **kwargs):
        """Check to see if this is a valid ip address."""
        try:
            ip_address(ip)
            return True
        except ValueError:
            return False

    def clean_text(self, text, **kwargs):
        """Create a more clean, but still user-facing version of an
        instance of the type."""
        try:
            return str(ip_address(text))
        except ValueError:
github alephdata / followthemoney / followthemoney / types / topic.py View on Github external
"crime.fin": _("Financial crime"),
        "crime.theft": _("Theft"),
        "crime.war": _("War crimes"),
        "crime.boss": _("Criminal leadership"),
        "crime.terror": _("Terrorism"),
        "crime.traffick": _("Trafficking"),
        "crime.traffick.drug": _("Drug trafficking"),
        "crime.traffick.human": _("Human trafficking"),
        "corp.offshore": _("Offshore"),
        "corp.shell": _("Shell company"),
        "gov": _("Government"),
        "gov.national": _("National government"),
        "gov.state": _("State government"),
        "gov.muni": _("Municipal government"),
        "gov.soe": _("State-owned enterprise"),
        "gov.igo": _("Intergovernmental organization"),
        "fin": _("Financial services"),
        "fin.bank": _("Bank"),
        "fin.fund": _("Fund"),
        "fin.adivsor": _("Financial advisor"),
        "role.pep": _("Politician"),  # don't FATF-splain me, bro.
        "role.rca": _("Associate"),
        "role.judge": _("Judge"),
        "role.civil": _("Civil servant"),
        "role.diplo": _("Diplomat"),
        "role.lawyer": _("Lawyer"),
        "role.acct": _("Accountant"),
        "role.spy": _("Spy"),
        "role.journo": _("Journalist"),
        "role.act": _("Activist"),
        "pol.party": _("Political party"),
        "pol.union": _("Union"),
github alephdata / followthemoney / followthemoney / types / address.py View on Github external
import re
from normality import slugify
from normality.cleaning import collapse_spaces

from followthemoney.types.common import PropertyType
from followthemoney.util import defer as _
from followthemoney.util import dampen


class AddressType(PropertyType):
    LINE_BREAKS = re.compile(r"(\r\n|\n|<br>|<br>|\t|ESQ\.,|ESQ,|;)")
    COMMATA = re.compile(r"(,\s?[,\.])")
    name = "address"
    group = "addresses"
    label = _("Address")
    plural = _("Addresses")
    matchable = True
    pivot = True

    def clean_text(self, address, **kwargs):
        """Basic clean-up."""
        address = self.LINE_BREAKS.sub(", ", address)
        address = self.COMMATA.sub(", ", address)
        address = collapse_spaces(address)
        if len(address):
            return address

    def _specificity(self, value: str) -&gt; float:
        return dampen(10, 60, value)

    def node_id(self, value: str) -&gt; str:
        return "addr:%s" % slugify(value)
github alephdata / followthemoney / followthemoney / types / topic.py View on Github external
"crime.traffick.drug": _("Drug trafficking"),
        "crime.traffick.human": _("Human trafficking"),
        "corp.offshore": _("Offshore"),
        "corp.shell": _("Shell company"),
        "gov": _("Government"),
        "gov.national": _("National government"),
        "gov.state": _("State government"),
        "gov.muni": _("Municipal government"),
        "gov.soe": _("State-owned enterprise"),
        "gov.igo": _("Intergovernmental organization"),
        "fin": _("Financial services"),
        "fin.bank": _("Bank"),
        "fin.fund": _("Fund"),
        "fin.adivsor": _("Financial advisor"),
        "role.pep": _("Politician"),  # don't FATF-splain me, bro.
        "role.rca": _("Associate"),
        "role.judge": _("Judge"),
        "role.civil": _("Civil servant"),
        "role.diplo": _("Diplomat"),
        "role.lawyer": _("Lawyer"),
        "role.acct": _("Accountant"),
        "role.spy": _("Spy"),
        "role.journo": _("Journalist"),
        "role.act": _("Activist"),
        "pol.party": _("Political party"),
        "pol.union": _("Union"),
        "rel": _("Religion"),
        "mil": _("Military"),
        "asset.frozen": _("Frozen asset"),
        "ctx.sanctioned": _("Sanctioned entity"),
        "ctx.poi": _("Person of interest"),
    }