Skip to content

Instantly share code, notes, and snippets.

@yume190
Created August 31, 2014 14:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yume190/53e525a493e9c2065c68 to your computer and use it in GitHub Desktop.
Save yume190/53e525a493e9c2065c68 to your computer and use it in GitHub Desktop.
Python MySQL
#!/usr/bin/python
# -*- coding: utf-8 -*-
import facebook
# 引入 MySQL 模組
import MySQLdb
# 連接到 MySQL
db = MySQLdb.connect(host="x.x.x.x", user="yume", passwd="xxxx", db="xData",charset="utf8",use_unicode = True)
cursor = db.cursor()
#cursor.execute("SELECT fid from memberlist")
cursor.execute("SELECT * from memberlist")
result = cursor.fetchall()
graph = facebook.GraphAPI()
for record in result:
#graph = facebook.GraphAPI()
#user = graph.get_object(record)
#cursor.execute("update memberlist set FBID = '%s' where fid = '$%s' "%(record,user[id]))
#if(record[0] == 43):
try:
user = graph.get_object(record[3])
#print user
sql = "update memberlist set FBID = '%s' where fid = '%s' "%(user['id'],record[3])
cursor.execute(sql)
sql = "update memberlist set facebookname = '%s' where fid = '%s' "%(user['name'],record[3])
cursor.execute(sql)
except:
print "Number : ",record[0]
#print "Number : ",record[0]
#print "DB : ",record
#print "fb : ",user
#print (record[3],user['id'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment