analitics

Pages

Tuesday, March 24, 2009

Python - random passwords

This program generates passwords on the size of 10 characters.
By using a function called "random_password" that creates a password of size 10 characters.
This function called "write_file" creates a file with automatic redial function "random_password. It contains a table of 10 X 10 random passwords.

from random import *
import string
chars = string.ascii_letters + string.digits
def random_password():
a = "".join(choice(chars) for x in range(randint(10, 10)))
b = a + ' | '
return b
def write_file():
f = open('random_pass.txt', 'wr+')
for c in range(10):
rand=''
for r in range(10):
rand = rand + random_password()
randpass=rand + random_password() + '\n'
f.write(str(randpass))
f.close()
write_file()

Friday, February 27, 2009

Python and xml

Python is an excellent choice for writing programs that process XML data.
XML's is a simplified subset of the Standard Generalized Markup Language (SGML).
He set of tools helps developers in creating web pages.
This is one simple example which I use with "conky":

from xml.dom import minidom as dom
import urllib2
def fetchPage(url):
a = urllib2.urlopen(url)
return ''.join(a.readlines())
def extract(page):
a = dom.parseString(page)
item2 = a.getElementsByTagName('SendingDate')[0].firstChild.wholeText
print "DATA ",item2
item = a.getElementsByTagName('Cube')
for i in item:
if i.hasChildNodes() == True:
e = i.getElementsByTagName('Rate')[8].firstChild.wholeText
d = i.getElementsByTagName('Rate')[18].firstChild.wholeText
print "EURO ",e
print "DOLAR ",d

if __name__=='__main__':
page = fetchPage("http://www.bnro.ro/nbrfxrates.xml")
extract(page)