get users current time using web.py - time

This may well be a silly question but I was wondering if its possible to get the current in time of a user who requests a page from a web.py application in the web.py application. I understand the difference between client side and server side scripting and that web.py is a server side framework but I know that some data is sent to the server when a page is requested and I was wondering if the user's time was such a piece of information.
For this specific case having access to the user's time is not a requirement but a nicety to add extra features if/when nits available.
Is this information retrievable? and if so how might i go about accessing it?

There is no way to do this with http headers.
Using IP: Check out this link using the IP to get local time. Look at this answer for some other python geolocation libraries.
Ask: Why not ask the user what their timezone is?
Client side JavaScript: Determine a User's Timezone

Related

Proxy / cache server for development purposes

I'm working on a mobile client. Dev backend server, I'm working with, isn't stable at all. It may be unusable for a full working day. Prod server is a bit better but still sometimes it doesn't work either. The other problem is it's much more difficult to use it in development. Besides that it's completely wrong to work like that. Basically these servers have been made for web, not for mobile. And it has other strange and annoying thing that destructs me from my primary work - token life time is only 60 seconds. That means if the app didn't refresh the token in that period the token dies. And next time you run the app you need to authorize from scratch. And that process takes centuries(((. May be I just don't understand how it works or something, but as I see web site just spams the sever every minute.
I was thinking how to fix this problem and started using mocking manually. But it's very annoying and time consuming either. The other idea is to use some kind of proxy / cache server that will send request to original server and if it fails return cached data. It seems that it may help in my situation. I'm not sure would such proxy / cache server be able to eliminate token problem. Basically I need to refresh it as soon as first token has been received. But who knows? May be I'm lucky enough?)
So the question: is there some simple to use proxy cache server that I will be able to run locally to achieve what I want?
The other opportunity is to write such proxy server myself. I have no experience in writing servers at all. But as a last chance I could try. The benefit of writing proxy server myself is that I should be able to "fix" token problem for sure. But I don't want to reinvent the wheel.
So any help and thoughts are appreciated.
Not entirely sure if this will solve your problem but let's give it a shot.
I myself have been programming against a rate-limited API. During development I often max out the allowed requests and have to wait before I could continue. I have developed a small caching proxy server that sits between your client and the server. It intercepts the requests and puts both the request and response in it's cache. Whenever it intercepts a request that it's already seen it will respond from cache without forwarding the request to the target server.
I'm not sure what your requests look like. The proxy that I build currently retrieves cache based on URL and HTTP Method, so that may or may not be what you need.
Here's the link to the GitHub repository: https://github.com/RobinvandenHurk/cache-proxy
Disclaimer: For if it wasn't clear, I am the author of this proxy

Laravel Fetch Real-Time from database

I have a market prices table, it updated every millisecond from a third-party service.
I need something to display the live prices to my HTML view, I don't want to use ajax
Asynchronous JavaScript probably is the easiest and lowest latency (best) solution although it still won't likely provide you to the millisecond accuracy.
Presenting the raw data source in a html frame that is repeatedly refresh via JavaScript may be an option depending on formatting needs but this has it's own challenges and is a bit of a hack.
You might be able to achieve this with static site generation task (rebuild) scheduling but you would be looking at even larger latency in that case, people would also need to refresh the page to see the updated data unless you refresh the page on an interval with this solution.
When dealing with markup the content will either need to be refreshed by JavaScript or by browser refresh.
To display data live, yes! websockets are the answer. Though you can't run them on the same server your default Laravel server relies. You'll need to create a different server via Artisan console or Task scheduler listening on a different port. Make sure your hosting provider supports the ability to listen over other ports than 80/443. You may need a VPS or something serverless to run such application.
The only reliable websocket PHP library which I know it has good integrity with Laravel is Ratchet.
Though I advise NodeJS with SocketIO when it comes to websocket applications.

Ajax without backend script

I have a simple database application in mind and I am thinking of making it browser-accessible instead of creating a standalone one.
I almost finished creating the DB schema in a PostgreSQL Server and I will now start developing. My first idea was using PHP or Ruby On Rails to manage the backend logic and interfacing with the DB, but since this application is fairly simple I think that I can easily implement all business and data manipulation logic with JavaScript or with the DB triggers.
So I am now wondering: is there a way to directly send the queries to a PostgreSQL Server, without server-side scripting?
More generally: can a PostgreSQL(9.3) Server receive the queries in Http requests and provide the results in Http responses?
I know this might sound stupid, and I am not looking for answers like "Use JS for presentation, PHP for logic and DB for data storage". I believe this is a lightweight solution for a very simple application, so I want to try it if possible!
Yes, That is possible.
What you can do is to send it via REST API. (post, get request ).
Here are some reference for you:
https://github.com/begriffs/postgrest
https://github.com/pgrest/pgrest
Please take a look at this for more HTTP API
[update!]
This idea is currently not possible (as I tought when I answered you before).
I tought it was possible after checking this node-postgres library written in javascript but it uses Node.js specific functions not present in the web browser as stated by the library's creator himself and this answer at stack overflow.
There is this package called browserify that exports a Node.js javascript file into a browser front-end ready javascript file. The problem with node-postgres + browserify is that it throw some errors during the browserification process, precisely when it tries to access libpq (an API written in C for accessing PostgreSQL).
I'm sorry I have mistaken you
Yet I still have a suggestion for you. You can try CouchDB if you really want to build a backendless/serverless application. It is natively RESTful, handles authentication and authorization at some extent, is opensource but unfortunately: NoSQL. It processes queries based on Map/Reduce paradigm and Mango query language so it's an entire different world for you to discover if you are used with SQL.
[old answer, I'm leaving it here for learning purposes]
Have you considered using a PostgreSQL driver for JavaScript? It is not RESTful, but it can connect to PostgreSQL and query it!
The library is called node-postgres and you can download it via npm
https://www.npmjs.com/package/pg
Just don't forget to enable SSL connection in the PostgreSQL server and in the client to avoid man-in-the-middle attacks.
An here's a tip: if you need an ACL for allowing or denying selects or inserts for specific users you can manage that through PostgreSQL user management and privileges. PostgreSQL has row level security, allowing you to define which rows in a table can be selected updated and deleted for a given set of users or groups.

Changing domain linked to a Selenium::Client::Driver instance

I'm using the Selenium Client (v 1.2.18) to do automated navigation of retail websites for which there exists no external API. My goal is to determine real-time, site-specific product availability using the "Check Availability" button that exists on a lot of these sites.
In case there's any concern, each of these checks will be initiated by a real live consumer who is actually interested in whether or not something's available at that store. There will be no superfluous requests or other internet badness.
I'm using Selenium's Grid framework so that I can run stuff in parallel and I'm keeping each of the controlled browsers open between requests. The issue I'm experiencing is that I need to perform these checks across a number of different domains, and I won't know in advance which one I will have to check next. I didn't think this would be too big an issue, but it turns out that when a Selenium browser instance gets made, it gets linked to a specific domain and I haven't been able to find any way to change what domain that is. This requires restarting a browser each time a request comes in for a domain we're not already linked to.
Oh, and the reason we're using Selenium instead something more light-weight (eg. Mechanize) is because we need something that can handle JavaScript.
Any help on this would be greatly appreciated. Thanks in advance.
I suppose you are restricted from changing domain because of same origin policy. Did you try using browser with elevated security privileges like iehta for internet explorer and chrome for firefox browsers. While using these modes of browsers, use open method in your tests and pass the URL which you want to open. This might solve your problem.

What is a better solution for save client machine time on server?

I need to save client machine time when he log in on my web application. For this I have 2 solution
Using javascript
Store the server time
System.DateTime.Now.ToUniversalTime();
and ask the user in which timezone he is in
TimeZoneInfo indTimeZone = TimeZoneInfo.Local;
return TimeZoneInfo.ConvertTimeFromUtc(date, TimeZoneInfo.Local);
What is the better solution to do this taks, using 1st one or 2nd one?
If there is any better solution then please give me.
To access the client's time, you have to use javascript. All server-based solutions can't access the client's clock.
So, there is no better solution, sorry.

Resources