I am relatively new to python and i am experiencing some issues with schedule. I have a simple BeautifulSoup code which is parse some news title from usatoday.
class Command(BaseCommand):
def handle(self, *args, **options):
html = urlopen('')
soup = BeautifulSoup(html, 'html.parser')
site_json=json.loads(soup.text)
for i in range(len(site_json)):
title = site_json[i]['title']
try:
Job.objects.create(
title=title,)
print('%s added' % (title,))
except Exception as e: print(e)
# print('%s already exists' % (title,))
self.stdout.write( 'job complete' )
My codes working perfectly but i tried to add schedule to run every 5sec. (its just testing)
import time
import schedule
from os import system
def sch():
class Command(BaseCommand):
def handle(self, *args, **options):
html = urlopen('')
soup = BeautifulSoup(html, 'html.parser')
site_json=json.loads(soup.text)
for i in range(len(site_json)):
title = site_json[i]['title']
try:
Job.objects.create(
title=title,)
print('%s added' % (title,))
except Exception as e: print(e)
# print('%s already exists' % (title,))
self.stdout.write( 'job complete' )
schedule.every(5).seconds.do(sch)
while True:
schedule.run_pending()
time.sleep(1)
In order to execute that py nothings happen and just blinking at shell. I dont have any outputerror log. Thats because i dont know what to do. How do I resolve this issue?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…