for row in rows: postnode = dom.createElement('post') # un-escape htmlchars in subject row['post_subject'] = row['post_subject'].replace("&","&").replace(""",'"').replace("<","<").replace(">",">") # set attributes export_fields = ["post_username", "post_subject", "username", "post_id"] for attr in export_fields: postnode.setAttribute(attr, str(row[attr]).decode(IN_ENCODING)) tstruct = time.gmtime( row["post_time"]) postnode.setAttribute('post_time', time.strftime("%m/%d/%Y, %H:%M:%S CET", tstruct)) # add posting text posting_text = cleanTextFromControlChars(row['post_text'].decode(IN_ENCODING)) txt = dom.createElement('text') if row['enable_bbcode']: posting_text = transformPostingText(posting_text) txt.appendChild(dom.createCDATASection(posting_text)) postnode.appendChild(txt) # add tags for t in tags: tagnode = dom.createElement('tag') tagnode.setAttribute('name', t) postnode.appendChild(tagnode) # add posting to thread threadnode.appendChild(postnode)
##pattern = re.compile(r'\b(' + '|'.join(d.keys()) + r')\b') #result = pattern.sub(lambda x: d[x.group()], s) return safe_unicode(result) dom = Document() dom.appendChild(dom.createElement('export')) # load categories lookup sql_str = "select * from nuke_postcalendar_categories" cursor = conn.cursor(MySQLdb.cursors.DictCursor) cursor.execute(sql_str) rows = cursor.fetchall() categories = {} for cat in rows: categories[str(cat['pc_catid'])] =\ cleanTextFromControlChars(str(cat['pc_catname'])) test_set = True custom_limit = "" if len(sys.argv) > 1: if sys.argv[1] == "all": test_set = False else: test_set = False custom_limit = sys.argv[1] # select topics for export sql_str = "select * from nuke_postcalendar_events where pc_eventstatus = 1" if test_set: sql_str = sql_str + " order by RAND() limit 0,200" elif custom_limit != "":