jindan

Untitled

Aug 1st, 2013
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.68 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. import re
  3. import MySQLdb
  4.  
  5. pattern = re.compile('@(.*)@.*$')
  6.  
  7. conn = MySQLdb.connect(
  8.     host='localhost', user='root',
  9.     passwd='password', db='j314', charset='utf8')
  10. cursor = conn.cursor()
  11.  
  12. cursor.execute(
  13.     """select `id`, `created_by_alias` from w0z9v_content where `catid` = 13 AND `created_by_alias` regexp "^@.*@.*$" limit 400""")
  14.  
  15. aliases = cursor.fetchall()
  16. for alias in aliases:
  17.     # print alias
  18.     newalias = pattern.match(alias[1])
  19.     # print newalias
  20.     if newalias.group(1) is not None:
  21.         cursor.execute("""
  22.        update w0z9v_content set `created_by_alias`=%s where `id`  = '%s'""", (newalias.group(1), alias[0]))
  23. conn.close
Advertisement
Add Comment
Please, Sign In to add comment