Hi all and thank you for reading i'll discuss underneath.
I have a simple python script that prints a random fact from reddit into the terminal i'm testing the waters of terminal whilst learning python.
I've tried changing my permissions to access the /usr/bin/ dir. No success
I've generated a new reddit.py script inside the /usr/bin dir as i read elsewhere that crontab only runs from its home directory and if both pathways are given in the crontab file this should solve the problem of it running. Again no success.
I've given myself full read, write and execute permissions on / apart from 'proc' & 'sys' which were denied.
It will run if i write the pathway in terminal and prints a random fact from the TIL from reddit.
Will not run through crontab any further information anyone can provide will be greatly received and if you can please provide any simplified detail as i've just started with this and i'm getting the hang of things slowly but surely. Again many thanks. I'll provide a copy of script below.
I am running Debian 10 on a AMD 64 chromebook.
#! /usr/bin/env python
import requests
import json
subreddit = 'todayilearned'
count = 1
timeframe = 'day' #hour, day, week, month, year, all
listing = 'random' # controversial, best, hot, new, random, rising, top
def get_reddit(subreddit,count):
try:
base_url = f'https://www.reddit.com/r/{subreddit}/{listing}.json?count={count}&t={timeframe}'
request = requests.get(base_url, headers = {'User-agent': 'yourbot'})
except:
print('An Error Occured')
return request.json()
top_post = get_reddit(subreddit,count)
if listing != 'random':
title = top_post['data']['children'][0]['data']['title']
url = top_post['data']['children'][0]['data']['url']
else:
title = top_post[0]['data']['children'][0]['data']['title']
url = top_post[0]['data']['children'][0]['data']['url']
print(f'{title}\n{url}')
Crontab file:
*/5 * * * * /usr/bin/python /usr/bin/reddit.py >dev/null 2>&1
Thanks, I've been trying to resolve this for a good 12 hours and still no success. It is helping me become comfortable with the environment and commands though! So silver linings =)