473,563 Members | 2,695 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

scanning through page and replacing all instances of 00:00:00.00

Kun
I have a python-cgi file that pulls data from an sql database, i am
wondering what is the easiest way to remove all instances of
'00:00:00.00' in my date column.

how would i write a python script to scan the entire page and delete all
instances of '00:00:00.00', would i use regular expressions?
Apr 17 '06 #1
13 1373
> I have a python-cgi file that pulls data from an sql
database, i am wondering what is the easiest way to
remove all instances of '00:00:00.00' in my date column.

how would i write a python script to scan the entire page
and delete all instances of '00:00:00.00', would i use
regular expressions?


No need for a regexp:

someString = someString.repl ace("00:00:00.0 0", "")

I'd recommend doing it before you print the values out,
rather than try and "scan the entire page" after you've
printed them.

Easy 'nuff.

-tkc

Apr 17 '06 #2
Kun wrote:
I have a python-cgi file that pulls data from an sql database, i am
wondering what is the easiest way to remove all instances of
'00:00:00.00' in my date column.

how would i write a python script to scan the entire page and delete all
instances of '00:00:00.00', would i use regular expressions?


You could use regular expressions or you might want to take a look at
Beautiful Soup http://www.crummy.com/software/BeautifulSoup
to parse the page and replace the offending text.

-Larry Bates
Apr 17 '06 #3
"Kun" wrote:
I have a python-cgi file that pulls data from an sql database, i am
wondering what is the easiest way to remove all instances of
'00:00:00.00' in my date column.

how would i write a python script to scan the entire page and delete all
instances of '00:00:00.00', would i use regular expressions?


umm. if you're using a database, why not filter out uninteresting dates either
in the SQL statement, or when you're building the page ?

</F>

Apr 17 '06 #4
Kun
Fredrik Lundh wrote:
"Kun" wrote:
I have a python-cgi file that pulls data from an sql database, i am
wondering what is the easiest way to remove all instances of
'00:00:00.00' in my date column.

how would i write a python script to scan the entire page and delete all
instances of '00:00:00.00', would i use regular expressions?


umm. if you're using a database, why not filter out uninteresting dates either
in the SQL statement, or when you're building the page ?

</F>

because in my sql database, the date is only 'date' (as in yyyy-mm-dd),
only when i extract it with my python-cgi does the date turn into
(yyyy-mm-dd 00:00:00.00), thus i figured the best way to fix this
problem is to parse it after the matter.

side note: the 'date' column is not formatted as datetime in the mysql
database.
Apr 17 '06 #5
"Kun" wrote:
because in my sql database, the date is only 'date' (as in yyyy-mm-dd),
only when i extract it with my python-cgi does the date turn into
(yyyy-mm-dd 00:00:00.00), thus i figured the best way to fix this
problem is to parse it after the matter.


you still make no sense. why not fix this in your python cgi script ?

</F>

Apr 17 '06 #6
Kun
Fredrik Lundh wrote:
"Kun" wrote:
because in my sql database, the date is only 'date' (as in yyyy-mm-dd),
only when i extract it with my python-cgi does the date turn into
(yyyy-mm-dd 00:00:00.00), thus i figured the best way to fix this
problem is to parse it after the matter.


you still make no sense. why not fix this in your python cgi script ?

</F>

i have the following python-cgi which extracts data from a mysql table,
how do i parse the date so that it doesn't display the time '00:00:00.00'?

print '<h1>Query Results</h1>'
try:
db = MySQLdb.connect (host="localhos t", user="xxx", passwd="xxxx",
db="xxxx")
cursor = db.cursor()
sqlstring = (select + " FROM dir" + where + order_by + limit)
print sqlstring
cursor.execute( sqlstring)

numrows = cursor.rowcount
numcols = len(cursor.desc ription)
#print sqlstring
#print "SQL statement used:<br>" + sqlstring

print """<table border="1" cellpadding="1" cellspacing="1" >"""
print "<tr>"

for col in range(0, numcols):
print "<td><b>", cursor.descript ion[col][0], "</b></td>"

print "</tr>"

for row in range(0,numrows ):
record = cursor.fetchone ()
print "<tr>"

for col in range(0, numcols):
print "<td>", record[col], "</td>"

print "</tr>"

except MySQLdb.Operati onalError, message:
print "Error %d:<br>%s<br><b r>" % (message[0], message[1])
print "SQL statement used:<br>" + sqlstring

print "</table>"
Apr 17 '06 #7

Kun> i have the following python-cgi which extracts data from a mysql
Kun> table, how do i parse the date so that it doesn't display the time
Kun> '00:00:00.00'?

I have no idea which column in your table is a datetime object, but just
convert it to a date. For example:
import datetime
dt = datetime.dateti me.now()
print dt 2006-04-17 18:19:38.698925 print dt.date()

2006-04-17

Skip
Apr 17 '06 #8
Kun
sk**@pobox.com wrote:
Kun> i have the following python-cgi which extracts data from a mysql
Kun> table, how do i parse the date so that it doesn't display the time
Kun> '00:00:00.00'?

I have no idea which column in your table is a datetime object, but just
convert it to a date. For example:
>>> import datetime
>>> dt = datetime.dateti me.now()
>>> print dt 2006-04-17 18:19:38.698925 >>> print dt.date()

2006-04-17

Skip

assuming that my date column is 2, how would i parse out the date? the
example you gave is of you parsing out the current time, but how do you
parse out a pre-specified time that is extracted via sql? i don't think
something like dt.date() works because it doesn't work with a string?
correct me if i'm wrong.
Apr 17 '06 #9
> for col in range(0, numcols):
print "<td>", record[col], "</td>"


This is the point at which you want to intercept the column
data and make your change:

print "<td>", str(record[col]).replace("00:0 0:00.0", ""), "</td"

If it's possible/plausible that other fields might have such
a value reasonably, then you'd want to do a check, something
like
THEDATECOL = 42
for col in range(0, numcols):
foo = record[col]
if col == THEDATECOL:
foo = foo.replace("00 :00:00.00", "")
print "<td>%s</td>" % foo

or alternatively

DATECOLUMNS = [3, 14]
for col in range(0, numcols):
foo = record[col]
if col in DATECOLUMNS:
foo = foo.replace("00 :00:00.00", "")
print "<td>%s</td>" % foo

I don't know off the top of my head if your MySQL cursor
object supports metadata...some thing like the following
pseudocode:

for col in range(0, numcols):
foo = record[col]
if cursor.fieldtyp es[col] == MYSQL_DATE:
foo = foo.replace("00 :00:00.00", "")
print "<td>%s</td>" % foo

Adjust accordingly.

-tkc

Apr 17 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
15209
by: yaipa | last post by:
What would be the common sense way of finding a binary pattern in a ..bin file, say some 200 bytes, and replacing it with an updated pattern of the same length at the same offset? Also, the pattern can occur on any byte boundary in the file, so chunking through the code at 16 bytes a frame maybe a problem. The file itself isn't so large,...
3
2774
by: Ed Burns | last post by:
Hi. I am trying to disable a user from going back to a previous page and displaying information previously shown. I want to give them the typical "Page has Expired" warning message. I am using Win Server 2003. Does anyone know what you have to do so that the user can only see the page once and not to be able to click back and see a cached...
1
2164
by: thomasb | last post by:
When setting up federation between two databases on the same instance everything works fine. When trying to do the same between two databases on different instances on the same machine I get into trouble. SQL1013N The database alias name or database name "UDB" could not be found. SQLSTATE=42705
1
2196
by: Randall Skelton | last post by:
Can someone explain why the latter query uses an index scan while the former uses a sequence scan? I have tried all sorts of casting in the first case but I cannot get the index scan. Cheers, Randall == data=> EXPLAIN ANALYZE SELECT acqtimestamp FROM aux_datarecord where acqtimestamp between (extract(epoch from timestamp '2004-02-21
0
1070
by: clintonG | last post by:
I need somebody who is using 2.0 RTM Membership with a dev machine located in GMT (-06:00) Central Time and is interested in running a short test to debug the RTM 2.0. I need to confirm if anybody else has users that are being added to aspnet_Users 6 hours into the future which is my experience when using Membership. I also want to...
3
2568
by: Michel | last post by:
Hi, I wrote an app in .Net and I whant only 1 instance of this app open for the user; the user open my app, do some works and try to open another instance of my app, I whant to show a message to user to inform him that only one instance is permit and then close the second instance after that. I am able to do this when the user run the...
2
4532
by: jgbid | last post by:
Hi, I'm trying to build an IP Scanner inc c# for a specific port (80) and for specific IP Ranges. For example 24.36.148.1 to 24.36.148.255 My first step was to use TcpClient, but there are nothing to control Timeout Connection... and I wasn't interested to wait 25-30sec for each ip. After some search, it's look like Socket was the...
1
4071
by: duncanm817 | last post by:
hi, I require some assistance in understanding how to accomplish replacing a particular hex value in a binary file on aix. in a binary file I need to find the following combination: 5A 00 10 D3 A9 XX XX XX XX XX XX XX XX XX XX XX XX 0C 5A XX represents any valid HEX value then replace this with the following HEX value
8
1750
by: =?Utf-8?B?QnJ5YW4=?= | last post by:
Hello group. I have some code (given to me), but I don't know alot about ASP, so I was hoping someone here can help. Running on Win 2008 server. The code below will scan a folder and subfolder with a date/time input and return xml structure off all files that are newer than the supplied date/time. The problem is that the returned xml has...
0
7664
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7583
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7885
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8106
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7948
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5484
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5213
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
1198
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
923
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.