def main(): print "Start get users'posts!" # Start thread get post: t = threading.Thread(target=inintThread) t.start() try: t.join() except: print 'thread t join fail' # # write post: #global list_post, list_comment dbHangler.wire_convert_file(config.f_user_posts, list_post) #dbHangler.wire_convert_file(config.f_user_comments, list_comment) # global total_post total_post += len(list_post) # print 'Total post: ', total_post #print 'Total comment: ', total_comment # end_time = time.time() print 'Read %d users in %d second' % ((end - start), (end_time - start_time)) # return 0
def main(): #print "Start get friend's imformation!" # get all Id exited in DB #global end, start #global start_time # Inint t = threading.Thread(target = inintThread) t.start() try: t.join() except: print 'thread t join fail' # print list (user) global list_infor dbHangler.wire_convert_file(config.f_user_infor, list_infor) global total_infor total_infor += len(list_infor) print 'Total infor: ', total_infor # end_time = time.time() print 'Read %d users in %d second'%((end - start), (end_time - start_time)) # return 0
def handling(fb_id): ################################################# # # # Get post and comment information # # # ################################################# # # 1. Send respon and get request data: # 1.1. inint feilds for request: _f_id = 'id' _f_created_time = 'created_time' _f_message = 'message' # _f_reactions = 'reactions' _f_likes = 'likes' _f_shares = 'shares' # list friend request #_f_comment = 'comments{id,from,created_time,like_count,message}' # since and until _since = config.time_since.strip() _until = config.time_until.strip() if _until: since = '&since=' + _since if _until: until = '&until=' + _until try: #global graph # _fields = '/posts?fields=%(_f_id)s,%(_f_created_time)s,%(_f_message)s,%(_f_likes)s,%(_f_shares)s%(since)s%(until)s' % locals( ) # 1.2 : ininit request : _request = '%(fb_id)s%(_fields)s' % locals() # 1.3 : Send request and get respon data: respon = graph.get_object(_request) # 2 : Conver data to update DB : try: #list_comments_of_user = [] list_posts = respon['data'] if len(list_posts) == 0: return # Conver posts : for post in list_posts: # add post's user post['from'] = fb_id # shares : dictonary {"count" : int} => int try: post[_f_shares] = post[_f_shares]['count'] except: post[_f_shares] = 0 try: post[_f_likes] = post[_f_likes]['count'] except: post[_f_likes] = 0 # 3 : Save to DB # write list post file and list_comments_of_user : #global list_post, list_comment, total_post, total_comment global add_data_lock add_data_lock.acquire() # add to list global list_post list_post.extend(list_posts) #list_comment.extend(list_comments_of_user) # # increase read succes: global read_succes read_succes += 1 # release lock add_data_lock.release() # # if length of list > length in config => write to DB if (len(list_post) > config.post_len): add_data_lock.acquire() # clone list list_data = [item for item in list_post] # clear list : global total_post list_post = [] add_data_lock.release() # write data : write_data_lock.acquire() # dbHangler.wire_convert_file(config.f_user_posts, list_data) # increate total post total_post += len(list_data) # write_data_lock.release() except IOError as err: print "Get information of user Error at Step 2 in Handling", print err except facebook.GraphAPIError as err: print err return
def handling(fb_id): ################################################# # # # Get information of User # # # ################################################# #1. Send respon and get request data: #1.1. Inint feilds for request: _f_id = 'id' _f_name = 'name' _f_locale = 'locale' _f_hometown = 'hometown' _f_location = 'location' _f_email = 'email' _f_birthday = 'birthday' try: # 1.2 : inint request : _fields = '?fields=' + _f_id + ',' + _f_name + ',' +\ _f_locale + ',' + _f_hometown + ',' + _f_location + ',' +\ _f_email + ',' + _f_birthday # _request = str(fb_id) + _fields # 1.3 : Send request and get respon data: #global graph respon = graph.get_object(_request) # 2 : Conver data to update DB try: # convert : # Hometown try: respon[_f_hometown] = respon[_f_hometown]['name'] except: respon[_f_hometown] = "" #_f_location try: respon[_f_location] = respon[_f_location]['name'] except: respon[_f_location] = "" # #print respon # Update DB : # Get lock #global add_data_lock global list_infor global read_succe # Get lock add_data_lock.acquire() # add to list list_infor.append(respon) # increase read_succes read_succe += 1 # add_data_lock.release() # # if (len(list_infor) > config.post_len): add_data_lock.acquire() _list_data = [item for item in list_infor] list_infor = [] add_data_lock.release() # global total_infor write_data_lock.acquire() dbHangler.wire_convert_file(config.f_user_infor, _list_data) total_infor += len(_list_data) write_data_lock.release() except IOError as err: dbHangler.logMessage('error', "Get information of user Error at Step 3") add_data_lock.release() print err except facebook.GraphAPIError as err: #print err, "\n", fb_id print '.', return
def handling(uids): ################################################# # # # Get information of User # # # ################################################# #1. Send respon and get request data: #1.1. Inint feilds for request: _f_id = 'id' _f_name = 'name' _f_locale = 'locale' _f_hometown = 'hometown' _f_location = 'location' _f_email = 'email' _f_birthday = 'birthday' _f_updated_time= 'updated_time' try: # 1.2 : inint request : _fields = '&fields=%(_f_id)s,%(_f_name)s,%(_f_locale)s,%(_f_hometown)s,%(_f_location)s,%(_f_email)s,%(_f_birthday)s,%(_f_updated_time)s'% locals() # _request = '?ids=%s%s' % (','.join(uids), _fields) # 1.3 : Send request and get respon data: #global graph respon = graph.get_object(_request) # 2 : Conver data to update DB try: _list_infor = [] for v in respon.values(): # convert : an id: # Hometown try: v[_f_hometown] = v[_f_hometown]['name'] except: v[_f_hometown] = "" #_f_location try: v[_f_location] = v[_f_location]['name'] except: v[_f_location] = "" # Add user infor to _list_infor _list_infor.append(v) #print respon # Update DB : # Get lock #global add_data_lock global list_infor global read_succe # Get lock add_data_lock.acquire() try: # add to list list_infor.extend(_list_infor) # increase read_succes read_succe += len(_list_infor) finally: # add_data_lock.release() # # if (len(list_infor) > config.post_len): add_data_lock.acquire() try: _list_data = [item for item in list_infor] list_infor = [] finally: add_data_lock.release() # global total_infor write_data_lock.acquire() try: dbHangler.wire_convert_file(config.f_user_infor, _list_data) total_infor += len(_list_data) finally: write_data_lock.release() TODO: Hanglder Exception faill except FacebookRequestError as fbErr: # _message = "Code error: %s\t Message: %s" % (fbErr.api_error_code(), fbErr.get_message()) dbHangler.logMessage('error', "Get information of user Error at Step 3\n%s"%(_message))