Created
August 31, 2014 14:37
-
-
Save yume190/53e525a493e9c2065c68 to your computer and use it in GitHub Desktop.
Python MySQL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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