David MENTRE | 14 Oct 2007 19:28
Favicon

Re: Questions

Hello Lyu,

Lyu ABE <lyu.abe <at> celery.ocn.ne.jp> writes:

> I'd like to know how I can retrieve questions, answers, votes, etc. I
> tried to use the "question_info" method, but I do not understand the
> server's reply because I only got a int value.

No, the question_info() method returns a quite complex data
structure. Here is part of its XDR (ONC-RPC) description:

struct response_t {
  response_desc_t r_info_desc;
  external_link_t r_info_link;
};

enum question_status_e { tagging_only = 1, public = 2 };

struct question_t {
  _int32 int q_timestamp;
  question_id_t q_id;
  question_desc_t q_desc;
  date_t q_info_limit_date; /* if set to zero, there is no limit date */
  question_status_e q_info_status;
  response_t q_info_responses<MAX_NUMBER_RESPONSES>;
  int q_info_num_votes;
  int q_info_elected_responses<MAX_NUMBER_RESPONSES>;
};

struct question_info_return_t {
(Continue reading)

Lyu Abe | 16 Oct 2007 02:06
Picon

Re: Questions

Hi David,

>> I'd like to know how I can retrieve questions, answers, votes, etc. I
>> tried to use the "question_info" method, but I do not understand the
>> server's reply because I only got a int value.
> 
> No, the question_info() method returns a quite complex data
> structure. Here is part of its XDR (ONC-RPC) description:

Okay, let's consider a simpler case. What about the 
max_question_id(cookie) function? The return value is of type:

struct max_question_id_return_t
{
     return_code_t max_question_id_rc;
     question_id_t max_question_id;
};

containing only a return code and the actual maximum question identifier 
on the server.

So what I do in PHP is:
1/ Generate the properly formatted message to send to the server:
$message = xmlrpcmsg("max_question_id", $cookie);

2/ Send the message...
$xmlrpc_res = $server->send($message);

... but here my $xmlrpc_res value has no particular type. Should I 
declare it as an array on the base of the max_question_id_return_t 
(Continue reading)

David MENTRE | 16 Oct 2007 09:41
Favicon

Re: Questions

Hello Lyu,

2007/10/16, Lyu Abe <lyu.abe <at> celery.ocn.ne.jp>:
> Diogene suggested to me to take a look at Augustin's code under Dupral
> (link or location?).

http://drupal.org/project/demexp

This is in the wiki. ;-)

https://demexp.org/dokuwiki/doku.php?id=en:start#drupal_module_for_demexp

I need more time (and a computer) to answer the other part of your question.

Yours,
d.
David MENTRE | 16 Oct 2007 09:47
Favicon

Re: Questions

Lyu,

2007/10/16, David MENTRE <dmentre <at> linux-france.org>:
> http://drupal.org/project/demexp

You can look at function _contact_demexp_server() and other functions
that call it.

However, from what I've read Augustin is using the xmlrpc() standard
call from PHP and not the xmlrpc external module, so the API is
probably quite different.

Yours,
d.
Lyu Abe | 17 Oct 2007 06:06
Picon
Favicon

Re: Questions

Hi David,

> You can look at function _contact_demexp_server() and other functions
> that call it.
> 
> However, from what I've read Augustin is using the xmlrpc() standard
> call from PHP and not the xmlrpc external module, so the API is
> probably quite different.

I did look at the _contact_demexp_server(), but I still do not 
understand why I cannot retrieve, for example, the max number of 
questions. In the Drupal code, a simple

$ds_max_question_id = _contact_demexp_server('max_question_id', 0);
echo $ds_max_question_id . 'server max';

can retieve the max number of questions. My PHP code is quite similar:

$message->xmlrpcmsg('max_question_id', $cookie);
$max_Q_ret = $server->send($message);
print $max_Q_ret->value();

but the returned response from the server has no meaning (like 
"379895601", or "415675044", or... I got a different value each time... 
so I think I'm totally off, but do not understand what I'm doing wrong). 
The XML response from the server is (for example),

<?xml version='1.0'?>
<methodResponse>
<params>
(Continue reading)

David MENTRE | 17 Oct 2007 18:54
Favicon

Re: Questions

Hello Lyu,

Lyu Abe <abe <at> magic.fr> writes:

> can retieve the max number of questions. My PHP code is quite similar:
>
> $message->xmlrpcmsg('max_question_id', $cookie);
> $max_Q_ret = $server->send($message);
> print $max_Q_ret->value();

You have made several errors in this code:
 * In "$message->xmlrpcmsg('max_question_id', $cookie);", you need to
   create a *new* xmlrpcmsg. So you need to use some code like
   "$message = new xmlrpcmsg('max_question_id', ... "

 * For the "$cookie", you need to encode it as XML-RPC value, using
   something like:
    "new xmlrpcval($cookie, "int")"
   Moreover, you forgot to pack it into an array() call.

   Above three points now give:
        $message = new xmlrpcmsg('max_question_id', 
				 array(new xmlrpcval($cookie, "int")));
	$max_Q_ret = $server->send($message);

 * You neew to convert the returned value in a scalar:
   "print $max_Q_ret->value()->scalarVal();"

This gives the following code:

(Continue reading)

Lyu Abe | 18 Oct 2007 11:53
Picon
Favicon

Re: Questions

David,

> -----begin Python example-----
> #!/usr/bin/python
> 
> from xmlrpclib import *
> import sys
> 
> login = "demo"
> password = "demo"
> url = "http://www.linux-france.org/cgi-bin/demexp-xmlrpc-demo"
> 
> print "Connect to server '%s'" % url
> s = ServerProxy(url)
> 
> print "login()"
> cookie = s.login(login, password)
> print " => %s" % cookie
> 
> 
> print "max_question_id()"
> max_question_id = s.max_question_id(cookie)
> print " => %s" % max_question_id
> 
> print "goodbye()"
> s.goodbye(cookie)
> -----end Python example-----
> 
> 
> Do you really want to use PHP? :-)
(Continue reading)

David MENTRE | 18 Oct 2007 16:46
Favicon

Re: Questions

Hello Lyu,

2007/10/18, Lyu Abe <abe <at> magic.fr>:
> I had to install mod python
> in order to make it work with it.
[...]
> Also, I tried to retrieve the "login" and "password" from the initial
> index.html using "import cgi":
>
> import cgi
> form = cgi.FieldStorage()
> if form.has_key["login"] ...
>
> But it didn't seem to work. Any suggestions?

It can't work because those two mode are incompatible. Either you are
running a CGI script (i.e. a Python script that is launch each time
Apache handles an URL pointing to this script), or either you use
mod_python and your code runs on a Python interpreter /within/ Apache.

In both cases you should able to get form variables and HTTP headers
info. But you need to look at the correct doc. Haven't doing that
myself, I can't help you further.

I suppose you are doing this only to get some HTML generated so you
can work on the CSS and the user interface.

However, if you plan to invest further in Python:
 * It might be wise to use an available framework the already do most
of the work to handle requests, prepare pages, etc. Django seems to be
(Continue reading)

Lyu Abe | 20 Oct 2007 06:59
Picon

Re: Questions

Hi,

>> import cgi
>> form = cgi.FieldStorage()
>> if form.has_key["login"] ...
>>
>> But it didn't seem to work. Any suggestions?
> 
> It can't work because those two mode are incompatible. Either you are
> running a CGI script (i.e. a Python script that is launch each time
> Apache handles an URL pointing to this script), or either you use
> mod_python and your code runs on a Python interpreter /within/ Apache.
> 
> In both cases you should able to get form variables and HTTP headers
> info. But you need to look at the correct doc. Haven't doing that
> myself, I can't help you further.

If I use the mod python "publisher" handler, then I can pass arguments 
from the HTML page.

HTML code:
<form method="POST" action="python/login.py/login">
<TABLE border="1" align="center">
<TR><TD>
<TABLE border="0" align="center">
<TR>
<TD align="right">Identifiant:</TD>
<TD><input type="text" name="login" size="20"></TD>
</TR>
<TR>
(Continue reading)

Lyu Abe | 18 Oct 2007 17:19
Picon

Re: Questions

Hi David,

> It can't work because those two mode are incompatible. Either you are
> running a CGI script (i.e. a Python script that is launch each time
> Apache handles an URL pointing to this script), or either you use
> mod_python and your code runs on a Python interpreter /within/ Apache.
> 
> In both cases you should able to get form variables and HTTP headers
> info. But you need to look at the correct doc. Haven't doing that
> myself, I can't help you further.

Okay...

> I suppose you are doing this only to get some HTML generated so you
> can work on the CSS and the user interface.
> 
> However, if you plan to invest further in Python:
>  * It might be wise to use an available framework the already do most
> of the work to handle requests, prepare pages, etc. Django seems to be
> a well known framework. We have listed some of them here:
> https://demexp.org/dokuwiki/doku.php?id=en:web_client_development_framework
> 
>  * You can use the Python ONC-RPC interface (Thomas Petazzoni's
> pydemexp) to talk to the demexp server. Once again, no hurry but for
> the long term it might be better.

Yes sure. I'll try to look into that.

I have a detail question: when using the question_info method, questions 
are returned as a list, but in reversed order (the last question as the 
(Continue reading)

David MENTRE | 18 Oct 2007 18:02
Favicon

Re: Questions

Hi Lyu,

2007/10/18, Lyu Abe <lyu.abe <at> celery.ocn.ne.jp>:
>  Is there a very simple way of addressing elements in a
> reversed way in a list?

Yep, use [::-1] operator ([:] operator with a negative step):
>>> l=[1,2,3,4]
>>> for i in l[::-1]:
	print i
4
3
2
1

Explanation in the Python library doc: http://docs.python.org/lib/typesseq.html

The Python doc (http://docs.python.org/) is very useful. Most of the
time, the thing you are looking for are either in the Language
Reference (http://docs.python.org/ref/ref.html) or in the Library
Reference (http://docs.python.org/lib/lib.html).

BTW, please note that there is no guarantee of the demexp server to
sort the list in a specific order (the current reverse order comes
from the current sequence of processing in the server, that might
change in the future). Each question contains its question number
(parameter q_id, qu['q_id'] in your code) and you should sort the list
according to that.

Yours,
(Continue reading)

Lyu Abe | 18 Oct 2007 18:16
Picon

Re: Questions

David,

> Yep, use [::-1] operator ([:] operator with a negative step):
>>>> l=[1,2,3,4]
>>>> for i in l[::-1]:
> 	print i
> 4
> 3
> 2
> 1
> 
> Explanation in the Python library doc: http://docs.python.org/lib/typesseq.html
> 
> The Python doc (http://docs.python.org/) is very useful. Most of the
> time, the thing you are looking for are either in the Language
> Reference (http://docs.python.org/ref/ref.html) or in the Library
> Reference (http://docs.python.org/lib/lib.html).

Yes thanks for the info. I was mostly looking at 
http://docs.python.org/tut/tut.html

> BTW, please note that there is no guarantee of the demexp server to
> sort the list in a specific order (the current reverse order comes
> from the current sequence of processing in the server, that might
> change in the future). Each question contains its question number
> (parameter q_id, qu['q_id'] in your code) and you should sort the list
> according to that.

Yes, I was thinking about that. There is also a method to retrieve 
questions by their IDs, right? Do you have any comments on which method 
(Continue reading)

David MENTRE | 18 Oct 2007 19:32
Favicon

Re: Questions

Hello Lyu,

Lyu Abe <lyu.abe <at> celery.ocn.ne.jp> writes:

>> BTW, please note that there is no guarantee of the demexp server to
>> sort the list in a specific order (the current reverse order comes
>> from the current sequence of processing in the server, that might
>> change in the future). Each question contains its question number
>> (parameter q_id, qu['q_id'] in your code) and you should sort the list
>> according to that.
>
> Yes, I was thinking about that. There is also a method to retrieve
> questions by their IDs, right?

You can use question_info() to get a specific id:
  question_info(cookie, q_id, 1)

> Do you have any comments on which method
> is preferable? (or not)

It depends heavily on your web framework and your web application logic.

If you display a single question (e.g. details on a question), it is
simpler to call a question_info() for the needed id and then do the
display.

If you want to list several questions, it is more efficient to use
question_info() to get needed information by groups (e.g. 200, use the
constant MAX_NUMBER_IDS [see demexp book ยง3.2.1] that you can get with
constants() RPC) and then extract and merge relevant information on
(Continue reading)

Lyu Abe | 18 Oct 2007 02:12
Picon

Re: Questions

Hi David,

Thanks for your helpful message!

> In such a case, please provide the *exact* and *complete* code you are
> using (like my example above). Otherwise it is quite complicated for me
> to understand what is the issue.

Okay.

> Do you really want to use PHP? :-)

Not necessarily. That's why I asked if you had suggestions about using
other languages. If you think Python is much more suited for that
purpose, then we'll use Python. My only comment is: except for coding
easyness and clarity, are there any major drawbacks using Python?... if
not, let's Pythonize.

Diogene, do you have any comments about this?

	Lyu.
David MENTRE | 17 Oct 2007 19:05
Favicon

Re: Questions

David MENTRE <dmentre <at> linux-france.org> writes:

> You have made several errors in this code:
>  * In "$message->xmlrpcmsg('max_question_id', $cookie);", you need to
>    create a *new* xmlrpcmsg. So you need to use some code like

In fact, I seems that the above code was sending the previous $message
doing the login(), that would explain the integer values you got as
returned values.

Yours,
d.
--

-- 
GPG/PGP key: A3AD7A2A David MENTRE <dmentre <at> linux-france.org>
 5996 CC46 4612 9CA4 3562  D7AC 6C67 9E96 A3AD 7A2A

Gmane