Skip to content

yamlfile.py

Bases: object

Config file in YAML format.

Parameters:

Name Type Description Default
data str

The filespec of the YAML file to read

required

Returns:

Type Description
YamlFile

An instance of this object

Source code in osm_fieldwork/yamlfile.py
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
def __init__(
    self,
    data: str,
):
    """This parses a yaml file into a dictionary for easy access.

    Args:
        data (str): The filespec of the YAML file to read

    Returns:
        (YamlFile): An instance of this object
    """
    self.filespec = None
    # if data == str:
    self.filespec = data
    self.file = open(data, "rb").read()
    self.yaml = yaml.load(self.file, Loader=yaml.Loader)

privateData

privateData(keyword)

See if a keyword is in the private data category.

Parameters:

Name Type Description Default
keyword str

The keyword to search for

required

Returns:

Type Description
bool

Check to see if the keyword is in the private data section

Source code in osm_fieldwork/yamlfile.py
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
def privateData(
    self,
    keyword: str,
):
    """See if a keyword is in the private data category.

    Args:
        keyword (str): The keyword to search for

    Returns:
        (bool): Check to see if the keyword is in the private data section
    """
    for value in self.yaml["private"]:
        if keyword.lower() in value:
            return True
    return False

ignoreData

ignoreData(keyword)

See if a keyword is in the ignore data category.

Parameters:

Name Type Description Default
keyword str

The keyword to search for

required

Returns:

Type Description
bool

Check to see if the keyword is in the ignore data section

Source code in osm_fieldwork/yamlfile.py
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
def ignoreData(
    self,
    keyword: str,
):
    """See if a keyword is in the ignore data category.

    Args:
        keyword (str): The keyword to search for

    Returns:
        (bool): Check to see if the keyword is in the ignore data section
    """
    for value in self.yaml["ignore"]:
        if keyword.lower() in value:
            return True
    return False

convertData

convertData(keyword)

See if a keyword is in the convert data category.

Parameters:

Name Type Description Default
keyword str

The keyword to search for

required

Returns:

Type Description
bool

Check to see if the keyword is in the convert data section

Source code in osm_fieldwork/yamlfile.py
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
def convertData(
    self,
    keyword: str,
):
    """See if a keyword is in the convert data category.

    Args:
        keyword (str): The keyword to search for

    Returns:
        (bool): Check to see if the keyword is in the convert data section
    """
    for value in self.yaml["convert"]:
        if keyword.lower() in value:
            return True
    return False

dump

dump()

Dump internal data structures, for debugging purposes only.

Source code in osm_fieldwork/yamlfile.py
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
def dump(self):
    """Dump internal data structures, for debugging purposes only."""
    if self.filespec:
        print("YAML file: %s" % self.filespec)
    for key, values in self.yaml.items():
        print(f"Key is: {key}")
        for v in values:
            if type(v) == dict:
                for k1, v1 in v.items():
                    if type(v1) == list:
                        for item in v1:
                            for i, j in item.items():
                                print(f"\t{i} = {j}")
                    else:
                        print(f"\t{k1} = {v1}")
                print("------------------")
            else:
                print(f"\t{v}")

write

write(table)

Add to the YAML file.

Parameters:

Name Type Description Default
table list

The name of the database table

required

Returns:

Type Description
str

The modified YAML data

Source code in osm_fieldwork/yamlfile.py
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
def write(
    self,
    table: list,
):
    """Add to the YAML file.

    Args:
          table (list): The name of the database table

    Returns:
        (str): The modified YAML data
    """
    tab = "    "
    yaml = ["select:", f'{tab}"osm_id": id', f"{tab}tags:"]
    for item in where:
        yaml.append(f"{tab}{tab}- {item}")
    yaml.append("from:")
    for item in table:
        yaml.append(f"{tab}- {item}")
    yaml.append("where:")
    yaml.append(f"{tab}tags:")
    notnull = f"{tab}{tab}- " + "{"
    for item in where:
        notnull += f"{item}: NOT NULL, "
    notnull = f"{notnull[:-2]}"
    notnull += "}"
    yaml.append(f"{notnull}")
    return yaml

options: show_source: false heading_level: 3