#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Posts
    36
    Rep Power
    12

    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
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Posts
    36
    Rep Power
    12

    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
  4. #3
  5. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    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


IMN logo majestic logo threadwatch logo seochat tools logo