Re: Who uses Python?

2007-06-04 Thread supercooper
I use it for processing GIS data (ALOT), building data harvesting apps
that slurp data into MySQL/SQLServer from text files (ALOT), batch
processing of daily mindless tasks like copying files and backups, and
filing/cataloging/EXIF-IPTC metadata editing on digital photos - to
name a few. I took Mark Lutz's python course last year and he summed
it up with "Anything you can do on a computer, you can do with
Python".

-- 
http://mail.python.org/mailman/listinfo/python-list


Convert binary string to something meaningful??

2007-06-13 Thread supercooper
I have this string that is being returned from a query on a DBISAM
database. The field must be some sort of blob, and when I connect to
the database thru ODBC in MS Access, the field type comes thru as OLE
Object, and Access cannot read the field (it usually crashes Access).
I can sorta pick out the data that I need (7.0, 28, 5TH PRINCIPAL MRD,
10.0 - and these occur in roughly the same place in every record
returned from the db), but I am wondering if there is a way to convert
this. I looked at the struct module, but I really dont know the format
of the data for sure. For starters, could someone tell me what '\x00'
more than likely is? Any hints on modules to look at or esp code
snippets would be greatly appreciated. Thanks.

\x9c
\x01\x00\x007.0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00
28.0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00
10.0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00WN
\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x10\xa3@
[EMAIL PROTECTED] NW SE
\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00CONGRESS
QTR\x00\x00\x00\x005\x00\x005TH PRINCIPAL MRD
\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0
0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0
0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0
0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Gmail Error using smtplib

2007-07-20 Thread supercooper
This works for me...

def SendEmail(msgType,sender,recipient,subject,message):
"""
Sends either a log file or a string message in email to
recipient.
Uses Google smtp server to send the mail.

CHANGELOG:
2006-12-7:Set sender, recipient, subject as input variables
 
-
Inputs:
msgType:If 'log', message is path to log file that is to be
written into email body
sender: Senders email addy
recipient:  Who we want to send to
subject:Email subject line
message:Message body of email
 
-
"""
# determine msg type
if msgType == 'log':
# Send log file in email
fp = open(message, 'rb')
# Create a text/plain message
# Read contents of log file into memory
msg = MIMEText(fp.read())
fp.close()
else:
# If not a log file, just create a text/plain message
msg = MIMEText(message)

# User/pwd
me = '[EMAIL PROTECTED]'
pwd = 'pass'

# Build the email
fromAddr = sender
toAddr = recipient
msg['Subject'] = subject
msg['From'] = fromAddr
msg['To'] = toAddr

# Set up and connect to smtp server
server = smtplib.SMTP('smtp.gmail.com', 587)
server.set_debuglevel(1)
server.ehlo()
server.starttls()
server.ehlo()
server.login(me, pwd)
# Send the email
server.sendmail(fromAddr, toAddr, msg.as_string())
server.close()



-- 
http://mail.python.org/mailman/listinfo/python-list


Re: shutil.copyfile problem for GIS data

2007-07-23 Thread supercooper
import shutil
import os

src = "c:\mydata\test\mygeo.mdb"
dst = "v:\updated\data\mygeo.mdb"

shutil.copyfile(src,dst)

This should totally work, do it all the time, but no one can be
connected to the database, ie have ArcMap or ArcCatalog open at the
time of copy, or the .ldb lock will kill it. I do all of my copies in
the early AM.


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Where do they tech Python officialy ?

2007-07-23 Thread supercooper
http://home.earthlink.net/~python-training/

I highly recommend Mark Lutz. Took the class last fall in Estes Park
and it was worth every penny.

-- 
http://mail.python.org/mailman/listinfo/python-list


urllib timeout issues

2007-03-27 Thread supercooper
I am downloading images using the script below. Sometimes it will go
for 10 mins, sometimes 2 hours before timing out with the following
error:

Traceback (most recent call last):
  File "ftp_20070326_Downloads_cooperc_FetchLibreMapProjectDRGs.py",
line 108, i
n ?
urllib.urlretrieve(fullurl, localfile)
  File "C:\Python24\lib\urllib.py", line 89, in urlretrieve
return _urlopener.retrieve(url, filename, reporthook, data)
  File "C:\Python24\lib\urllib.py", line 222, in retrieve
fp = self.open(url, data)
  File "C:\Python24\lib\urllib.py", line 190, in open
return getattr(self, name)(url)
  File "C:\Python24\lib\urllib.py", line 322, in open_http
return self.http_error(url, fp, errcode, errmsg, headers)
  File "C:\Python24\lib\urllib.py", line 335, in http_error
result = method(url, fp, errcode, errmsg, headers)
  File "C:\Python24\lib\urllib.py", line 593, in http_error_302
data)
  File "C:\Python24\lib\urllib.py", line 608, in redirect_internal
return self.open(newurl)
  File "C:\Python24\lib\urllib.py", line 190, in open
return getattr(self, name)(url)
  File "C:\Python24\lib\urllib.py", line 313, in open_http
h.endheaders()
  File "C:\Python24\lib\httplib.py", line 798, in endheaders
self._send_output()
  File "C:\Python24\lib\httplib.py", line 679, in _send_output
self.send(msg)
  File "C:\Python24\lib\httplib.py", line 646, in send
self.connect()
  File "C:\Python24\lib\httplib.py", line 630, in connect
raise socket.error, msg
IOError: [Errno socket error] (10060, 'Operation timed out')


I have searched this forum extensively and tried to avoid timing out,
but to no avail. Anyone have any ideas as to why I keep getting a
timeout? I thought setting the socket timeout did it, but it didnt.

Thanks.

<--- CODE --->

images = [['34095e3','Clayton'],
['35096d2','Clearview'],
['34095d1','Clebit'],
['34095c3','Cloudy'],
['34096e2','Coalgate'],
['34096e1','Coalgate SE'],
['35095g7','Concharty Mountain'],
['34096d6','Connerville'],
['34096d5','Connerville NE'],
['34096c5','Connerville SE'],
['35094f8','Cookson'],
['35095e6','Council Hill'],
['34095f5','Counts'],
['35095h6','Coweta'],
['35097h2','Coyle'],
['35096c4','Cromwell'],
['35095a6','Crowder'],
['35096h7','Cushing']]

exts = ['tif', 'tfw']
envir = 'DEV'
# URL of our image(s) to grab
url = 'http://www.archive.org/download/'
logRoot = '//fayfiler/seecoapps/Geology/GEOREFRENCED IMAGES/TOPO/
Oklahoma UTMz14meters NAD27/'
logFile = os.path.join(logRoot, 'FetchLibreDRGs_' + strftime('%m_%d_%Y_
%H_%M_%S', localtime()) + '_' + envir + '.log')

# Local dir to store files in
fetchdir = logRoot
# Entire process start time
start = time.clock()

msg = envir + ' - ' + "Script: " + os.path.join(sys.path[0],
sys.argv[0]) + ' - Start time: ' + strftime('%m/%d/%Y %I:%M:%S %p',
localtime()) + \
 
'\n--
\n\n'
AddPrintMessage(msg)
StartFinishMessage('Start')

# Loop thru image list, grab each tif and tfw
for image in images:
# Try and set socket timeout default to none
# Create a new socket connection for every time through list loop
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(('archive.org', 80))
s.settimeout(None)

s2 = time.clock()
msg = '\nProcessing ' + image[0] + ' --> ' + image[1]
AddPrintMessage(msg)
print msg
for ext in exts:
fullurl = url + 'usgs_drg_ok_' + image[0][:5] + '_' + image[0]
[5:] + '/o' + image[0] + '.' + ext
localfile = fetchdir + image[0] + '_' +
string.replace(image[1], ' ', '_') + '.' + ext
urllib.urlretrieve(fullurl, localfile)
e2 = time.clock()
msg = '\nDone processing ' + image[0] + ' --> ' + image[1] +
'\nProcess took ' + Timer(s2, e2)
AddPrintMessage(msg)
print msg
# Close socket connection, only to reopen with next run thru loop
s.close()

end = time.clock()
StartFinishMessage('Finish')
msg = '\n\nDone! Process completed in ' + Timer(start, end)
AddPrintMessage(msg)

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: urllib timeout issues

2007-03-27 Thread supercooper
On Mar 27, 3:13 pm, "Gabriel Genellina" <[EMAIL PROTECTED]>
wrote:
> En Tue, 27 Mar 2007 16:21:55 -0300, supercooper <[EMAIL PROTECTED]>
> escribió:
>
> > I am downloading images using the script below. Sometimes it will go
> > for 10 mins, sometimes 2 hours before timing out with the following
> > error:
>
> > urllib.urlretrieve(fullurl, localfile)
> > IOError: [Errno socket error] (10060, 'Operation timed out')
>
> > I have searched this forum extensively and tried to avoid timing out,
> > but to no avail. Anyone have any ideas as to why I keep getting a
> > timeout? I thought setting the socket timeout did it, but it didnt.
>
> You should do the opposite: timing out *early* -not waiting 2 hours- and
> handling the error (maybe using a queue to hold pending requests)
>
> --
> Gabriel Genellina

Gabriel, thanks for the input. So are you saying there is no way to
realistically *prevent* the timeout from occurring in the first
place?  And by timing out early, do you mean to set the timeout for x
seconds and if and when the timeout occurs, handle the error and start
the process again somehow on the pending requests?  Thanks.

chad

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: urllib timeout issues

2007-03-29 Thread supercooper
On Mar 27, 4:50 pm, "Gabriel Genellina" <[EMAIL PROTECTED]>
wrote:
> En Tue, 27 Mar 2007 17:41:44 -0300, supercooper <[EMAIL PROTECTED]>
> escribió:
>
>
>
> > On Mar 27, 3:13 pm, "Gabriel Genellina" <[EMAIL PROTECTED]>
> > wrote:
> >> En Tue, 27 Mar 2007 16:21:55 -0300, supercooper <[EMAIL PROTECTED]>
> >> escribió:
>
> >> > I am downloading images using the script below. Sometimes it will go
> >> > for 10 mins, sometimes 2 hours before timing out with the following
> >> > error:
>
> >> > urllib.urlretrieve(fullurl, localfile)
> >> > IOError: [Errno socket error] (10060, 'Operation timed out')
>
> >> > I have searched this forum extensively and tried to avoid timing out,
> >> > but to no avail. Anyone have any ideas as to why I keep getting a
> >> > timeout? I thought setting the socket timeout did it, but it didnt.
>
> >> You should do the opposite: timing out *early* -not waiting 2 hours- and
> >> handling the error (maybe using a queue to hold pending requests)
>
> >> --
> >> Gabriel Genellina
>
> > Gabriel, thanks for the input. So are you saying there is no way to
> > realistically *prevent* the timeout from occurring in the first
>
> Exactly. The error is out of your control: maybe the server is down,
> irresponsive, overloaded, a proxy has any problems, any network problem,
> etc.
>
> > place?  And by timing out early, do you mean to set the timeout for x
> > seconds and if and when the timeout occurs, handle the error and start
> > the process again somehow on the pending requests?  Thanks.
>
> Exactly!
> Another option: Python is cool, but there is no need to reinvent the
> wheel. Use wget instead :)
>
> --
> Gabriel Genellina

Gabriel...thanks for the tip on wget...its awesome! I even built it on
my mac. It is working like a champ for hours on end...

Thanks!

chad




import os, shutil, string

images = [['34095d2','Nashoba'],
['34096c8','Nebo'],
['36095a4','Neodesha'],
['33095h7','New Oberlin'],
['35096f3','Newby'],
['35094e5','Nicut'],
['34096g2','Non'],
['35096h6','North Village'],
['35095g3','Northeast Muskogee'],
['35095g4','Northwest Muskogee'],
['35096f2','Nuyaka'],
['34094e6','Octavia'],
['36096a5','Oilton'],
['35096d3','Okemah'],
['35096c3','Okemah SE'],
['35096e2','Okfuskee'],
['35096e1','Okmulgee Lake'],
['35095f7','Okmulgee NE'],
['35095f8','Okmulgee North'],
['35095e8','Okmulgee South'],
['35095e4','Oktaha'],
['34094b7','Old Glory Mountain'],
['36096a4','Olive'],
['34096d3','Olney'],
['36095a6','Oneta'],
['34097a2','Overbrook']]

wgetDir = 'C:/Program Files/wget/o'
exts = ['tif', 'tfw']
url = 'http://www.archive.org/download/'
home = '//fayfiler/seecoapps/Geology/GEOREFRENCED IMAGES/TOPO/Oklahoma
UTMz14meters NAD27/'

for image in images:
for ext in exts:
fullurl = url + 'usgs_drg_ok_' + image[0][:5] + '_' + image[0]
[5:] + '/o' + image[0] + '.' + ext
os.system('wget %s -t 10 -a log.log' % fullurl)
shutil.move(wgetDir + image[0] + '.' + ext, home + 'o' +
image[0] + '_' + string.replace(image[1], ' ', '_') + '.' + ext)

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: looking for ocbc example

2007-11-29 Thread supercooper
On Nov 28, 2:43 am, Tim Golden <[EMAIL PROTECTED]> wrote:
> Carl K wrote:
> > jay graves wrote:
> >> On Sep 21, 2:43 am, Tim Golden <[EMAIL PROTECTED]> wrote:
> >>> Carl K wrote:
>  It seems there are 2 odbc modules - pyOdbc and mxOdbc - anyone know the 
>  difference?
> >>> In short, pyodbc is open source; mxOdbc requires a commercial license.
> >>> pyodbc is a newcomer, but appears to work for everything I've thrown
> >>> at it (which is not much). mxOdbc has been around longer, and is sure
> >>> to be a more mature product. It may offer more features & functionality.
> >> There is also a brand new module 'ceODBC'.
> >>http://ceodbc.sourceforge.net/
>
> >> I haven't used it yet but I want to give it a try.
>
> > I tried it, and it worked better than pyodbc.  (better is not exactly right.
> > there was some weird bug in the ctree odbc driver, and the author of ceODBC 
> > gave
> > me a workaround.)
>
> All right, I'm a little perplexed as to whether "better" here
> refers to the admirable response of the ceOBDC author or to
> some other factors which demonstrate ceODBC's superiority.
>
> I've not really got the opportunity to pit them against each
> other so to speak, but I'd love to hear from someone who had.
>
> TJ

Just tried ceODBC the other day (on XP), and it worked like a charm
connecting SqlServer and DB2. Here's SqlServer:

>>> import ceODBC
>>> db=ceODBC.connect('DSN=Wells')
>>> c=db.cursor()
>>> c.execute('select wellname, latitudedecimal, longitudedecimal from 
>>> dbo.wells where wellid in (11587,11194,11157)')
>>> for each in c.fetchall():
... print each
...
('GILL #1-18', 33.095599, -92.38563)
('HOW #2-7', 35.10155, -91.48824)
('JKK #11-13', 34.09130, -93.45256)

Simple! Very similar syntax to mxODBC.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Converting Excel time-format (hours since 1.1.1901)

2007-12-07 Thread supercooper
On Dec 7, 8:15 am, Dirk Hagemann <[EMAIL PROTECTED]> wrote:
> On 7 Dez., 14:34, supercooper <[EMAIL PROTECTED]> wrote:
>
>
>
> > On Dec 7, 7:20 am, Dirk Hagemann <[EMAIL PROTECTED]> wrote:
>
> > > Hello,
>
> > > From a zone-file of a Microsoft Active Directory integrated DNS server
> > > I get the date/time of the dynamic update entries in a format, which
> > > is as far as I know the hours since january 1st 1901.
> > > For Example: the number 3566839 is 27.11.07 7:00. To calculate this in
> > > Excel I use this:
> > > ="01.01.1901"+(A1/24-(REST(A1;24)/24))+ZEIT(REST(A1;24);0;0)  (put
> > > 3566839 in field A1 and switch the format of the result-field to the
> > > corresponding date-time format).
>
> > > You might guess what I need now: I want to calculate this somehow in
> > > python.
>
> > > Sorry, but I couldn't find anything in the module time or something
> > > else to get this calculated.
>
> > > Does anyone know how to convert this time in python to something
> > > usable or how to convert this formula in python?
>
> > > Thanks a lot and regards
> > > Dirk
>
> > I think you want the xldate_as_tuple function in the xlrd module:
>
> >http://www.lexicon.net/sjmachin/xlrd.htm
>
> > It works like a champ for me:
>
> > >>> import xlrd
> > >>> xlrd.xldate.xldate_as_tuple(38980,0)
>
> > (2006, 9, 20, 0, 0, 0)
>
> > chad!
>
> Thanks so far, that comes close to a solution I think, BUT when I
> enter 3566985 instead of 38980 I get the following error:
> Traceback (most recent call last):
>   File "test.py", line 20, in 
> print xlrd.xldate.xldate_as_tuple(3566985,0)
>   File "C:\Python25\lib\site-packages\xlrd\xldate.py", line 75, in
> xldate_as_tuple
> raise XLDateTooLarge(xldate)
> xlrd.xldate.XLDateTooLarge: 3566985
>
> Do I have to use another function of this module? My number is 2
> digits shorter than yours. What is 38980 representing?
>
> Dirk

Excel stores dates as floating point
numbers; the number of days (or fraction thereof) since
12/31/1899. So 38980.0 is midnight 9/20/2006. You think your numbers
represent
the number of hours since 1/1/1901?

3,566,985 hrs/24 hrs in a day = ~148,618 days
148,618 days/365 days in a year = ~407 years

Am I doing the math wrong?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Converting Excel time-format (hours since 1.1.1901)

2007-12-07 Thread supercooper
On Dec 7, 7:20 am, Dirk Hagemann <[EMAIL PROTECTED]> wrote:
> Hello,
>
> From a zone-file of a Microsoft Active Directory integrated DNS server
> I get the date/time of the dynamic update entries in a format, which
> is as far as I know the hours since january 1st 1901.
> For Example: the number 3566839 is 27.11.07 7:00. To calculate this in
> Excel I use this:
> ="01.01.1901"+(A1/24-(REST(A1;24)/24))+ZEIT(REST(A1;24);0;0)  (put
> 3566839 in field A1 and switch the format of the result-field to the
> corresponding date-time format).
>
> You might guess what I need now: I want to calculate this somehow in
> python.
>
> Sorry, but I couldn't find anything in the module time or something
> else to get this calculated.
>
> Does anyone know how to convert this time in python to something
> usable or how to convert this formula in python?
>
> Thanks a lot and regards
> Dirk

I think you want the xldate_as_tuple function in the xlrd module:

http://www.lexicon.net/sjmachin/xlrd.htm

It works like a champ for me:

>>> import xlrd
>>> xlrd.xldate.xldate_as_tuple(38980,0)
(2006, 9, 20, 0, 0, 0)
>>>

chad!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PIL and IPTC

2008-04-30 Thread supercooper
On Apr 30, 9:15 am, Jumping Arne <[EMAIL PROTECTED]> wrote:
> I'm completely new to PIL and I'm trying to read IPTC info, I understand that
> it's possible but I can't find out how (and for once Google doesn't seem to
> be able to help). Does anyone have an example of how it's done?

I use the IPTCInfo module with great success. Its very easy to work
with to read/write IPTC metadata:

http://pypi.python.org/pypi/IPTCInfo/1.9.2-rc5

HTH
--
http://mail.python.org/mailman/listinfo/python-list