Reputation: 1
Trying to schedule a python code in crontab, but it doesn't work. How Can I understand the reason why? I've already add cron and termianl to Full disk access, so this shouldn't be a problem
everything works fine when I run in terminal command
python /users/myuser/slots_update.py
Crontab command which doesnt'work:
45 12 * * * /usr/bin/python /users/myuser/slots_update.py
Python script (put different sql inside to make it simplier)
#!/usr/bin/env python
# coding: utf-8
# In[2]:
# importing the required libraries
import gspread
import pandas as pd
from oauth2client.service_account import ServiceAccountCredentials
# In[50]:
# define the scope
scope = ['https://spreadsheets.google.com/feeds','https://www.googleapis.com/auth/drive']
# add credentials to the account
creds = ServiceAccountCredentials.from_json_keyfile_name('key.json', scope)
# authorize the clientsheet
client = gspread.authorize(creds)
# In[51]:
# get the instance of the Spreadsheet
sheet = client.open('EGE_slots1')
# get the first sheet of the Spreadsheet
sheet_instance = sheet.get_worksheet(0)
# In[ ]:
sheet_instance.col_count
# In[52]:
sheet_instance.cell(col=1,row=1)
# In[12]:
import pandas as pd
import numpy as np
from sqlalchemy import create_engine
from datetime import datetime as dt
# In[13]:
connection = create_engine('postgresql://')
# In[47]:
slots = pd.read_sql("""
select * from teachers
""",connection)
# In[53]:
sheet_instance.update('A2',slots.values.tolist())
# In[ ]:
Upvotes: 0
Views: 62
Reputation: 23815
Use full path to the json file.
creds = ServiceAccountCredentials.from_json_keyfile_name('key.json', scope)
--> creds = ServiceAccountCredentials.from_json_keyfile_name('/a/b/c/key.json', scope)
Upvotes: 1