-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebscrapping.py
56 lines (45 loc) · 1.62 KB
/
webscrapping.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import requests
import json
import pandas as pd
import boto3
import os
from datetime import datetime
from io import StringIO
import time
import configparser
def s3_upload(path, source):
config = configparser.ConfigParser()
config.read('cred.conf')
access_key = config['AWS']['KEY']
secret_access_key = config['AWS']['SECRET']
print("enviando para a nuvem...")
t = datetime.now()
date = t.strftime('%y-%m-%d %Hh:%Mm:%Ss')
destination_s3_bucket = 'datalake-proaplicado'
upload_file_key = 'raw-zone/' + '{}-{}'.format(date,source)
filepath = upload_file_key + ".csv"
s3 = boto3.resource('s3',
aws_access_key_id=access_key,
aws_secret_access_key=secret_access_key,
region_name='sa-east-1')
s3.Bucket(destination_s3_bucket).upload_file(path,upload_file_key)
def vesselCompanies():
lista = []
print("Obtendo tabelas...")
for number in range(100,13900,100):
passo = pd.read_html('https://nrcwaplan.usecology.com/VesselList/VesselList?index={}'.format(number), attrs = {'class': 'table'}, header=0)
lista.append(passo)
time.sleep(1)
print("Gravando tabelas...")
for i in range(0,137):
lista[i][0].to_csv(f'./operadoras/operadoras{i}.csv', sep=';', header=True)
return
def main():
#vesselCompanies()
path = "/home/airflow/airflow/dags/operadoras"
for file in os.listdir(path):
if file.endswith(".csv"):
s3_upload(os.path.join(path, file), "operators")
return print("Data was uploaded")
if __name__ == "__main__":
main()