0

I am working on an analysis project. I have to fetch the news daily from some news channel. I have written a python script in my Django views which are used to fetch the news every day. What can I do in my script so that it runs automatically at 11:30 pm. Here is my script:

def ndtv(request):
    url = 'https://www.ndtv.com'
    resp = requests.get(url)
    soup = BeautifulSoup(resp.text, 'html.parser')
    i = 1
    data = ""
    da = []
    d1 = []
    href = []
    date = []
    d = datetime.now() - timedelta(1)
    for x in soup.find_all('a'):

        try:
            n = x.text.strip()
            n2 = x.get('href').strip()
            if (len(n) > 60):
                d1.append(n)
                href.append(n2)
                resp = requests.get(n2)
                soup2 = BeautifulSoup(resp.text, 'html.parser')
                for x in soup2.find_all('span'):
                    if x.get('itemprop') == "dateModified":
                        y = x.text[9:22]
                        date.append(y)
                        # print(n,x.text[9:])
                        y = y.lstrip(':')
                        y = y.rstrip('I')
                        if (dateparser.parse(y) > d):
                            qs = NDTVdb(title=n, href=n2)
                            qs.save()

                            print(n, y)
                            break
        except:
            p = 1
    return HttpResponse("<h1>Success NDTV</h1>")

When I run this script fetches all the title of today news and save it to my database. The URL is following

http://127.0.0.1:8000/news/ndtv

Please help me to run it automatically at 11:30.

imsaiful
  • 1,556
  • 4
  • 26
  • 49

0 Answers0