So I've conntected GMail API to my Django project. When I run quickstart.py alone in PyCharm it runs and works perfectly (that's the script that opens a new tab with GMail log in).
Great but now I have to give a user an opportunity to do the same. So I decided that I'll create a button and with pressing that button the quickstart.py will run and user will log in.
I tried that by creating an action.
Then I tried a usual 'a' tag.
And in both cases was error "Not found".
Also I even tried to run an php where I execute .py script.Sounds crazy.
<?php
echo exec('/quickstart.py');
?>
But the error is the same. I've also tried to play with url.py and write paths. I think I don't understand something. Please, explain.
So again and shortly: Press button -> Run quickstart.py
Seems like you have not to run quickstart.py, but create there some function, import your from quickstart import your_function into your views.py and call that your_function from your_custom_view.
Simplified logic like that:
from quickstart import your_function
def your_custom_view(request):
button_was_pressed = request.GET.get("button")
if button_was_pressed:
your_function()
return HttpResponse("Button pressed")
else:
return HttpResponse("No button pressed")
And make your Button work like a link (if you dont need a POST request), smth like:
Button
NOTE: This is not working code, but simplified logic, with so short information that you gave.
UPDATE 1:
settings.py:
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
views.py:
from your_project.settings import BASE_DIR
path_to_json = os.path.join(BASE_DIR, r'client_secret.json')
flow = client.flow_from_clientsecrets(path_to_json, SCOPES)
Related
Is there a reasonable solution to stream a live Video from my PiCamera to an apache2 Server. I want that I can activate the stream using a button on the server and deactivate it the same way. However, I looked up a lot of solutions but didn't find one that belongs to my problem. Maybe someone here knows how to solve it.
On the apache2 server, I use Html, PHP and CSS. I use the PHP language to configure my other buttons with a python script.
Here you can see my PHP code that I use to activate a script:
<html>
<head>
<form method="post" >
<input type="submit" value="Schiessen" name="schiessen">
</form>
<title>MUW</title>
</head>
<body>
<?php
if(isset($_POST["schiessen"]))
{
$command = escapeshellcmd("/var/www/html/runMotors.py");
$output = shell_exec($command);
echo $output;
}
?>
</body>
Here is an example how I want that my server looks like. Most important is that in the middle is a sort of display which shows the live stream. It is very important that you can still use the buttons even if the camera is on. Therefore the camera display should be such as a rectangle in the middle.
You can use flask too. That is web framework for python.
for example from the flask home page that is given above:
from flask import Flask, escape, request
app = Flask(__name__)
#app.route('/')
def hello():
name = request.args.get("name", "World")
return f'Hello, {escape(name)}!'
#app.route('/run_motors')
def run_motors():
# method calls here.
return
app.run(host='localhost', port=3000)
Your python code will listen to the port that specified by you (5000 is the default one of flask) and when HTTP request comes to the specified route (in this situation the route is '/run_motors') it will make another method calls.
I'm a bit lost at the moment and I hope that you can help!
I try to recognize people with OpenCV in Python. This is working so far. With the id of the recognized person I want to display information which belong to her or him.
For that I tried something like this:
1)
import webbrowser
webbrowser.open('http://mysite/index.php?userID=XYZ', new = 0)
But although I wrote the "new = 0" it opens a new browser tab everytime an other userID stands in the link.
2) An other approach was to send information via a http post request to the website like:
url = 'http://mysite/index.php'
query = {'personID': XYZ}
res = requests.post(url, data=query)
But doing this I don't have any idea how to work with this post command in my PHP code so it refreshes the site with the data belonging to user XYZ..
May you help me please?
Kind regards
Edit1 - START:
A small php example with using GET parameters would be something like this
<?php
echo("<html><head><title></title></head><body>");
if ($_GET['userID'] == 1) {
echo("<div id='userContent'>Hello User 1</div>");
}
else if ($_GET['userID'] == 2) {
echo("<div id='userContent'>Hello User 2</div>");
}
else {
echo("<div id='userContent'>Public, non user specific information</div>");
}
echo("</body></html>");
?>
But at this point I don't know how to make this site to a dynamic one which shows different information when Python sends a request..
Edit1 - END
This is not possible in webdriver currently. The 0 flag refers to the window, not the tab. See a discussion of this on reddit here. Another question also asked this on Stack Overflow but got no answers.
It is possible however with the much more feature rich package Selenium.
import time
from selenium import webdriver
link1="http://mysite/index.php?userID=ABC"
link2="http://mysite/index.php?userID=XYZ"
driver=webdriver.Firefox()
driver.get(link1)
time.sleep(5)
driver.get(link2)
Selenium does require some installation steps: http://selenium-python.readthedocs.io/installation.html
Regarding using requests, there's no reason you can't do a GET request so you don't have to worry about handling a post request:
import requests
url = "http://mysite/index.php?userID=ABC"
res = requests.get(url)
print(res.text)
Without seeing more of your php code or knowing more details, it is hard to say what approach is best for you but this should get you past the issues you mentioned.
i'm trying to create a php test to check if a specific ajax is executed, but i can't find anything that can help me.
I'm fine even if i can check if the method, whom triggers the ajax request, is called (but i think is not possibile to mock js functions with codeception).
A little example to explain better:
let's assume i have my online page: http://example.com with the following js
var log = {
execute: function(){
// AJAX CALL HERE
}
};
log.execute();
With the test i would like to know if log.execute() is executed, so in codeception i can do something like:
$I = new AcceptanceTester($scenario);
// Opening page
$I->amOnUrl('http://example.com');
// Checking if log is invoked
$I->wantTo('Check if log is invoked');
// Something to understand if a method is executed
$I->???('log.execute()');
Otherwise, i'm fine if there is a method to take the browser network activity and then regex it (do not suggest proxy, don't wanna go there).
I'm open to any kind of solutions, even to use a different testing system (with php)
Edit: i forgot to say that i'm using selenium with chromeDrivers
Thanks for your time
I dont know how to explain my need, and neither which key words to use to find a solution on google, so i'll give an url to be more clear:
check an IP (click on: Check your current IP address)
I'ld like, by using this website for example, getting somes informations after all the processus are terminated.
I tried with "file_get_contents" and with "cURL functions" but i did not find a way to do it, i always get the original source code.
Any idea ?
EDIT:
<body onLoad="setTimeout('get_my_blacklist()', 60000)">
...
...
<?php
echo '<iframe id="my_iframe" src="http://multirbl.valli.org/lookup/'.$ip.'.html">';
?>
...
...
<script>
function get_my_blacklist()
{
//function to get the content after somes secondes.
}
</script>
Here is the new code i tried thank to #Ludovic for is iframe idea.
Still working on it, i'll tell you if its working or not to solve my issue.
Edit2: Whatever how i try, i didnt find a way to get the containt of my frame window.. And even if i'ld succeed, i dont know how i can update my database if do it with JQuery/Javascript
First the page should have been construct by server script like PHP, at this step you have all IP requested then the page is modified by JQuery script who seems to query each IP.
The second step is an asynchronous script so you can't know when the page is effectively finished to construct.
My problem is I need to fetch FOOBAR2000's title because that including information of playing file, so I create a execute file via Win32 API(GetWindowText(), EnumWindows()) and it's working good.
TCHAR SearchText[MAX_LOADSTRING] = _T("foobar2000");
BOOL CALLBACK WorkerProc(HWND hwnd, LPARAM lParam)
{
TCHAR buffer[MAX_TITLESTRING];
GetWindowText(hwnd, buffer, MAX_TITLESTRING);
if(_tcsstr(buffer, SearchText))
{
// find it output something
}
return TRUE;
}
EnumWindows(WorkerProc, NULL);
Output would look like "album artis title .... [foobar2000 v1.1.5]"
I created a php file like test.php, and use exec() to execute it.
exec("foobar.exe");
then in console(cmd) I use command to execute it
php test.php
It's working good too, same output like before.
Now I use browser(firefox) to call this php file(test.php), strange things happened.
The output only foobar2000 v1.1.5, others information gone ...
I think maybe is exec() problem? priority or some limitation, so I use C# to create a COM Object and register it, and rewrite php code
$mydll = new COM("FOOBAR_COMObject.FOOBAR_Class");
echo $mydll->GetFooBarTitle();
still same result, command line OK, but browser Fail.
My question is
Why have 2 different output between command line and browser. I can't figure it out.
How can I get correct output via browser.
or there is a easy way to fetch FOOBAR2000's title?
Does anyone have experience on this problem?
== 2012/11/28 edited ==
follow Enno's opinion, I modify http_control plug-in to add filename info, original json info is "track title".
modify as following
state.cpp line 380 add 1 line
+pb_helper1 = pfc::string_filename(pb_item_ptr->get_path());
pb_helper1x = xml_friendly_string(pb_helper1);
# 1: when firefox opens the php and it gets executed, it the context depends on the user which runs the php-container (apache), this is quite different from the commandline call which gets executed in your context
# 2 and 3: there seems to be more than one way for getting the title: use the foobar-sdk and create a module which simply reads the current title per api, then write your result in an static-html-document inside your http-root-folder OR use the http-client inside the sdk, with it, you do not need a wabserver, even better use a already implemented module: for instance foo_upnp or foo-httpcontrol
Good luck!
If your webserver runs as a service, in windows you need to enable "allow desktop interaction" for the service. Your php script runs as a child of the webserver process when requested via browser.