Answer the question
In order to leave comments, you need to log in
How to run python script in cron?
Hello everyone, help me run the script in cron, the scheduler itself works, but the script itself does not work, although when launched on a LAN, everything works with a bang!
here is part of the code
# -*- coding: utf-8 -*-
import time
import eventlet
import requests
import logging
import telebot
from time import sleep
URL_VK = 'https://api.vk.com/method/wall.get?domain=bootstraphtml5&count=10&filter=owner'
FILENAME_VK = 'last_known_id.txt'
BASE_POST_URL = 'https://vk.com/wall-74027819_'
BOT_TOKEN = 'тут токен бота'
CHANNEL_NAME = '@bootstraphtml5'
SINGLE_RUN = True
bot = telebot.TeleBot(BOT_TOKEN)
def get_data():
timeout = eventlet.Timeout(10)
try:
feed = requests.get(URL_VK)
return feed.json()
except eventlet.timeout.Timeout:
logging.warning('Got Timeout while retrieving VK JSON data. Cancelling...')
return None
finally:
timeout.cancel()
def send_new_posts(items, last_id):
for item in items:
if item['id'] <= last_id:
Answer the question
In order to leave comments, you need to log in
There may be several reasons, import error, no interpreter specified, sometimes it's worth doing cd scriptdir first. Give an example of a line in the crontab and what error you get, so as not to guess.
Use absolute paths and you will be happy.
How can the system understand where the file is located ???
At least like this:
Or like this:
PREFIX = "/var/tmp/"
FILENAME_VK = '%s/last_known_id.txt' % PREFIX
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question