Surya K | 1 Jul 2012 14:34

How to authorize my application to use Google API

I am building a Facebook application using Django where I am using Blogger API. So, all I want is to just read the data from a public blog (my blog).


I tried to read the documentation and found that we have 3 types of authentication mechanisms (ClientLogin, OAuth, AuthSub Proxy). As I can't directly put login credentials in the application (insecure), I have only one option to use. i.e., OAuth.


The tricky part of my project is, the "users"(facebook users) should be able to access my data without providing any authorization information to Google. However, in the eyes of Google - OAuth, as I am pulling data from blog to display to public, I am considered as "user" who needs to authorize the application when ever someone opens the app on facebook, which is completely absurd...


So, there might be two ways to do this:


  1. I should be able to pull data from blog without any authorization of user..

How can I do it? If not


  1. I should be able authorize my application internally for OAuth so that facebook users can access data without providing any information to google.

How can I do this?? If possible, is this a secure way?



  • I am quite new to OAuth, Google API.. so, please suggest the best and secure way..
_______________________________________________
Tutor maillist  -  Tutor <at> python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
Sean Carolan | 1 Jul 2012 22:49
Picon
Gravatar

Python XML for newbie

I'm trying to parse some XML data (Book titles, ISBN numbers and
descriptions) with Python.  Is there a *simple* way to import an XML
file into a dictionary, list, or other usable data structure?  I've
poked around with minidom, elementtree, and "untangle" but am not
really understanding how they are supposed to work.

Here's some sample data:

<xml>
<fields>
<field>
<name>Title</name>
<id>2</id>
<count>1</count>
<type>11</type>
<search>true</search>
<hasnumber>false</hasnumber>
</field>

...several more fields, then there are the items...

</fields>
<items>
<item>
<id>108</id>
<data>
<datum>
<index>1</index>
<field>2</field>
<value>Essential System Administration</value>
</datum>

For starters, I'd like to be able to just print out the list of titles
in the XML file, using the correct XML parser.  I don't mind doing
some research or reading on my own, but the official documentation
seems terribly confusing to me.

http://docs.python.org/library/xml.dom.minidom.html

Any pointers?
_______________________________________________
Tutor maillist  -  Tutor <at> python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Alan Gauld | 2 Jul 2012 01:10

Re: Python XML for newbie

On 01/07/12 21:49, Sean Carolan wrote:
> ... Is there a *simple* way to import an XML
> file into a dictionary, list, or other usable data structure?

The simplest way using the standard library tools is (IMHO)
elementtree. minidom is a complex beast by comparison,
especially if you are not intimately familiar with
your XML structure.

However hthere are some other add-in packages that are
allegedly much easier still.

But I'd start with the etree tutorial (of which
there are many variations on the web):

The original:
http://effbot.org/zone/element-index.htm

My preference:
http://infohost.nmt.edu/tcc/help/pubs/pylxml/web/index.html

You may not need anything else...

--

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

_______________________________________________
Tutor maillist  -  Tutor <at> python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Sean Carolan | 2 Jul 2012 01:14
Picon
Gravatar

Re: Python XML for newbie

> The simplest way using the standard library tools is (IMHO)
> elementtree. minidom is a complex beast by comparison,
> especially if you are not intimately familiar with
> your XML structure.

Thank you, this is helpful.  Minidom is confusing, even the
documentation confirms this:
"The name of the functions are perhaps misleading...."

> But I'd start with the etree tutorial (of which
> there are many variations on the web):
>
> The original:
> http://effbot.org/zone/element-index.htm
>
> My preference:
> http://infohost.nmt.edu/tcc/help/pubs/pylxml/web/index.html

I'm going to work through those and see what I can come up with.
_______________________________________________
Tutor maillist  -  Tutor <at> python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Sean Carolan | 2 Jul 2012 04:31
Picon
Gravatar

Re: Python XML for newbie

> Thank you, this is helpful.  Minidom is confusing, even the
> documentation confirms this:
> "The name of the functions are perhaps misleading...."
>
>> But I'd start with the etree tutorial (of which
>> there are many variations on the web):

Ok, so I read through these tutorials and am at least able to print
the XML output now.  I did this:

doc = etree.parse('computer_books.xml')

and then this:

for elem in doc.iter():
    print elem.tag, elem.text

Here's the data I'm interested in:

index 1
field 11
value 9780596526740
datum

How do you say, "If the field is 11, then print the next value"?  The
raw XML looks like this:

<datum>
<index>1</index>
<field>11</field>
<value>9780470286975</value>
</datum>

Basically I just want to pull all these ISBN numbers from the file.
_______________________________________________
Tutor maillist  -  Tutor <at> python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

David Kidd | 2 Jul 2012 04:56
Picon

Re: Python XML for newbie

On Mon, Jul 2, 2012 at 12:31 PM, Sean Carolan <scarolan <at> gmail.com> wrote:
How do you say, "If the field is 11, then print the next value"?  The
raw XML looks like this:

<datum>
<index>1</index>
<field>11</field>
<value>9780470286975</value>
</datum>

Instead of iterating over the whole tree, grab all the <datum> elements then retrieve the <field> child, check the field value, and if '11', then pull the <value> value.
_______________________________________________
Tutor maillist  -  Tutor <at> python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
Greg Nielsen | 2 Jul 2012 06:21
Picon

Math Function and Python

Hello Tutor,
 
     I'm having some trouble with a mathematical function in my code. I am attempting to create a realistic acceleration in an object, slower to speed up at its min and max speeds and fastest in the middle. To keep the math simpl(er), I just wrote this function for a parabola, which models the acceleration of the object. Y is the acceleration and X is the current speed of the object.
 
Y = -.01X^2 * 1.45X
 
Before I came up with this formula, I was using a very inefficient list method to do this. The old code is in italics. I still have it in the code because it works (sort of). The function is commented out because it doesn't work. It's also in bold, so you can see it easily.
 
        if keys[pygame.K_UP] and self.dy < (15 + self.speedMod):
            if self.dy <= 0:
                self.accelPoints += self.accelList[0]
                #self.dy += 1
            else:
                self.accelPoints += self.accelList[self.dy]
                #self.accelPoints += ((-.1 * (self.dy * self.dy)) + (1.45 * self.dy))
            if self.accelPoints >= self.accelGoal:
                self.dy += 1
                self.nety = self.dy
                self.accelPoints = 0
 
I did a test, and for some reason, it seems like the output of the function is never saved into the self.accelPoints variable, because it always prints out as 0. (For those who don't want to do the math, when dy = 1, the function should output something close to 1.55) My best guess is that the accelPoints doesn't like the fact that the function outputs a double, but even when i make accelPoints a double (made it equal 0.01 instead of 0) it still didn't work. If you have any thoughts on the matter, please let me know. I most likely broke it in the most silly way imaginable. Thanks for reading.
 
Greg
_______________________________________________
Tutor maillist  -  Tutor <at> python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
Steven D'Aprano | 2 Jul 2012 07:14

Re: Math Function and Python

On Sun, Jul 01, 2012 at 11:21:11PM -0500, Greg Nielsen wrote:
> Hello Tutor,
> 
>      I'm having some trouble with a mathematical function in my code. I am
> attempting to create a realistic acceleration in an object, slower to speed
> up at its min and max speeds and fastest in the middle. To keep the math
> simpl(er), I just wrote this function for a parabola, which models the
> acceleration of the object. Y is the acceleration and X is the current
> speed of the object.
> 
> Y = -.01X^2 * 1.45X

Are you sure that's the expression you want to use for acceleration? It 
certainly isn't a parabola. It simplifies to:

Y = -0.0145*X**3

which says that the DECELERATION is proportional to the CUBE of the 
speed.

Also, that's not a function. This would be a function:

def acceleration(v):
    """Return the acceleration of the object given its current
    velocity.
    """
    return -0.0145*v**3

> Before I came up with this formula, I was using a very inefficient list
> method to do this. The old code is in italics. I still have it in the code
> because it works (sort of). The function is commented out because it
> doesn't work. It's also in bold, so you can see it easily.

Eh, no. There are no italics or bold in plain text emails.

>         if keys[pygame.K_UP] and self.dy < (15 + self.speedMod):
>             if self.dy <= 0:
>                * self.accelPoints += self.accelList[0]*
>                 *#self.dy += 1*
>             else:
>                 *self.accelPoints += self.accelList[self.dy]*
>                 *#self.accelPoints += ((-.1 * (self.dy * self.dy)) + (1.45 * self.dy))*
>             if self.accelPoints >= self.accelGoal:
>                 self.dy += 1
>                 self.nety = self.dy
>                 self.accelPoints = 0

Without explaining what "accelPoints", "nety", "dy" etc. mean, there is 
no real way to tell whether this is a realistic model for a moving body. 
Without more context, I can't tell what it actually does, let alone what 
it is supposed to do.

I'm not an expert on PyGame, but I would expect that the way to model 
movement of a sprite is to calculate the delta-X and delta-Y, where X 
and Y are POSITIONS not speed and acceleration. I don't understand 
what "accelList" is for. Then you call the move() method on the sprite's 
rectangle, and redraw it.

> I did a test, and for some reason, it seems like the output of the function
> is never saved into the self.accelPoints variable, because it always prints
> out as 0.

Of course it does. You set it to 0 with this line:

self.accelPoints = 0

> (For those who don't want to do the math, when dy = 1, the
> function should output something close to 1.55) 

It certainly does not.

In your code, you have this expression:

(-.1 * (self.dy * self.dy)) + (1.45 * self.dy)

When self.dy = 1, that returns 1.35, not 1.55.

The other expression you give, early in this post, doesn't have a dy 
term. But if I put Y = dy instead, it gives -0.0145.

> My best guess is that the
> accelPoints doesn't like the fact that the function outputs a double, 

No.

By the way, in Python we don't talk about doubles. We have floats, which 
are implemented as C doubles, but since we don't have C-singles, we just 
call them floats.

--

-- 
Steven
_______________________________________________
Tutor maillist  -  Tutor <at> python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Alan Gauld | 2 Jul 2012 09:37

Re: Math Function and Python

On 02/07/12 05:21, Greg Nielsen wrote:

> models the acceleration of the object. Y is the acceleration and X is
> the current speed of the object.
> Y = -.01X^2 * 1.45X

That's not the same as the formula you have implemented.

> it doesn't work. It's also in bold, so you can see it easily.
>          if keys[pygame.K_UP] and self.dy < (15 + self.speedMod):
>              if self.dy <= 0:
>                  /self.accelPoints += self.accelList[0]/
>                  *#self.dy += 1*
>              else:
>                  /self.accelPoints += self.accelList[self.dy]/
>                  *#self.accelPoints += ((-.1 * (self.dy * self.dy)) + (1.45 * self.dy))*

Are you sure the else is being executed?
Have you tried inserting a print statement to check the value right 
after the block?

> I did a test, and for some reason, it seems like the output of the
> function is never saved into the self.accelPoints variable, because it
> always prints out as 0.

If your dy is very close to zero the value of your formula will be very 
close to zero so accelPoints never increases. But you also commented out 
the dy increment line so dy never increases which migfht suggest the 
else never gets called??

Can you send us the actual code that fails rather than something else 
that nearly works?
Its much easier to debug the thing that's actually broken that something 
that looks vaguely like it.

> outputs a double, but even when i make accelPoints a double (made it
> equal 0.01 instead of 0) it still didn't work.

Provided they are both numbers Python will adapt. That's not likely to 
be the problem.

--

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

_______________________________________________
Tutor maillist  -  Tutor <at> python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Peter Otten | 2 Jul 2012 09:57
Picon

Re: Python XML for newbie

Sean Carolan wrote:

>> Thank you, this is helpful.  Minidom is confusing, even the
>> documentation confirms this:
>> "The name of the functions are perhaps misleading...."
>>
>>> But I'd start with the etree tutorial (of which
>>> there are many variations on the web):
> 
> Ok, so I read through these tutorials and am at least able to print
> the XML output now.  I did this:
> 
> doc = etree.parse('computer_books.xml')
> 
> and then this:
> 
> for elem in doc.iter():
>     print elem.tag, elem.text
> 
> Here's the data I'm interested in:
> 
> index 1
> field 11
> value 9780596526740
> datum
> 
> How do you say, "If the field is 11, then print the next value"?  The
> raw XML looks like this:
> 
> <datum>
> <index>1</index>
> <field>11</field>
> <value>9780470286975</value>
> </datum>
> 
> Basically I just want to pull all these ISBN numbers from the file.

With http://lxml.de/ you can use xpath:

$ cat computer_books.xml 
<foo>
    <bar>
        <datum>
            <index>1</index>
            <field>11</field>
            <value>9780470286975</value>
        </datum>
    </bar>
</foo>
$ cat read_isbn.py
from lxml import etree

root = etree.parse("computer_books.xml")
print root.xpath("//datum[field=11]/value/text()")
$ python read_isbn.py 
['9780470286975']
$ 

_______________________________________________
Tutor maillist  -  Tutor <at> python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Gmane