def scraper(): form = scrape_form() scraper_list = db.session.query(scrape_task).all() print(scraper_list) if form.validate_on_submit(): city = str(form.city.data).title() keyword = form.keyword.data provider = "Justdial" # Check if the city and keyword already exsists ? check_one = db.session.query(scrape_task).filter_by( city=city, keyword=keyword, provider=provider).first() if check_one is None: new_scraper = scrape_task(city=city, keyword=keyword, provider=provider, status=str(0), meta=str(1)) db.session.add(new_scraper) db.session.commit() session['mssg'] = " 👍 Scraper added to list." return redirect('/scraper') else: session[ 'mssg'] = " 🙃 Job already exsists. You can re-run the job from the list below , or run a new job with different parameters." return redirect('/scraper') return render_template('scraper.html', form=form, scraper_list=scraper_list, mssg=session['mssg']), 200
def scraper(): form = scrape_form() c_p = curr_project() project_curr = db.session.query(Project).filter_by(id = int(c_p)).first() scraper_list = list(project_curr.scrapers) if (int(curr_project()) > 0): if form.validate_on_submit(): city= str(form.city.data).title() keyword= form.keyword.data provider = "Justdial" # Check if the city and keyword already exsists ? check_one = db.session.query(scrape_task).filter_by(city = city, keyword = keyword, provider = provider).first() if check_one is None: new_scraper= scrape_task(city = city, keyword = keyword, provider = provider, status = str(0), meta = str(1) , project_sc = project_curr) project_curr.scrapers.append(new_scraper) db.session.add(new_scraper) db.session.commit() session['mssg'] = " 👍 Scraper added to list." return redirect('/scraper') else: session['mssg'] = " 🙃 Job already exsists. You can re-run the job from the list below , or run a new job with different parameters." return redirect('/scraper') return render_template('scraper.html', form= form, scraper_list = scraper_list, mssg = session['mssg']), 200 else: session['mssg'] = "No project selected . Redirecting to Projects page." return redirect('projects')