-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
63 lines (53 loc) · 1.87 KB
/
main.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
57
58
59
60
61
62
63
import pandas as pd
import logging
import os
import seaborn as sns
from utils import get_credentials, create_google_spreadsheet, write_to_sheet
from column_color_codings import COLS_TO_COLORS
GCP_SERVICE_ACCOUNT_EMAIL = '[email protected]'
CREATE_NEW_SPREADSHEET = False
def order_columns(df):
columns_first = [
df.columns[idx] for idx, dtype in enumerate(df.dtypes) if str(dtype) == 'object'
]
columns_last = [col for col in df.columns if col not in columns_first]
df = df[columns_first + columns_last]
return df
def download_data():
df = sns.load_dataset('iris')
logger.info(df.shape)
return df
if __name__ == '__main__':
logging.basicConfig()
logger = logging.getLogger('logger')
logger.setLevel(logging.INFO)
df = download_data()
df = order_columns(df)
# create or fetch spreadsheet
if CREATE_NEW_SPREADSHEET:
sheet_id, gc, link = create_google_spreadsheet(
title='DFP [AutoUpdating] Sheet',
service_account_email=GCP_SERVICE_ACCOUNT_EMAIL,
credential_password_env_var_name='SA_PASSWORD',
email_message="DFP is sharing its cool autoupdating sheet with you, enjoy!",
send_notification=True,
share_domains=['[email protected]'],
)
else:
sheet_id = '1yh_gOT8TsUnwU8EAAdLSEexn3JGtiY_q5O6j8RtZevU'
link = f'\nhttps://docs.google.com/spreadsheets/d/{sheet_id}'
_, gc = get_credentials(credential_password_env_var_name='SA_PASSWORD')
# write df to sheet
write_to_sheet(
gc,
sheet_id,
'floral datas',
df,
percent_cols=[],
column_width_dict={0: 250},
no_borders=True,
wrap_cols=[],
cols_to_colors=COLS_TO_COLORS,
)
logger.info("Spreadsheet is ready!!!")
logger.info('\n' + link)