473,698 Members | 2,102 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 1383
> 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
15246
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, maybe 32 kbytes is all and the need for speed is not so great, but the need for accuracy in the...
3
2778
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 page. Thanks! Ed
1
2177
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
2201
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
1072
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 confirm if the Website Administration Tool (WAT) adds has two
3
2596
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 application on his PC whit this : Process.GetProcessesByName(Process.GetCurrentProcess.ProcessName) ...
2
4540
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 solution with
1
4074
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
1759
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 path names like C:\folder\subfolder\filename.ext I would like it to be more like...
0
9152
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9014
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8885
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8855
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7708
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5857
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3037
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2320
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1995
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.