Function that loads a custom data source Args: stream (io.StringIO): An in-memory stream of a custom data source. The format of the stream must be a comma-separated file with header containing the columns defined in
(self, stream)
| 128 | return [self.locations[index] for index in indices] |
| 129 | |
| 130 | def load(self, stream): |
| 131 | """ |
| 132 | Function that loads a custom data source |
| 133 | Args: |
| 134 | stream (io.StringIO): An in-memory stream of a custom data source. |
| 135 | The format of the stream must be a comma-separated file |
| 136 | with header containing the columns defined in RG_COLUMNS. |
| 137 | """ |
| 138 | stream_reader = csv.DictReader(stream, delimiter=',') |
| 139 | header = stream_reader.fieldnames |
| 140 | |
| 141 | if header != RG_COLUMNS: |
| 142 | raise csv.Error('Input must be a comma-separated file with header containing ' + \ |
| 143 | 'the following columns - %s. For more help, visit: ' % (','.join(RG_COLUMNS)) + \ |
| 144 | 'https://github.com/thampiman/reverse-geocoder') |
| 145 | |
| 146 | # Load all the coordinates and locations |
| 147 | geo_coords, locations = [], [] |
| 148 | for row in stream_reader: |
| 149 | geo_coords.append((row['lat'], row['lon'])) |
| 150 | locations.append(row) |
| 151 | |
| 152 | return geo_coords, locations |
| 153 | |
| 154 | def extract(self, local_filename): |
| 155 | """ |