Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import init_workdir
- import logging
- import dropbox
- from dropbox.files import WriteMode
- from tqdm import tqdm as tqdm
- from src.rateshopper.config import config
- from src.data.general_data_utils import write_df_to_db
- class TransferData:
- def __init__(self, access_token):
- self.access_token = access_token
- def upload_file(self, file_from, file_to):
- """upload a file to Dropbox using API v2
- """
- logging.info('Creating dbx with access_token')
- dbx = dropbox.Dropbox(self.access_token)
- with open(file_from, 'rb') as f:
- dbx.files_upload(f.read(), file_to, mode=WriteMode('overwrite'))
- def upload_last_state_data_to_dropbox(list_of_files):
- access_token = config.DROPBOX_ACCESS_TOKEN
- logging.info('Creating TransferData')
- transferData = TransferData(access_token)
- for file in tqdm(list_of_files):
- file_from = config.LOG_PATH + file
- file_to = config.DROPBOX_FOLDER + file # The full path to upload the file to, including the file name
- # API v2
- logging.info('Entering TransferData.upload_file')
- transferData.upload_file(file_from, file_to, )
- logging.info('Uploading delta to database')
- write_df_to_db(df=pd.read_feather(f'{config.LOG_PATH}rateshopper_detlta.feather'),
- table_name='rateshopper_detlta',
- schema_name='RMZG')
- def main():
- list_of_files = ["rateshopper_zagreb.xlsx", "rateshopper_istra.xlsx", "rateshopper_dubrovnik.xlsx",
- "sanity_check.txt", "histogram.png", "rateshopper_index_report.xlsx"]
- upload_last_state_data_to_dropbox(list_of_files)
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement