nephish 0 Light Poster

threading, yep. going to take some time to learn this. but appears to be what i need.
thanks

nephish 0 Light Poster

Hey there,
i have a simple question about getting a script to do
two things at once.
like this.


for i in range(100):
print i
time.sleep(.2)
if i == 15:
os.system('python /home/me/ipupdate.py')
print 'done'

when i run this, it stops at 15 and runs the script called out in the os.system line. i know it is supposed to do that. But, how could i get a script to do this without stopping the count (or delaying it unill the script called exits) I don' t have to run it this way, i can import it if necessary as a module. or whatever will work so i can execute two things at once.

thanks

nephish 0 Light Poster

cool thanks, very helpful, i have been re-arranging stuff now.
all is starting to look better.
regards
sk

nephish 0 Light Poster

i found it.
the & operator.
thanks

nephish 0 Light Poster

i have an interesting project at work going on. here is the challenge.
i am using the serial module to read data from a serial input.
it comes in as a hex. i need to make it a binary and compare it bit by
bit to another byte. They have some weird way they set this up that i
have to compare these things with AND. in other words, if bit 1 is 1
AND bit 1 is 1 then the real value is 1...

long story short. is there a good way to compare bytes, bit by bit with
one of the modules of python. i want to know so i dont get halfway into
developing this and find that there is a much better way to do this
than by hand.

thanks for any suggestions.
sk <><

nephish 0 Light Poster

i have boa installed, but never use it much. i use eric sometimes when scripting because it shows a little bug when i have a syntax error. i like it, but i think wxglade is going to help me learn wx better.
cherrs

nephish 0 Light Poster

yeah, i forgot to close a tag.
:rolleyes:

nephish 0 Light Poster

cool thanks, i saw an app wxglade that looked pretty cool. even if not, i think i am leaning more that way because of desiring a more native look.
thanks

nephish 0 Light Poster

Hey there, i have been writing python scripts for about 4 months now so i am still very new at programming. that said, i need to build a gui app to handle some data manipulation from a database, set points, etc... what i would like is the easiest to learn gui development method for python in linux. Dont need anything cross platform, just easy to learn but able to do things like plotting info on a graph. ok, so i have looked at Tkinter, glade2 and wxPython. i dont know, but i would like some opinions before i jump into one.
thanks

nephish 0 Light Poster

Hey there,
i have some python scripts that run with the cgi-module. all named whatever.py
the thing is, firefox will open one that has a form on it, but not load the next one in line.
it pops up a window that says what do you want me to do with this file? and i can open with, or download it.
the other python programs work . i already did the chmod 755 on it, tried the chmod a+x, but just isn't doing anything.
they work if rendered with IE - go figure.
anyone ever see this ?
thanks

nephish 0 Light Poster

i am using sql 4.024 (debian-stable) so i gues the subqueries are out. i like the idea of writing two queries, that would work i think. i am coding in python and have one table with current info, another table of almost a million records (grows by about 50000/day) that i am using to query to keep the current status updated. i run this every 5 minutes or so. so i created a buffer table of just the last 5 minutes worth of entries, using that to run the queries, check for matches in UnitNumbers and update the current table accordingly, that way the web server isn't having to query a million record table to get the most recent info on the unit.
thanks, i am closer now than i was yesterday!

nephish 0 Light Poster

Hey there,
i have a table in MySQL that is updated about every 5 minutes with about a hundred new records. For an application i am building, i only need the info from the most recent entry for each specific unit. But, i need all of the info in that row.

i was going to use DISTINCT like this,

SELECT DISTINCT UnitNumber FROM table ORDER BY `autoinc` DESC

it gives me only the last record for each unit, but only returns the UnitNumber and i need all of the colums for each UnitNumber that it gives me.

or if i use something like this, will it only pull out items that have only one entry of each?

select distinct UnitNumber, value1, value2 from table order by autoinc desc

or is there a better way?
thanks

nephish 0 Light Poster

Dalhart, little town outside of Amarillo. Welcome to DaniWeb, lots of help i have gotten here.

cheers,
nephish <><

nephish 0 Light Poster

Where in Texas ?

welcome, lots o' scripting help i get here....

cheers

nephish 0 Light Poster

Hey thanks !

nephish 0 Light Poster

oh, nevermind. got it fixed now.
had my SQL environment messed up.

nephish 0 Light Poster

Hey there all,
i have a question about how to point my python install to my sql database.

when i enter this:

db = MySQLdb.connect(user="user", passwd="pass", db="myDB")

i get this:

Traceback (most recent call last):
  File "<pyshell#1>", line 1, in -toplevel-
    db = MySQLdb.connect(user="user", passwd="pass", db="MyDB")
  File "/usr/lib/python2.4/site-packages/MySQLdb/__init__.py", line 66, in Connect
    return Connection(*args, **kwargs)
  File "/usr/lib/python2.4/site-packages/MySQLdb/connections.py", line 134, in __init__
    super(Connection, self).__init__(*args, **kwargs2)
OperationalError: (1049, "Unknown database 'MyDB'")

i am using the all in one package from lampp (now xampp) and i have tested a couple of python scripts from the cgi, but.... nothing that connects to the database.

any ideas?

thanks

nephish 0 Light Poster

Hey there, how is your project comming along ?

nephish 0 Light Poster

ok
first off, many web hosts support scripting languages, but as they include php, perl, etc.. many do not support python.
the good news is...
you can host the site yourself.
apache is available for windows and they have great documentation and support.
heck, i will even host your site (i am hosting four sites now) if you are not going to get more than a thousand hits/day.

what i am saying is.... its easy... seems intimidating at first, but all things technical do. what you need is python, apache and the mod_python module. you edit the configuration file to have apache start the mod_python module when apache starts. put your scripts in a folder called cgi-bin (usually) look for a line in the apache configuration file called Script-Alias. this is also where the scripts would go if you upload them to a host. almost always not the same folder where the html stuff goes.
and, yeah, the scripts whatever.py has to be on the server because they are server side scripts. server side means that all the data process is done at the server and the results are posted to the web page.
when you call print, and you are printing html, it is printing to the web browser.
in the two scripts i posted, the html form passes data to the python script, the python script takes that info (username and password) and creates a webpage that

nephish 0 Light Poster

oh, i am using a gif.
and it works now, but here is what i had to do.
i have the script that writes the line to the text file write

print 'src="http://stretchweb.org/"'+lineList[NextStep]+".gif"+">

and then the script that prints the image just reads this line from a text file
and prints it

print line[1]

in the middle of it printing other html stuff.

gee whiz, it works, but ...... man......

thanks for your help.
not a very clean way to do it.. but it works right now.
i think very much that the problem i was having was in the line up
of quotes...because the error i kept getting was about not ending script headers...

nephish 0 Light Poster

try this....

here is a simple form.....

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html; charset=ISO-8859-1"
 http-equiv="content-type">
  <title>Admin Login</title>
</head>
<body>
<big><big>Login
Here<br>
<br>
</big></big>
<form action="/cgi-bin/Login.py" name="LoginForm"><big>Administration
Login<br>
 User Name<br>
  <input name="UserName"><br>
  <br>
  <br>
Password<br>
  <input name="PassWord"><br>
  </big><br>
   <br>
  <br>
<input type="submit">
  <br>
</form>
&nbsp;__&nbsp;<br>
</body>
</html>

and the script that it passes info to in the cgi-bin
called login.py

#!/usr/bin/python
import cgi
import cgitb; cgitb.enable()
# get the info from the html form
form = cgi.FieldStorage()
#set up the html stuff
reshtml = """Content-Type: text/html\n
<html>
 <head><title>Security Precaution</title></head>
 <body>
 """

print reshtml 

User = form['UserName'].value
Pass = form['PassWord'].value

if User == 'john' and Pass == 'jacob':
	print '<big><big>Welcome'
	print 'mr. Jingleheimerschmidt !</big></big><br>'
	print '<br>'
else:
	print 'Sorry, incorrect user name or password' 
	print '</body>'
print '</html>'

if you are using Linux, remember to make the login.py
script executable
chmod a+x /whatever/the/path/is/to/your/cgi-bin/login.py

let me know how it works.
also. if it does not work, lemme know some other stuff
what web server you are using.....
operating system.....
etc... what ever you think may help diagnose.

nephish 0 Light Poster

use a wysiwyg editor like mozilla-composer or nvu. (free downloads too!)

they have little buttons, forms, text imput, drop down lists, etc... stuff that you can choose from to create the form. it helps you out until you learn more of html.

hope this helps

nephish 0 Light Poster

oh, yeah,
items does return the number of total messages and size.
cheers !

nephish 0 Light Poster

finally came up with this, bits and pieces from tutorials,

#!/usr/bin/python
import poplib
import string
import StringIO, rfc822

# set up server info
SERVER = "mail.xxx.net"
USER  = "me"
PASSWORD = "py-junkie"

# connect to server
server = poplib.POP3(SERVER)

# login
server.user(USER)
server.pass_(PASSWORD)

# list items on server
resp, items, octets = server.list()

# download first message
id, size = items[0].split()
resp, text, octets = server.retr(id)

text = string.join(text, "\n")
file = StringIO.StringIO(text)

message = rfc822.Message(file)

print message.fp.read()

works though.
thanks..

nephish 0 Light Poster

what you want to look at is the cgi module.
go here
http://gnosis.cx/publish/programming/feature_5min_python.html
or here
http://wiki.python.org/moin/CgiScripts

i use only python in my cgi , just because i dig python.
hope this helps

nephish 0 Light Poster

Yeah, that is what i wound up doing.
thanks much.

nephish 0 Light Poster

OK i found this in a tutorial, tested it and it works.
just prints the message body.

import poplib
import string, random
import StringIO, rfc822

SERVER = "pop.spam.egg"

USER  = "mulder"
PASSWORD = "trustno1"

# connect to server
server = poplib.POP3(SERVER)

# login
server.user(USER)
server.pass_(PASSWORD)

# list items on server
resp, items, octets = server.list()

# download a random message
id, size = string.split(random.choice(items))
resp, text, octets = server.retr(id)

text = string.join(text, "\n")
file = StringIO.StringIO(text)

message = rfc822.Message(file)

for k, v in message.items():
    print k, "=", v

print message.fp.read()

i am really not to keen on the random part.
how would i use this line

id, size = string.split(random.choice(items))

to select a specific message from the retrieved list?

nephish 0 Light Poster

yeah, the messeges come in with all kinds of tracer stuff on them, spam stuff, this and that server......
gee whiz

nephish 0 Light Poster

hey there,
i have written a script that gets my email messages, but i need to
be able to strip off all of the stuff except the body of the message so i can write that to a text file.

is there an easy way to do this ?
Edit/Delete Message

nephish 0 Light Poster

um.. sure.
instead of having the script write just the name of the image file to load , i had it write the whole html line when the image is selected like this

image = form['image'].value

then later....

OutFile.write('src="http://stretchweb.org/'+image+'"></td>\n')

the script that reads the lines, just does this...

print image...

and it worked !

if you need more details or want to see the whole script, let me know

nephish 0 Light Poster

nevermind, i found a work-around

nephish 0 Light Poster

ok, here ya go

#!/usr/bin/python
import os
import cgi
import cgitb; cgitb.enable()
from time import gmtime, strftime

the_time = strftime("%A, %B %d, %Y") #Get a TimeStamp

#This script takes data from ViewRecords.py and opens and views the 
#Selected text file
#some bug some where

form = cgi.FieldStorage()
DataRecord = form['DataTime'].value
Customer = form['CustName'].value 

# Set up the html stuff
reshtml = """Content-Type: text/html\n
<html>
 <head><title>Customer Data</title></head>
<body>
"""


print reshtml
print '<big><span style="font-weight: bold;">Watkins Crop Consulting</span>&nbsp;'
print '</big>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'
print '&nbsp;&nbsp;<big>'+the_time+'</big>'
print '<br>'
print "1915 Cherokee <br>"
print "Dalhart, Tx 79022 <br>   333-5943&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<H2>"+Customer+"</H2>"


fileHandle = open("/var/www/stretch/web_root/SidCrops/"+Customer+"/"+DataRecord, "r")
lineList = fileHandle.readlines()
fileHandle.close()
Line_Iters = len(lineList)/7 #number of lines in the file divided by 7 (how many fields there are)


Iterations = 0 #represents the number of times the following while loop will run
NextStep = 0 #Increments to the next line of the file 
while Iterations < Line_Iters:
	print '<meta'
 	print 'content="text/html; charset=ISO-8859-1" http-equiv="content-type">'
  	print '<title></title>'
	print '</head>'
	print '<body>'
	print '<table style="text-align: left; width: 100%;"'
 	print 'border="0" cellpadding="0" cellspacing="0">'
  	print '<tbody>'
   	print '<tr>'
     	print '<td><img'
 	print 'style="width: 150px; height: 150px;" alt="circle"'
	print 'src="http://stretchweb.org/"'+lineList[NextStep]+".gif"+"></td>'
      	print '<td>'
	NextStep = NextStep + 1
	print "<span style='font-weight: bold;'>Field -</span>&nbsp;&nbsp;&nbsp;&nbsp; "+lineList[NextStep]+"	"
	NextStep = NextStep + 1
	print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'
	print "<span style='font-weight: bold;'>Crop -</span>&nbsp;&nbsp;&nbsp;&nbsp; "+lineList[NextStep]+"	"
	NextStep = NextStep + 1
	print "<span style='font-weight: bold;'>GS -</span>&nbsp;&nbsp;&nbsp;&nbsp; "+lineList[NextStep]+"	"
	NextStep = NextStep + 1
	print '<br>'
	print '<br>'
	print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'
	print "<span style='font-weight: bold;'>Water -</span>&nbsp;&nbsp;&nbsp;&nbsp; "+lineList[NextStep]+"	"
	print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'
	print "<br>"
	print "<br>"
	NextStep …
nephish 0 Light Poster

i have an html form with a drop-down list that lists a bunch of images.
how can i get my cgi script to load the image ?
i have imported cgi and os
text entered from a form and read from a file do ok, but i cant seem to get it to load an image.

the form writes all of the entries as lines in a .txt file
this file is selected later,
all the lines are read,
and based on the first line of the text file determines the name of the .gif image to load.

is there a way to do this, i think i am getting all the ' and '' stuff confused.

thanks.

nephish 0 Light Poster

nevermind, got it working now.
stupid submit button

arrgh

nephish 0 Light Poster

Hey there,
i have a python cgi script that prints out html just fine in the Opera browser
but doesnt print at all under FireFox.
weird, eh?
i am getting nothing in the apache logs about any error.
perhaps its a firefox issue, but i doubt it.

any suggestions. simple script here..

nephish 0 Light Poster

strftime was the key.
all working now.
thanks a million.
your'e awesome.

nephish 0 Light Poster

ok will do when i get back to the house.
thanks,
i'll let you know how it turns out.

nephish 0 Light Poster

Well, it printed exactly that....
printed it out like a string

/var/www/stretch/web_root/SidCrops/gritty/Sun Jun 5 18:52:55 2005.txt

it did get the two variables right.

i guess we are having a difficulty with empty spaces.

ok, i also tried from the interpereter and got the same error.
IDLE told me the file does not exist also...... and .... yes, it does.
so.... this file is based (obviously) on a timestamp. maybe i should format the way its put out. here is how i am doing it right now

from time import time, ctime
the_time = ctime(time())
try:    #Make the customer directory and create a data file by a timestamp name
	os.mkdir("/var/www/stretch/web_root/SidCrops/"+Customer) 
	OutFile = open("/var/www/stretch/web_root/SidCrops/"+Customer+"/"+the_time+".txt", "w")
	OutFile.write("")
	OutFile.close()
	print "File created successfully  "
except IOError:
   	print "IO Error"

this works to create a file that another script is able to open and write to
at a later stage in the app. Thats whats weird .

thanks

nephish 0 Light Poster

Hey there. Here is the deal.... i have a script that is supposed to
open a file based on criteria from a web form.
i cant seem to get it to work though.

here is the code:

form = cgi.FieldStorage()
DataRecord = form['DataTime'].value
Customer = form['CustName'].value # should be automatically filled in


print "Content-Type: text/html\n\n"
print

WorkingFile =
open("/var/www/stretch/web_root/SidCrops/"+Customer+"/"+DataRecord,
"r")
all_lines = WorkingFile.readlines()
WorkingFile.close()
for line in all_lines:
	print line

here is the error:
WorkingFile undefined, builtin open = <type 'file'>, Customer =
'tenderloin', DataRecord = 'Tue Jun 7 20:13:35 2005.txt'

IOError: [Errno 2] No such file or directory:
'/var/www/stretch/web_root/SidCrops/tenderloin/Tue Jun 7 20:13:35
2005.txt'
args = (2, 'No such file or directory')
errno = 2
filename = '/var/www/stretch/web_root/SidCrops/tenderloin/Tue Jun
7 20:13:35 2005.txt'
strerror = 'No such file or directory'

here is the deal.... the file is there ! i run similar code in idle and
it works.
i just dont get it. it isn't a permissions issue, its chmod 777 all
the way.
i gotta find out why this is goofing on me...

please help me!