Skip to content

Instantly share code, notes, and snippets.

@yume190
Created August 31, 2014 14:37
Show Gist options
  • Save yume190/53e525a493e9c2065c68 to your computer and use it in GitHub Desktop.
Save yume190/53e525a493e9c2065c68 to your computer and use it in GitHub Desktop.

Revisions

  1. yume190 created this gist Aug 31, 2014.
    35 changes: 35 additions & 0 deletions fb.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,35 @@
    #!/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'])