Skip to content
This repository
branch: experimental
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 61 lines (50 sloc) 2.127 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
import re
import web

#db = web.database(dbn='mysql', db='bb', user='root', pw='pass')
import config # ^ this is

db = config.db

def getTopics(fid):
return db.select('topics', order='id', where='fid='+str(fid))

def getTopic(s, tid):
return db.where('topics', slug=s, id=tid)

def getPosts(tid):
return db.where('posts', order='id', tid=str(tid))

def addTopic(t, b):
tt = t
        t = t.lower()
t = re.sub('[\s]+', '-', t)
t = re.sub(r'[^a-z0-9-]', '', t)
        result = db.insert('topics', uid=1, title=tt, date=1, fid=0, slug=t, replies=0)
        if(result):
db.update('topics', where='id=%s' % result, last_poster='%s' % 'johndoe')
return db.insert('posts', uid=1, body=b, date=1, tid=result)
        else:
                return 'error'
# SLUG TODO
#import re
#topic = topic.lower()
#topic = re.sub('[\s]+', '-', topic)
#topic = re.sub(r'[^a-z0-9-]', '', topic)
# return 'slug'
# db.insert(topics, uid=1,title=t, body=b, date=1, fid=0, slug=#TODO)

def addReply(id, reply, userid):
# TODO LASTPOST
# db.query('UPDATE LASTPOST ?
# db.update ?
replies_update = db.query('UPDATE topics SET replies=replies+1 WHERE id=%s' % id)
        post = db.insert('posts', uid=userid, body=reply, tid=id)
last_poster = db.update('topics', where='id=%s' % id, last_poster='%s' % 'johndoe')
return db.update('topics', where='id=%s' % id, last_post='%s' % post)
#last_post_update = db.update('topics', where='id=%s' % id, last_post='%s' % reply)
# last_post_update = db.query('UPDATE topics SET last_post=%s WHERE id=%s') % reply, id
# return db.query('UPDATE topics SET last_post=%s' % reply)

# return db.insert('posts', uid=userid, body=reply, tid=id)

# pid = postid, tid = topic-id
def delPost(pid, tid):
replies_update = db.query('UPDATE topics SET replies=replies-1 WHERE id=%s' % tid)
return db.delete('posts', where='id=%s' % pid)

def search(query):
# match against
a = db.query('SELECT title FROM topics WHERE MATCH(title) AGAINST (\'*%s*\' IN BOOLEAN MODE)' % query)
#b = db.query('SELECT body FROM posts WHERE MATCH(body) AGAINST (\'*%s*\' IN BOOLEAN MODE)' % query)
return a
Something went wrong with that request. Please try again.