Skip to content

Commit 738139c

Browse files
committed
style: Applies linters
1 parent d177c3f commit 738139c

4 files changed

+32
-18
lines changed

extract.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import os.path
2+
23
import requests
3-
from tqdm import tqdm
44
from bs4 import BeautifulSoup
5+
from tqdm import tqdm
56

67
path = 'data/extract/'
78

@@ -23,22 +24,21 @@
2324
if os.path.exists(filename):
2425
continue
2526

26-
with requests.get(link) as file_response:
27-
with open(filename, 'wb') as file_to_save:
28-
file_to_save.write(file_response.content)
27+
with requests.get(link) as file_response, open(filename, 'wb') as file_to_save:
28+
file_to_save.write(file_response.content)
2929

3030
# Public aerodromes (ANAC)
3131
public_aerodromes_filepath = path + 'public_aerodromes.csv'
3232
if not os.path.exists(public_aerodromes_filepath):
3333
url = 'https://sistemas.anac.gov.br/dadosabertos/Aerodromos/Aer%C3%B3dromos%20P%C3%BAblicos/Lista%20de%20aer%C3%B3dromos%20p%C3%BAblicos/AerodromosPublicos.csv'
34-
with requests.get(url) as file_response:
35-
with open(public_aerodromes_filepath, 'wb') as file_to_save:
36-
file_to_save.write(file_response.content)
34+
with requests.get(url) as file_response, \
35+
open(public_aerodromes_filepath, 'wb') as file_to_save:
36+
file_to_save.write(file_response.content)
3737

3838
# Airport Codes (DataHub.io)
3939
airport_codes_filepath = path + 'airport_codes.csv'
4040
if not os.path.exists(airport_codes_filepath):
4141
url = 'https://datahub.io/core/airport-codes/r/airport-codes.csv'
42-
with requests.get(url) as file_response:
43-
with open(airport_codes_filepath, 'wb') as file_to_save:
44-
file_to_save.write(file_response.content)
42+
with requests.get(url) as file_response, \
43+
open(airport_codes_filepath, 'wb') as file_to_save:
44+
file_to_save.write(file_response.content)

transform_to_airports_csv.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os.path
2+
23
import geocoder
34
import pandas as pd
45

@@ -91,14 +92,19 @@
9192
'ident',
9293
'coordinates',
9394
]
94-
df_others_airports = pd.read_csv(path + 'airport_codes.csv', usecols=others_airports_columns)
95+
df_others_airports = pd.read_csv(
96+
path + 'airport_codes.csv',
97+
usecols=others_airports_columns
98+
)
9599

96100
# Rename columns
97101
columns_map = {
98102
'ident': 'code',
99103
}
100104
df_others_airports = df_others_airports.rename(columns=columns_map)
101-
df_others_airports[['lon_geo_point', 'lat_geo_point']] = df_others_airports.coordinates.str.split(', ', expand=True, )
105+
df_others_airports[
106+
['lon_geo_point', 'lat_geo_point']
107+
] = df_others_airports.coordinates.str.split(', ', expand=True, )
102108
df_others_airports = df_others_airports.drop(columns=['coordinates'])
103109

104110
# Coordinates dataframe
@@ -123,7 +129,7 @@
123129
'continent',
124130
]
125131
airports_to_find = []
126-
for index, row in df_merge[df_merge.lat_geo_point.isnull()].iterrows():
132+
for index, row in df_merge[df_merge.lat_geo_point.isnull()].iterrows(): # noqa: B007
127133
label = ''
128134

129135
for column in columns:

transform_to_anac_csv.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import os.path
21
import glob
2+
import os.path
3+
34
import pandas as pd
45

56
if os.path.exists('data/anac.csv'):
@@ -9,7 +10,9 @@
910
files = glob.glob('data/extract/resumo_anual_*.csv')
1011

1112
# Combine all files in the list
12-
combined_csv = pd.concat([pd.read_csv(file, sep=';', encoding='ISO-8859-1') for file in files])
13+
combined_csv = pd.concat(
14+
[pd.read_csv(file, sep=';', encoding='ISO-8859-1') for file in files]
15+
)
1316

1417
# Rename columns
1518
columns_map = {

transform_to_graphml.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os.path
2+
23
import networkx as nx
34
import pandas as pd
45

@@ -13,7 +14,7 @@
1314
G = nx.Graph()
1415

1516
# Add nodes
16-
for index, row in df_airports.iterrows():
17+
for index, row in df_airports.iterrows(): # noqa: B007
1718
G.add_node(row['code'],
1819
name=row['name'],
1920
country=row['country'],
@@ -27,10 +28,14 @@
2728
'destination_airport_abbreviation',
2829
]].dropna()
2930
df_edges = df_edges.groupby(df_edges.columns.tolist(), as_index=False).size()
30-
for index, row in df_edges.iterrows():
31+
for index, row in df_edges.iterrows(): # noqa: B007
3132
if row['origin_airport_abbreviation'] == row['destination_airport_abbreviation']:
3233
continue
33-
G.add_edge(row['origin_airport_abbreviation'], row['destination_airport_abbreviation'], flight_count=row['size'])
34+
G.add_edge(
35+
row['origin_airport_abbreviation'],
36+
row['destination_airport_abbreviation'],
37+
flight_count=row['size']
38+
)
3439

3540
# Export to graphml
3641
nx.write_graphml(G, 'data/air_traffic.graphml')

0 commit comments

Comments
 (0)