Advertisement
Guest User

Untitled

a guest
Mar 31st, 2020
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. import init_workdir
  2. import logging
  3.  
  4. import dropbox
  5. from dropbox.files import WriteMode
  6. from tqdm import tqdm as tqdm
  7.  
  8. from src.rateshopper.config import config
  9. from src.data.general_data_utils import write_df_to_db
  10.  
  11.  
  12. class TransferData:
  13. def __init__(self, access_token):
  14. self.access_token = access_token
  15.  
  16. def upload_file(self, file_from, file_to):
  17. """upload a file to Dropbox using API v2
  18. """
  19. logging.info('Creating dbx with access_token')
  20. dbx = dropbox.Dropbox(self.access_token)
  21.  
  22. with open(file_from, 'rb') as f:
  23. dbx.files_upload(f.read(), file_to, mode=WriteMode('overwrite'))
  24.  
  25.  
  26. def upload_last_state_data_to_dropbox(list_of_files):
  27. access_token = config.DROPBOX_ACCESS_TOKEN
  28. logging.info('Creating TransferData')
  29. transferData = TransferData(access_token)
  30.  
  31. for file in tqdm(list_of_files):
  32. file_from = config.LOG_PATH + file
  33. file_to = config.DROPBOX_FOLDER + file # The full path to upload the file to, including the file name
  34.  
  35. # API v2
  36. logging.info('Entering TransferData.upload_file')
  37. transferData.upload_file(file_from, file_to, )
  38.  
  39. logging.info('Uploading delta to database')
  40. write_df_to_db(df=pd.read_feather(f'{config.LOG_PATH}rateshopper_detlta.feather'),
  41. table_name='rateshopper_detlta',
  42. schema_name='RMZG')
  43.  
  44.  
  45. def main():
  46. list_of_files = ["rateshopper_zagreb.xlsx", "rateshopper_istra.xlsx", "rateshopper_dubrovnik.xlsx",
  47. "sanity_check.txt", "histogram.png", "rateshopper_index_report.xlsx"]
  48. upload_last_state_data_to_dropbox(list_of_files)
  49.  
  50.  
  51. if __name__ == '__main__':
  52. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement