Пример #1
0
def home_view(request):
    context = {}
    context['user'] = request.user
    if request.method == 'POST':
        form = URLForm(request.POST)
        if form.is_valid():
            # Get url
            url = form.cleaned_data['url']

            # crawl
            # Very poorly managed. This should have some safety features
            # you should really just create a seperate crawl command to search important domains.
            # It should be running whenever the server is running
            found = mark_to_crawl(url)
            if not found:
                context['not_found'] = 'Site not found'

            # get links
            try:
                site = Website.objects.get(url=urlparse(url).netloc)
                context['pages'] = Webpage.objects.filter(website=site).all()[:10]
            except Website.DoesNotExist:
                # add 'please wait message to output'
                pass
    else:
        form = URLForm()  # An unbound form
    context['form'] = form
    return render_to_response('home.html', context, RequestContext(request))
Пример #2
0
def home_view(request):
    context = {}
    context['user'] = request.user
    if request.method == 'POST':
        form = URLForm(request.POST)
        if form.is_valid():
            # Get url
            url = form.cleaned_data['url']

            # crawl
            # Very poorly managed. This should have some safety features
            # you should really just create a seperate crawl command to search important domains.
            # It should be running whenever the server is running
            found = mark_to_crawl(url)
            if not found:
                context['not_found'] = 'Site not found'

            # get links
            try:
                site = Website.objects.get(url=urlparse(url).netloc)
                context['pages'] = Webpage.objects.filter(
                    website=site).all()[:10]
            except Website.DoesNotExist:
                # add 'please wait message to output'
                pass
    else:
        form = URLForm()  # An unbound form
    context['form'] = form
    return render_to_response('home.html', context, RequestContext(request))
Пример #3
0
def index():
    form = URLForm()
    timg = Image(False, "", "", "")
    botError = BotError(False, "")
    if form.validate_on_submit():

        url = form.query.data

        try:
            # resize image to 32x32 pixel image
            procImage = allcnn_predict.processImage(url)
            # transform to 32,32,3 matrix, feed to model
            category, prob = allcnn_predict.predictImage(procImage)

            timg = Image(True, url, category, prob)
            timg.toString()
        except ValueError as e:
            print(e)
            botError = BotError(True, e)
        except urllib.error.HTTPError as e:
            print(e.msg)
            botError = BotError(True, e.msg)

        return render_template("index.html",
                               title='VisionBot',
                               form=form,
                               botError=botError,
                               image=timg)

    return render_template("index.html",
                           title='VisionBot',
                           form=form,
                           botError=botError,
                           image=timg)
Пример #4
0
def get_url(request):
        if request.method == 'POST':
            form = URLForm(request.POST)
            if form.is_valid():
                url = form.cleaned_data["URL"]
                try:
                    r = requests.get(url)
                except requests.exceptions.RequestException as e:
                    print e
                    return HttpResponse("Connection failed")
                else:
                    content = r.content
                    list_counters = content.split("<br \>")
                    
                    for counter in list_counters:
                        if counter != "":
                            c = counter.split("=")
                            d = Counter(counter_name= c[0], counter_value= c[1])
                            d.save()

                    return HttpResponseRedirect('/counters_app/start')
        else:
            form = URLForm()

        return render(request, 'counters_app/URL.html', {'form': form})
Пример #5
0
def move(url):
    page = wiki.get_or_404(url)
    form = URLForm(obj=page)
    if form.validate_on_submit():
        newurl = form.url.data
        wiki.move(url, newurl)
        return redirect(url_for('.display', url=newurl))
    return render_template('move.html', form=form, page=page)
Пример #6
0
def getURL():
    form = URLForm()
    if form.validate_on_submit():
        # [...]

        print "input URL: %s" % form.url.data
        return redirect(url_for('getBS_img', imageurl=form.url.data))
    return render_template('enterurl.html', form=form)
Пример #7
0
def flow():
    """Route vers le lecteur d'URL pour flux rss/atom"""
    user_id = current_user.get_id()
    form = URLForm()
    if form.validate_on_submit():
        flow = Flow(url=form.url.data, user=user_id)
        flow.save()
    return render_template("flow.html", form=form)
Пример #8
0
def getBS_img_multi():
    import base64
    defaultURL = chooseDefaultURLfromList()
    imageurl = request.args.get('imageurl', default=defaultURL)
    #remove quotes in url if any
    imageurl = imageurl.strip('"').strip('\'')
    if not imageurl.startswith("http"):
        imageurl = "http:\\" + imageurl

    #number of clustering versions to show
    number_iter = request.args.get('iter', default=5, type=int)

    #SHOW_SIMPLER_IMAGES config from url
    SHOW_SIMPLER_IMAGES = request.args.get('show_simpler_images',
                                           default=False,
                                           type=bool)
    print "SHOW_SIMPLER_IMAGES --", str(SHOW_SIMPLER_IMAGES)

    #get data from image comment (comment, colors, drawn colors)
    #imageresponse = imageapp.commentOnImageFullMode(imageurl,number_iter,SHOW_SIMPLER_IMAGES)
    #REDIS enqueue blocking function
    #imageresponse = imageapp.commentOnImage(imageurl)

    job = q.enqueue(imageapp.commentOnImageFullMode, imageurl, number_iter,
                    SHOW_SIMPLER_IMAGES)
    # TODO: how long to wait?
    while not job.result:
        imageresponse = ''
    imageresponse = job.result

    imagecomment = imageresponse["comment"]
    maincolorstringslist = imageresponse["maincolorstringslist"]
    silhouettescores = imageresponse["silhouettescores"]
    colorboxes = imageresponse["colorboxes"]
    simplerimages = imageresponse["simplerimages"]

    #print "len(simplerimages):", len(simplerimages)

    #print silhouettescores
    #print len(silhouettescores)

    form = URLForm()
    if form.validate_on_submit():
        # [...]
        print "input URL: %s" % form.url.data
        return redirect(url_for('getBS_img_multi', imageurl=form.url.data))

    return render_template("getbs_img_multi.html",
                           imagecomment=imagecomment,
                           imageurl=imageurl,
                           maincolorstringslist=maincolorstringslist,
                           silhouettescores=silhouettescores,
                           colorboxes=colorboxes,
                           simplerimages=simplerimages,
                           SHOW_SIMPLER_IMAGES=SHOW_SIMPLER_IMAGES,
                           form=form)
Пример #9
0
def index(request):
    if request.method == 'POST':
        form = URLForm(request.POST)
        if form.is_valid():
            xml_url = form.cleaned_data["url"]
            redirect_url = reverse("heartbeatmatch.views.track") + "?url=" + urllib2.quote(xml_url)
            return HttpResponseRedirect(redirect_url)
        else:
            return render_to_response('hbm-index.html', {'URLForm': form}, context_instance=RequestContext(request))
    else:
        return render_to_response('hbm-index.html', {'URLForm': URLForm()}, context_instance=RequestContext(request))
Пример #10
0
def index():
    form = URLForm()

    # over here, form submission
    if request.method == "POST":
        if form.validate_on_submit():
            print("Got form! URL is:", form.url.data)
            reviews, data = backend.scrape(form.url.data)
            sys.stdout.flush()

            if (reviews is None):
                print("Something went wrong.")
                sys.stdout.flush()
                flash(
                    "Something went wrong, either invalid URL or internal server error."
                )
                return render_template("index.html", form=form)

            num_fake, num_real = 0, 0
            num_fake_stars, num_real_stars = 0, 0

            for review in reviews:
                predict, conf = backend.classify(review["rating"],
                                                 review["product_category"],
                                                 review["verified"],
                                                 review["review_text"])
                num_fake += 1 if predict == "FAKE" else 0
                num_real += 0 if predict == "FAKE" else 1

                num_fake_stars += review["rating"] if predict == "FAKE" else 0
                num_real_stars += 0 if predict == "FAKE" else review["rating"]

            product_data = {}
            product_data["percentage_fake"] = int(
                (num_fake / (num_real + num_fake)) * 100)
            product_data["raw_rating"] = round(
                (num_fake_stars + num_real_stars) / (num_fake + num_real), 2)
            product_data["adjusted_rating"] = round(
                (num_real_stars) / (num_real), 2)
            product_data["title"] = data["title"]
            product_data["price"] = data["price"]
            product_data["image_url"] = data["image"]
            product_data["url"] = form.url.data

            # return here index.html, but with the product info
            return render_template("index.html",
                                   form=form,
                                   product_data=product_data)
        else:
            flash("Invalid URL")

    # over here, form request
    return render_template("index.html", form=form)
Пример #11
0
def get_short_url():
    request_data = request.get_json()
    source_url = request_data.get('source_url', '')
    human_readable = request_data.get('human_readable', '')
    url_form = URLForm(source_url=source_url, human_readable=human_readable)
    if url_form.validate():
        if human_readable:
            return get_response_for_readable_url(request_data)
        else:
            return get_response_for_short_url(request_data)
    else:
        abort(404)
Пример #12
0
def createURL(request):
    if not admin():
        return HttpResponseRedirect(users.create_login_url('/blogs'))
    form = URLForm(request.POST)
    if form.is_valid():
        friendlyURL = FriendlyURL()
        friendlyURL.name = form.cleaned_data['name']
        friendlyURL.URL = form.cleaned_data['URL']
        friendlyURL.put()
        return HttpResponseRedirect('/blogs')
    else:
        return newURL(request)
Пример #13
0
def submit():
    error = None
    form = URLForm(request.form)
    print("url submitted : ", form.q.data)
    if (request.method == "GET"):
        return render_template("page.html", form=form)
    elif request.method == "POST" and form.validate():
        # print("url submitted : " ,form.q.data)
        inp(form.q.data)
    else:
        error = "WRONG URL!!!"
    return render_template("page.html", form=form, error=error)
Пример #14
0
def updateURL(request, key):
    if not admin():
        return HttpResponseRedirect(users.create_login_url("/blogs"))
    form = URLForm(request.POST)
    if form.is_valid():
        friendlyURL = FriendlyURL.get(key)
        friendlyURL.name = form.cleaned_data["name"]
        friendlyURL.URL = form.cleaned_data["URL"]
        friendlyURL.put()
        return HttpResponseRedirect("/blogs")
    else:
        return editURL(request, key)
Пример #15
0
def index():
	""" Главная страница """

	form = URLForm()
	if form.validate_on_submit():
		url = db.session.query(ShortURL).filter_by(full_url=form.url_string.data).first()
		if url:
			return redirect(url_for('short_page', short_url=url.short_url))
		else:
			new_url = ShortURL(full_url=form.url_string.data, short_url=random_url())
			db.session.add(new_url)
			db.session.commit()
			return redirect(url_for('short_page', short_url=new_url.short_url))
	return render_template('index.html', form=form)
Пример #16
0
def get_url(request):
    ''' This function grabs the url that the user inputs in the landing page
	    Then scrapes the page using requests and loads the values into databse '''

    if request.method == 'POST':
        form = URLForm(request.POST)
        if form.is_valid():
            url = form.cleaned_data["URL"]
            try:
                r = requests.get(url)
            except requests.exceptions.RequestException as e:
                return HttpResponse("Connection failed ", e)
            else:

                u = url_hash()
                u.url_hash = u._createHash(url)

                content = r.content
                list_counters = content.split("<br \>")

                for counter in list_counters:
                    if counter != "":
                        c = counter.split("=")
                        app_counter = c[0].split("_")
                        _app_name = app_counter[0]
                        a = app_name(url_hash=u.url_hash, app_name=_app_name)
                        d = Counter(counter_name=app_counter[1],
                                    counter_value=c[1],
                                    app_name=a.app_name,
                                    url_hash=u.url_hash,
                                    pub_date=parser.parse(c[2]))
                        a.save()
                        u.save()
                        d.save()

                return HttpResponseRedirect('/counters_app/start-apps/' +
                                            str(u.url_hash))
    else:
        form = URLForm()

    return render(request, 'counters_app/URL.html', {'form': form})
Пример #17
0
def index():
    if request.method == 'GET':
        form = URLForm()
        return render_template('index.html', form=form)
    if request.method == 'POST':
        source_url = request.form['source_url']
        human_readable = request.form['human_readable']
        data = {"source_url": source_url, 'human_readable': human_readable}
        if human_readable:
            return get_response_for_readable_url(data)
        else:
            return get_response_for_short_url(data)
Пример #18
0
def create():
	form = URLForm()
	if request.method =='POST':
		if form.validate():
			try:
				#check if site in database, if not create a new document
				site_id = mongo.db.links.find_one_or_404({'url':form.url.data})['site_id']
			except:
				#not the best way to do this, but for demonstrations purposes it gets the job done.
				site_id = ''
				for i in range(random.randrange(3,6)):
					site_id += random.choice(string.ascii_letters)

				data = {
					'site_id': site_id,
					'url': form.url.data
				}
				mongo.db.links.insert(data)
			
			flash('URL created! <a href="{0}" target="_blank">{0}</a> redirects to {1}.'.format(url_for("homepage", _external=True) + site_id, form.url.data))
			return redirect(url_for('homepage'))
Пример #19
0
def create():
    form = URLForm()
    if request.method == 'POST':
        if form.validate():
            try:
                #check if site in database, if not create a new document
                site_id = mongo.db.links.find_one_or_404(
                    {'url': form.url.data})['site_id']
            except:
                #not the best way to do this, but for demonstrations purposes it gets the job done.
                site_id = ''
                for i in range(random.randrange(3, 6)):
                    site_id += random.choice(string.ascii_letters)

                data = {'site_id': site_id, 'url': form.url.data}
                mongo.db.links.insert(data)

            flash(
                'URL created! <a href="{0}" target="_blank">{0}</a> redirects to {1}.'
                .format(
                    url_for("homepage", _external=True) + site_id,
                    form.url.data))
            return redirect(url_for('homepage'))
Пример #20
0
def add():
	urlform = URLForm(request.form)
	pform = PreviewForm(request.form)
	sourceform = SourceForm(request.form)
	curr=True
	print sourceform.validate()
	if urlform.validate_on_submit() and not pform.validate_on_submit():
		track = get_track_info(urlform.url.data)
		pform.songname.data = track.title
		pform.artist.data = track.user['username']
		pform.label.data = track.label_name
		if pform.label.data is None:
			pform.label.data = ''
		pform.year.data = track.release_year
		if pform.year.data is None:
			pform.year.data = ''
		curr=False
	elif sourceform.validate_on_submit():
		add_source(sourceform.source.data, sourceform.genre.data)
		return redirect(url_for("index"))
	elif pform.validate_on_submit():
		add_track(pform.url.data, current_user.id, "user", pform.songname.data, pform.artist.data, pform.genre.data, pform.label.data, pform.year.data)
	return render_template("add.html", urlform=urlform, previewform=pform, sourceform=sourceform, curr=curr)
Пример #21
0
def get_url(request):

	''' This function grabs the url that the user inputs in the landing page
	    Then scrapes the page using requests and loads the values into databse '''

        if request.method == 'POST':
            form = URLForm(request.POST)
            if form.is_valid():
                url = form.cleaned_data["URL"]
                try:
                    r = requests.get(url)
                except requests.exceptions.RequestException as e:
                    return HttpResponse("Connection failed ", e)
                else:

		    u = url_hash()
 		    u.url_hash = u._createHash(url)
                
                    content = r.content
                    list_counters = content.split("<br \>")
                    
                    for counter in list_counters:
                        if counter != "":
                            c = counter.split("=")
                            app_counter = c[0].split("_")
                            _app_name = app_counter[0]
			    a = app_name(url_hash = u.url_hash, app_name = _app_name)
                            d = Counter(counter_name= app_counter[1], counter_value= c[1], app_name = a.app_name, url_hash = u.url_hash, pub_date = parser.parse(c[2]))
                            a.save() 
                            u.save()
			    d.save()

                    return HttpResponseRedirect('/counters_app/start-apps/'+ str(u.url_hash))
        else:
            form = URLForm()

        return render(request, 'counters_app/URL.html', {'form': form})
Пример #22
0
def getBS_img():
    defaultURL = chooseDefaultURLfromList()
    imageurl = request.args.get('imageurl', default=defaultURL)
    #remove quotes in url if any
    imageurl = imageurl.strip('"').strip('\'')
    if not imageurl.startswith("http"):
        imageurl = "http:\\" + imageurl

    #number of clusters to use --TODO: do something with it
    number_clusters = request.args.get('clusters', default=5)

    form = URLForm()
    if form.validate_on_submit():
        # [...]
        print "input URL: %s" % form.url.data
        try:
            return redirect(url_for('getBS_img', imageurl=form.url.data))
        except Exception as err:
            print "error in form bit -- %s" % str(err)

    ##CALL TEMPLATE WITH JUST AVAILABLE DATA##
    ##The page then call /startimageanalysis to start the job and /result to update##
    return render_template('getbs_img2.html', imageurl=imageurl, form=form)
    '''
Пример #23
0
def index():
    form = URLForm()
    if request.method == 'GET':
        # form.process(MultiDict())
        return render_template('index.html', form=form)
    if request.method == 'POST':
        frm = urlparse(request.form['url'])
        ctx = {'schema': frm.scheme,
               'allowed_schemes': ALLOWED_SCHEMES,
               }
        if frm.scheme in ALLOWED_SCHEMES:
            key = random_key()
            cache.add(key, request.form['url'])
            ctx['url'] = key
        else:
            ctx['error_message'] = "Supported schemes are: " + ", ".join(ALLOWED_SCHEMES)
        return render_template('index.html', **ctx, form=form)
    else:
        return abort(400)
Пример #24
0
def create():
    form = URLForm()
    if form.validate_on_submit():
        return redirect(url_for('edit', url=form.clean_url(form.url.data)))
    return render_template('create.html', form=form)
Пример #25
0
def homepage():
    form = URLForm()
    return render_template('index.html', form=form)