Created
June 7, 2022 12:39
-
-
Save dubeyji10/cd9518941fe1531a7a3f42fbb12f1d1a to your computer and use it in GitHub Desktop.
connection lost at index 400 restarted api requests at index 401
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ''' | |
| push clients with refresh tokens function | |
| ''' | |
| import os | |
| import logging | |
| import time | |
| from datetime import datetime , timedelta | |
| import json | |
| from apiCall import pushInto | |
| import requests | |
| #refreshing access token | |
| urlRefresh = "https://accounts.zoho.in/oauth/v2/token?" | |
| files=[] | |
| headers = {} | |
| now = datetime.now() | |
| fileName = now.strftime('%Y_%m_%d_%H_%M_%S') | |
| logging.basicConfig(filename="logs\\clientsAPI_call_refreshContinued at_401_"+fileName+"_LOGS.log", level=logging.INFO, datefmt='%Y-%m-%d %H:%M:%S') | |
| startTime = now | |
| print('script started at : {}'.format(startTime.strftime('%Y-%m-%d %H:%M:%S'))) | |
| logging.info('script started at : {}\n'.format(startTime.strftime('%Y-%m-%d %H:%M:%S'))) | |
| path = 'clients' | |
| files = [f for f in os.listdir(path)] | |
| for index,i in enumerate(files): | |
| payloadPath = '' | |
| responsePath = '' | |
| currPath = '' | |
| payloadPath = i | |
| print('now payloadPath : {}'.format(i)) | |
| logging.info(f'--> payload #{index} : {i}') | |
| print(' ----------- index : {} --------------'.format(index)) | |
| logging.info(' ----------- index : {} --------------'.format(index)) | |
| if index<401: | |
| print('skipping') | |
| logging.info('\t -------- skipped ----------\n') | |
| else: | |
| responsePath = 'responses\\clients\\'+i[:-5] + "_response.json" | |
| print('making api request') | |
| logging.info('making api request') | |
| data = None | |
| currPath = os.path.join(path,i) | |
| print('payload path : ',currPath) | |
| with open(currPath,'r') as clientPayload: | |
| data = clientPayload.read() | |
| print('length of file read : ',len(data)) | |
| res = pushInto('clients',data) | |
| with open(responsePath,'w') as responseClient: | |
| responseClient.write(res.text) | |
| print('\t -> response in : {}'.format(responsePath)) | |
| logging.info('\t -> response in : {}\n'.format(responsePath)) | |
| print('-'*50) | |
| print('3 second wait') | |
| time.sleep(3) | |
| logging.info(' {0} {0} '.format(' - - - - - - - - - - - - - - - - - - - - - - - - - - - ')) | |
| now = datetime.now() | |
| endTime = now | |
| print('script ended at : {}'.format(endTime.strftime('%Y-%m-%d %H:%M:%S'))) | |
| logging.info('script ended at : {}'.format(endTime.strftime('%Y-%m-%d %H:%M:%S'))) | |
| print('total files read : ',len(files)) | |
| print('last file in directory : ',files[-1]) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment