SunQuest
           Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today!
  #1  
Old November 6th, 2003, 06:03 PM
Arkamir Arkamir is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 36 Arkamir User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
RE and html and MySQL need help

I've deduced from the error messages it has too do something with thedate time object of x[1].I was hoping you guys could supply me with an answer.This is the code in question:

import MySQLdb
import re
import compare
import numberofpages
import display
import time

db = MySQLdb.connect(host='localhost', user='conrad',passwd='mysqlinsecret', db='cgi')
cursor = db.cursor()

def retrieve_posts(forum, thread, end_post):
giventemplate = 'posttemplate'
inputtemplate = open(giventemplate, 'r')
posttemplate = inputtemplate.read()
inputtemplate.close()

start_post = end_post - 20

cursor.execute('''select names, dates, subjects, posts, positions from%s where threads = \'%s\' and positions > \'%s\' and positions <\'%s\'''' % (forum, thread, start_post, end_post))

postsinfo = cursor.fetchall()
postsinfo = list(postsinfo)
postsinfo.sort(compare.compare)
posts = posttemplate
subsitutes = ['NAME', 'DATE', 'SUBJECT', 'POST']
list_of_posts = []
# 1111111 expression = '<!--INSERT %s HERE-->'
content1 = re.escape('<!--INSERT NAME HERE-->')
content2 = re.escape('<!--INSERT DATE HERE-->')
content3 = re.escape('<!--INSERT SUBJECT HERE-->')
content4 = re.escape('<!--INSERT POST HERE-->')
for post in postsinfo:
#change it from a datetime object
repr(post[1])
for value in range(4): # 1111111 posts = re.sub((expression, post[value], posts) %subsitutes[value])

posts = re.sub(content1, post[0], posts)
#this is where the error occurs
posts = re.sub(content2, post[1], posts)
posts = re.sub(content3, post[2], posts)
posts = re.sub(content4, post[3], posts)
print posts
list_of_posts.append(posts)
posts = posttemplate

Reply With Quote
  #2  
Old November 6th, 2003, 06:10 PM
Arkamir Arkamir is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 36 Arkamir User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
more stuff

This is posttemplate:
<div class="postholder">
<div class="name">
<br>
<!--INSERT NAME HERE--> <br>
<p>Posted on: <!--INSERT DATE HERE--> </p>

</div>
<div class="subject">
<!--INSERT SUBJECT HERE--> </div>
<div class="post">
<br>
<br>
<!--INSERT POST HERE-->
<br>
<br>
<br>
<br>
<br>
<br>
</div>
</div>
This is the error message:
>>> import retrieveposts
>>> retrieveposts.retrieve_posts('general', 'Hello, World', 20)
Traceback (most recent call last):
File "<stdin>", line 1, in ? File "retrieveposts.py", line 45, in retrieve_posts

posts = re.sub(content2, post[1], posts)
File "/usr/lib/python2.2/sre.py", line 143, in sub return _compile(pattern, 0).sub(repl, string, count)

File "/usr/lib/python2.2/sre.py", line 257, in _subx template = _compile_repl(template, pattern) File "/usr/lib/python2.2/sre.py", line 242, in _compile_repl

p = sre_parse.parse_template(repl, pattern) File "/usr/lib/python2.2/sre_parse.py", line 644, in parse_template

s = Tokenizer(source) File "/usr/lib/python2.2/sre_parse.py", line 186, in __init__ self.__next()

File "/usr/lib/python2.2/sre_parse.py", line 188, in __next

if self.index >= len(self.string):

TypeError: len() of unsized object>>>

Thanks for the help
Conrad

ps make the the text box bigger i dont know how to format it so it appears nicely

Reply With Quote
  #3  
Old November 6th, 2003, 08:40 PM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,529 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 17 h 18 m 50 sec
Reputation Power: 63
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
Hey Ark, normally to keep indentation in your code you want to put a [ CODE ][ /CODE ] tag around it (no spaces). Because this one is so big i think it would be best just to attache the file

Mark.
__________________
programming language development: www.netytan.com Hula


Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > RE and html and MySQL need help


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway