analitics

Pages

Saturday, September 24, 2011

Creating folders and documents with gdata module

Today I played with gdata python module.
The problem that I solved it:
creating folders and documents in your Gmail account.
First you need to install gdata module.
In fedora I used:
yum install python-gdata.noarch 
Here are the first lines of source code that creates a folder named test-fedora
Python 2.7.1 (r271:86832, Apr 12 2011, 16:16:18) 
[GCC 4.6.0 20110331 (Red Hat 4.6.0-2)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import gdata.docs.service
>>> my=gdata.docs.service.DocsService()
>>> my.ClientLogin('your-account@gmail.com','your-password')
>>> my.CreateFolder('test-fedora')
I tried to automate the process of creating folders and I used a list and instruction for
>>> folders=['aaa','bbb','ccc']
>>> for f in folders:
...     my.CreateFolder(f)
... 
To create a document to write more lines of code.
This is because there are many types of documents
>>> new_entry = gdata.GDataEntry()
>>> new_entry.title = gdata.atom.Title(text='fedora-test')
>>> category = my._MakeKindCategory(gdata.docs.service.DOCUMENT_LABEL)
>>> new_entry.category.append(category)
>>> created_entry = my.Post(new_entry, '/feeds/documents/private/full')
Here's a simple solution to avoid loss of mail password.
>>> import getpass
>>> username = raw_input('Please enter your username: ')
Please enter your username: user1
>>> password = getpass.getpass()
Password: 
>>> print username
user1
>>> print password
pass1
I hope you will use this

Friday, August 12, 2011

GLUT - Creating a fullscreen applications.

To create a fullscreen application must use the function:
glutGameModeString()
glutEnterGameMode()

Below is the source commented.
import sys
from OpenGL.GL import *
from OpenGL.GLUT import *

def main():
 
    # Initialize OpenGL
    glutInit(sys.argv)
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB)
 
    # Configure the display output
    glutGameModeString("1024x600:32@60")

    # The application will enter fullscreen
    glutEnterGameMode()
 
    # Setup callbacks for keyboard and display
    glutKeyboardFunc(keyboard)
    glutDisplayFunc(display)
 
    # Enters the GLUT event processing loop
    glutMainLoop()
 
def keyboard(key, x, y):
    if key == 'q':
        sys.exit(0)

def display():
    glClear(GL_COLOR_BUFFER_BIT)

    # Draw a green line
    glBegin(GL_LINES)
    glColor3f(0.0,100.0,0.0)
    glVertex2f(1.0, 1.0)
    glVertex2f(-1.0, -1.0)
    glEnd()
 
    glutSwapBuffers()
 
if __name__ == "__main__":
    main()