SHARE
TWEET

DBuploadfaild

a guest Oct 22nd, 2017 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import json
  2. import pymysql
  3.  
  4.  
  5. conn = pymysql.connect(host=DB_HOST, user=DB_USER, password=DB_PASSWD,
  6.                    db=DB_NAME, charset='utf8')
  7.    
  8.  
  9.  
  10. with open("input.json", encoding="utf-8") as open_file:
  11.     data = json.load(open_file)
  12. for k in data["inputList"]:
  13.     print (k)
  14.     print(",".join(k), k.values())
  15. with conn.cursor() as cursor:
  16.     for k in data["inputList"]:
  17.         cs = ",".join(k)
  18.         cc = 'uid', 'board_id', 'parent_uid', 'member_uid', 'member_display', 'title', 'content', 'date', 'update', 'view', 'comment', 'like', 'unlike', 'vote', 'thumbnail_name', 'thumbnail_file', 'category1', 'search'
  19.         d1a= "'"+k['uid']+"'","'"+k['board_id']+"'","'"+k['parent_uid']+"'","'"+k['member_uid']+"'","'"+k['member_display']+"'","'"+k['title']+"'","'"+k['content']+"'","'"+k['date']+"'","'"+k['update']+"'","'"+k['view']+"'","'"+k['comment']+"'","'"+k['like']+"'","'"+k['unlike']+"'","'"+k['vote']+"'","'"+k['thumbnail_name']+"'","'"+k['thumbnail_file']+"'","'"+k['category1']+"'","'"+k['search']+"'"
  20.          
  21.         sql = "INSERT INTO wp_kboard_board_content (%s) VALUES (%s)"  
  22.         print(cc)
  23.        
  24.         cursor.execute(sql,(cc,d1a))
  25.        
  26.         conn.commit()
  27. conn.close()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top