I have just taken over a new data pipeline from a previous developer who left this role- there is not any documentation on how the python scripts are meant to work so any debugging I have to figure out on the fly.
This script is meant to be running daily on a google cloud VM but it isnt working correctly right now
The authentifaction in this script is done using oauth2client which I am not familar but it reads in two json files, credentials.json and adops.json- credentitals.json appears to have the correct info in it but the adops.json file is empty - I think there should be some sort of credentials in the file- because its empty the IF statement evaluates to true and the .run_flow() attempts to open some sort of google sheet but I dont have access to it. I am guessing theres some sort of credential stored on the sheet it is trying to access but I am not 100% sure- to me it seems simpler if the crednetials were just stored in adops.json to begin with but I am not familiar with this kind of authentication so any help is appreciated just get me in the right direction so I know what needs fixing.
`GMAIL_CREDENTIALS_PATH = 'credentials.json' # downloaded
GMAIL_TOKEN_PATH = 'adops.json' # this file is empty
SCOPES = ['https://www.googleapis.com/auth/gmail.readonly']
search_query = "[email protected]"
filename = 'Downloads/{0}_Programmatic_Duration_Media.csv'.format(datetime.now().date())
reportName = '{0}_Programmatic_Duration_Media.csv'.format(datetime.now().date())
try:
#Get OATH Credentials that already exist, else generate a request for them.
store = file.Storage(GMAIL_TOKEN_PATH)
creds = store.get()
#This will execute because adops.json is empty
if not creds or creds.invalid:
print('the creds are invalid')
flow = client.flow_from_clientsecrets(GMAIL_CREDENTIALS_PATH, SCOPES)
creds = tools.run_flow(flow, store)
print('the creds have been created')
print('attempting to create the service')
service = build('gmail', 'v1', http=creds.authorize(Http()), cache_discovery=False)
`
So far I have ran the code up to the .run_flow line. - it tries to open a google sheet but it either doesnt exist or I dont have access to it. I added the print statements to help me debug since I can see whihc bits of the code are running and which arent