Getting html content api with laravel - laravel

I need to develop an application get html content from certain urls and shows them in my own web app.
UI web application will be laravel 5.3 its ok. But the thing is key pointhere that retrieves data from urls(read and parse html content of via url)
and writes it to postgresql db migth be developed within laravel also ?
Before I decide to create this post I feel had to make an web service in python and read url and writes to db and read them within laravel web application. Which one is better or more efficient?
Besides them I also wonder that is possible develop such a web service in laravel

You can use ixudra/curl package. It's powerful, easy to use and you will be free to do anything you want. You can also save results into database. Make sure php-curl module installed on your php before you use this package. there is a pacakge named Guzzle and you can use that package but it's a little bit complicated than ixudra.
when you get html content from requested urls. You can parse the content with yangqi/htmldom package.

Related

Firefox Extension - Database access

I want to make a Firefox extension that can store and retrieve data from a database. However I've only been finding solutions that would work locally for each user. I'd like every user to have access to the same database.
Is that possible?
It is possible to access remote SQL databases like MySQL and PostgreSQL with node.js modules, but it is more sensible to create REST API front ends to your databases and call them from the extension. Exposing the SQL calls directly in your web extension is not a good idea. It is basically bad security practice and will expose your database to hackers.
You will also need your addon to pass Mozilla's approval process if you are going to distribute publicly and I doubt the reviewers will be pleased to see raw SQL calls in your extension's code.
The more sensible way is to update the database is through a REST API front end.
A simple example on how to create a REST API for a Postgres database can be found at Node.js, Express.js, and PostgreSQL: CRUD REST API example - LogRocket Blog and this playlist show how to create a REST interface in a Firefox extension - Build a Firefox Extension from Scratch that integrates with Node.js - DEV Community
The above database example is quite simple. For real world use you will need a more advanced REST framework for your API which sanitizes the data before inserting it into the databasse. You have more reading to do here.
However if you need to make SQL calls directly from your extension which I still don't advise, you can include some packages from node.js in your web extension, and use browserify which extracts and packages the modules needed into your extension. Your addons though had better be for private or in-house use, not for public distribution.
Some nodejs modules for database access are - https://github.com/mysqljs/mysql, https://node-postgres.com/ and https://www.npmjs.com/package/pg.
Just a little advice. Feel free to ignore it if you have nothing to do with it. Your question sounds quiet generic. You should learn and doing it by yourself first and only ask here when there are specific issues you're stuck with.
By "locally", I think you mean via Web SQL or IndexedDB. They're called local database and their behaviors are totally different from what you're looking for.
I should haven't need to tell you to do this. Just in case. Of course first thing first you need to know how website is working for both front end and back end, not just local stuff, especially how they're communicating between each other. So you should know about HTTP request, Javascript, and AJAX.
What has it to do with Firefox extension?. Not just Firefox, browser extension is just another type of web page that overlaying the opened web page in all kind of browser. In Firefox the opened page is called activeTabs. The only difference from regular web page is you need to signup your account first, manifest.json file as your project root file, and it compile from command line with web-ext tools. In case if you're facing Cross-origin resource sharing (CORS) restriction, follow instructions HERE and allow the URL on server side.

Trigger Laravel Scout update from outside Laravel

I have a Laravel backend which basically works as an API and dashboard for my database and its data. The data updated daily using a Python script directly to the database. Is there any way to trigger a Laravel Scout update (so that the row is updated in Algolia as well) outside the PHP project?
The only alternative I thought was to use a Laravel api to handle the changes between the python script and the database so that only Laravel can communicate directly to the database.
However, I would really prefer if there was a way to add a listener or whatever to that without using Laravel in between since the python script is REALLY fast.
There are two ways for that:
1). You can use Laravel API to update Algolia entries into database.
2). Maybe you can use Algolia Python Library.
I suggest you to use Laravel API. You can simply call API URL from Python Script. You need to write clear PHP code of Laravel controller API, because python is fast and it will need to communicate fast with api.
Also: You can simply use Python module named flask to connect to your laravel database and make changes what you want in database. (Every database can be managed from different programming languages such as PHP, Ruby on Rails, Python and etc.)
Only laravel can't communicate to your database, it can be done from Python too (But of course it's mainly possible from laravel too).
If you want to reindex everything, which seems to be the best way for you, I would just execute php path/to/artisan scout:import "App\Model" via Python.
If you want to update each model, because you will only edit a very limited number, like Giorgi said, I would use the Algolia Python client and call Algolia's API directly. It should be very easy to write.
https://github.com/algolia/algoliasearch-client-python

Openerp or odoo use ajax to send POST and GET data ? without refreshing

I want to know the technology used in ODOO(Openerp) to send POST and GET data without refreshing the page: because I don't see any AJAX code !!
Odoo is using http POST/GET requests to update the user interface. A combination of javascript making requests on the page and controllers responding. Odoo also uses longpolling to allow the server to provide updates to the client.
Take a look at the web addon
Of particular note would be
addons/web/controllers/main.py
and
addons/web/static/src/js
The js directory mentioned above (i am sorry there is a lot there). Defines how the standard ui widgets work (and much more). Most of the files are reasonably named to give you an indication of what is going on in each file.
You will also want to look at the framework directory within the above noted directory.
There you will find ajax.js which (you guessed it!) is the Odoo ajax module.
NOTE: The above directories are similar in Odoo8 however Odoo9 and Odoo10 have the above structure. Odoo8 does not have an ajax.js (to my knowledge) .

Looking at building an app using Laravel and Ionic Framework - some initial questions

I'm currently building a web app using Laravel 5.1 and would like to start creating a native application so that my users can use their phones. I have decided that using the Ionic Framework is likely the best approach for the app and just have a few questions on marrying the two together.
I've got routes in Laravel that looks like this example:
app.dev/geckos - This is a GET request.
Which takes the currently authenticated user, uses their ID and fetches all geckos that match their user ID. It does return a blade view however.
I assume that when working with something like Ionic, the GET request would need to return JSON instead on order to loop through properly?
Is there a way that I can alter my controller to serve JSON based on if the route was something like this instead:
app.dev/api/v1/geckos
Both routes would use the GeckoController#index method, ideally I just don't want to repeat the code.
I'm fairly new to Laravel and very new to Ionic. So if I'm over complicating this theory please let me know.
Any information is appreciated on this,
Andy
Another solution which I used is to have 1. application in Laravel, which is a RESTful JSON API. Then you would have 2. Web app (in AngularJS) and 3. Mobile app in Ionic (which is based on AngularJS).
So you will create two separate applications, mobile and web, which both communicate with the same JSON API. The web would be a single-page AngularJS application, so that way you can reuse all the Angular services which communicate with the API, maybe even some controllers between your mobile Ionic and Web application.
You will save some time when creating two separate responses for mobile/web application, since you would create only one: JSON response. AngularJS will take care of rendering in both applications, that way you won't have to create separate templates for web applications in Blade, instead make all the rendering using Angular in both applications. There will be some nuances in rendering of the same content in Web and Mobile app, but it would only require creating separate js directives/css styles/html templates for both applications, using Blade you wouldn't be able to reuse any view related code between applications. Also you will be able to use the same Authentication method for both applications.
To sum up, this solution should be cleaner then your solution because you will be able to reuse backend entirely between the applications, reuse a lot of fronted stuff (like input validation code, services, filters,..), reuse Authentication and introduce looser coupling and have much clearer structure then the ugly response type switch in controllers.
EDIT:
So this can be a rough example of the structure of such project:
1. API - REST in Laravel, returning JSON
-Controllers
-Session // actions CREATE, DELETE
-User // actions CREATE, VIEW, UPDATE, DELETE..
-Gecko
2. JS application - Angular App, for both mobile and web app
-common //controllers, services, filters - most of the frontend logic which reusable between both applications
-controllers.js
-services.js
-filters.js
-mobile //this part can be hosted on some server or part of the mobile application
-app.js //separate configs for mobile app
-controllers.js //controllers only for mobile app
-directives.js
-web
-app.js //separate configs for web app (links to HTML template URLS,...)
-controllers.js //controllers only for web app
-directives.js
-services.js //or even services only for web app
3. WEB APP
-HTML Templates - bunch of static .HTML files
-Home
-Login
-Register
-Gecko
-Gecko Views...
-Some index file with layout template, which includes everything from js/common and js/web, entry point to your web application
4. MOBILE APP
-www
-index.html // must include everything from js/common and js/mobile
-templates
-Gecko
-Gecko Views...
But the structure may vary significantly, depending on what part of mobile application you want to have hosted on web server and which should be available offline, or how you want to host it, how detailed the structure might be..
Doing this would be messy because your single controller action will be returning two totally different responses.
However if you go down this route, you could add an additional header to the request from the mobile app, and then check for this to switch the response.

Parse.com as CodeIgniter Backend

I have googled and searched SO for the title above but didn't get much help. I am new on backend side (usually working on frontend), and my boss suddenly want to use Parse for our backend. My questions are:
Is it possible to use it with CodeIgniter? A friend of mine suggested to discard CodeIgniter if I use Parse.
If it is possible, do I just need to make a call to the API through CI's controller to post/get data?
Thanks.
Add the following lines to the head of all the pages that require Parse:
<script src="http://www.parsecdn.com/js/parse-1.2.8.min.js"></script>
In your code, before using any Parse classes, add the initialization call with your Application ID and JavaScript key:
Parse.initialize("XVRsi5WgBbUrEXNc6zfGnvNbSFDmWD9sSda2X3iP", "XeuUDEzRJGOS5NtpBdeeswdRWDu3olmuMJvO9yN2");
If you are converting an existing Backbone application to use Parse, read the conversion instructions.
https://www.parse.com/docs/js_guide#convert

Resources