I am attempting to integrate Elasticsearch as a search engine for my static website. I use the Python package "Lektor" as my static website generator. I have been able to automate indexing all my webpages into Elasticsearch. Additionally, I am using Bootstrap to have a navigation bar on the top of the website. I have added the relevant search bar code from Bootstrap and it looks exactly like I want it to. My issue is with connecting the Bootstrap search bar to my Python code that queries the Elasticsearch cluster I have set up. I am hoping to process the search bar data and send it as an argument to my Python querying function. Is this possible? I know how to do this with Flask and setting up an endpoint, but in this case, I do not know how to set a specific endpoint for search that reacts to the search bar's form data.
Related
There's not much to be said about it except for the absence of any form of documentation having the least possible understandable way of doing it. Google's documentation only includes JS snippets that are good enough if I know how to use them in flask, django, or whatever python web framework.
With Flask and Django you make HTML pages in the end, and from Flask you can just return some HTML with the parameters you need.
The Google maps embed API uses an iframe, so you can display a map on your page like this:
<iframe
width="600"
height="450"
style="border:0"
loading="lazy"
allowfullscreen
referrerpolicy="no-referrer-when-downgrade"
src="https://www.google.com/maps/embed/v1/place?key=API_KEY
&q=Space+Needle,Seattle+WA">
</iframe>
"You can set the Maps Embed API URL as the src attribute of an iframe" says the doc with that in https://developers.google.com/maps/documentation/embed/get-started
In your Flask or Django view thing, you can then have for example the geocoordinates of the map place you want, gmaps has had a nice API for ages.
For adding markers, heatmaps etc. from code, the Maps client side JS api works, so you'd do that on the client but can get data for the front JS code from your Python backend. I have a simple old gmaps app that is browser side JS only, reads the marker data from a JSON, in https://github.com/playsign/insideoulu/blob/master/map.js
There is an extension in flask it only requires
Jinja
Flask
A google api key
And to use in your project use thy dependency manager and pip-install it like this
pip install flask-googlemaps
For how-to-use check out their documentation here it's pretty straightforward.
I have a Python program for customers to query price. Each time a customer can input some necessary information, the program will calculate and return the price to customer. Note: during the calculation process, the program also need to query a third party map service web API to get some information (such as google map API or other similar service).
I have a website developed using web development tools such Wix, Strikingly. It offers a capability to customize a web page by simply input a block of HTML codes. So, I want to study the possibility of using Django to convent my python program into HTML (incl. add some user interface such as text box and button), which can then be pasted into the website to form a unique webpage.
I am not sure if it is doable? Especially, the part of connecting third party map service API. Would Django be able to convert this part automatically to HTML as well? (how does it deal with API key and connection).
Python itself runs only on the console, and is meant to be the backend in site development, whereas HTML is meant only to be the frontend, so no calculation or data fetching. Wix is a frontend tool with some content management that offers customization but still in the frontends (html/css), and there's nothing more you could do with the content management other than using the built in table like feature. Trying to use the html generated by wix will be so much pain due to its css name optimization and making it quite unscalable.
If you don't wish to learn frontend building at all then you could look up other html generator tool for the frontend codes. From there, django itself is capable of building the entire website, using the html you generated as template, and passing the data you've computed into the templates. That's what Django is meant to do. In this case you would need to learn Django itself, which I would recommend if you intend to showcase your project as an interactive program rather just console logs.
Other alternatives include converting your python codes into javascript, which is capable of doing calculations and fetching from APIs, and you can include the javascript code directly in HTML with the tag.
I am trying to automate native android app using robot framework + appium with AppiumLibrary and was able to successfully open application ,from there my struggle begins, not able to find any element on the screen through UI automator viewer since the app which I was testing is web-view context and it shows like a single frame(no elements in it is being identified) . I have spoken to dev team and they gave some html static pages where I could see some element id's for that app. So I have used those id's ,But whenever I ran the test it throws error as element doesn't match . The same app is working with java + appium testNG framework. Only difference I could see between these two is, using java + appium framework complete html code is getting when we call page source method for the android driver object but in robot its returning some xml code which was displayed in UI automator viewer(so this xml doesn't contain any HTML source code with element id's and robot is searching the id's in this xml code and hence it is failing). I am totally confused and got stuck here. Can some one help me on this issue.
Switch to (webview) context resolved this issue.
I'm trying to scrape search results from a number of websites. The problem is that not all of these sites return their search results as plain html text, a lot of it is dynamically generated with with JS, AJAX, etc. However, I can see exactly what I need by looking at the page with the Firefox inspector, since the scripts have all run and modified the html.
My question is: is there a way for me to download a webpage AFTER allowing the scripts to run, or at least get them to run locally. That way, I'd get the final html.
For reference, I'm using python.
Possible duplicate. In that case the question is with php and JS.
Sure, you have to provide some enviroment for scripts (js) to run and often to return a test value to target server. It's not that easy for the server side languages. So today for this we mostly leverage browser driving or imitating tools mentioned there.
I've found for you the python analog to v8js php plugin: PyV8.
PyV8 is a python wrapper for Google V8 engine, it act as a bridge between the Python and JavaScript objects, and support to hosting Google's v8 engine in a python script.
If properly configured, your scraper:
Gets site's js
Evaluates this js thru the given plugin
Gets access to target html for further parse.
I have a question regarding how to handle datastore data coming from a Google App Engine python project with Jinja2 templating for use in a custom Polymer element.
I am using the simple getting started demo on the Polymer website. I have successfully transferred that existing project to my Google project on App Engine and its working live as I want. I am now attempting to use, with polymer, the values passed from my server via the Jinja2 template method; so I can drop in my Datastore query using {{ stuff }}.
However I noticed that the scope of this data is not reaching the imported files of my Polymer elements. So my custom polymer elements cant see these objects being passed from the server, but the main page which is loaded as the template can use them fine as expected.
What is the correct way to handle passing Datastore into polymer when on app engine? It seems a waste to create a post-service like in the tutorial when I have already queried for the client all my info via python and Datastore and passed it in via templating?
Now that polymer is focusing on single page application(SPA) format, this question has become sort of depreciated as using Jinja2 templating and something like the Polymer Starter Kit brings up other issues of url handling.
In either case, I created simple functions on the App Engine python side to allow me to post/get json objects from the server to some simple javascript. I used the web component iron-ajax to handle the firing of the api calls from the polymer pages.