def fetch_twitter_post(handle_id,tag_data_dict): auth = tweepy.OAuthHandler(consumer_key, consumer_secret) auth.set_access_token(access_token, access_token_secret) api = tweepy.API(auth) page_post= models.Page.objects.get(page_id= handle_id) for status in tweepy.Cursor(api.user_timeline,id=handle_id,count=200,exclude_replies=True).items(4000): (tweet_data_save, tweet_data_save_status)= models.Posts.objects.update_or_create(post_id=str(status.id), defaults={'page_id': page_post,'message': str(status.text.encode('utf-8')),'created_time': str(status.created_at),'updated_time': str(status.created_at)}) nl.nl_main_func(str(status.text.encode('utf-8')),str(status.id),tag_data_dict) print (tweet_data_save, tweet_data_save_status)
def get_posts_data(page_id, access_token, tag_data_dict): graph = GraphAPI(access_token) #page_id= 'flipkart' data = graph.get( page_id + "/posts?fields=id,created_time,updated_time,message,description&limit=100", page=True, retry=5) page_post = models.Page.objects.get(page_id=page_id) #transaction.set_autocommit(False) for i in data: #print i['data'] for post_data in i['data']: print post_data if 'description' in post_data and 'message' in post_data: (post_data_save, post_data_save_status ) = models.Posts.objects.update_or_create( post_id=str(post_data['id']), defaults={ 'page_id': page_post, 'message': post_data['message'], 'description': post_data['description'], 'created_time': post_data['created_time'], 'updated_time': post_data['updated_time'] }) nl.nl_main_func(post_data['message'], str(post_data['id']), tag_data_dict) nl.nl_main_func(post_data['description'], str(post_data['id']), tag_data_dict) elif 'description' not in post_data and 'message' in post_data: (post_data_save, post_data_save_status ) = models.Posts.objects.update_or_create( post_id=str(post_data['id']), defaults={ 'page_id': page_post, 'message': post_data['message'], 'created_time': post_data['created_time'], 'updated_time': post_data['updated_time'] }) nl.nl_main_func(post_data['message'], str(post_data['id']), tag_data_dict) elif 'description' in post_data and 'message' not in post_data: (post_data_save, post_data_save_status ) = models.Posts.objects.update_or_create( post_id=str(post_data['id']), defaults={ 'page_id': page_post, 'description': post_data['description'], 'created_time': post_data['created_time'], 'updated_time': post_data['updated_time'] }) nl.nl_main_func(post_data['description'], str(post_data['id']), tag_data_dict) else: pass print(post_data_save, post_data_save_status)
def fetch_twitter_post(handle_id, tag_data_dict): auth = tweepy.OAuthHandler(consumer_key, consumer_secret) auth.set_access_token(access_token, access_token_secret) api = tweepy.API(auth) page_post = models.Page.objects.get(page_id=handle_id) for status in tweepy.Cursor(api.user_timeline, id=handle_id, count=200, exclude_replies=True).items(4000): (tweet_data_save, tweet_data_save_status) = models.Posts.objects.update_or_create( post_id=str(status.id), defaults={ 'page_id': page_post, 'message': str(status.text.encode('utf-8')), 'created_time': str(status.created_at), 'updated_time': str(status.created_at) }) nl.nl_main_func(str(status.text.encode('utf-8')), str(status.id), tag_data_dict) print(tweet_data_save, tweet_data_save_status)
def get_posts_data(page_id,access_token,tag_data_dict): graph = GraphAPI(access_token) #page_id= 'flipkart' data= graph.get(page_id+ "/posts?fields=id,created_time,updated_time,message,description&limit=100", page=True, retry=5) page_post= models.Page.objects.get(page_id= page_id) #transaction.set_autocommit(False) for i in data: #print i['data'] for post_data in i['data']: print post_data if 'description' in post_data and 'message' in post_data: (post_data_save, post_data_save_status)= models.Posts.objects.update_or_create(post_id=str(post_data['id']), defaults={'page_id': page_post,'message': post_data['message'],'description': post_data['description'],'created_time': post_data['created_time'],'updated_time': post_data['updated_time']}) nl.nl_main_func(post_data['message'],str(post_data['id']),tag_data_dict) nl.nl_main_func(post_data['description'],str(post_data['id']),tag_data_dict) elif 'description' not in post_data and 'message' in post_data: (post_data_save, post_data_save_status)= models.Posts.objects.update_or_create(post_id=str(post_data['id']), defaults={'page_id': page_post,'message': post_data['message'],'created_time': post_data['created_time'],'updated_time': post_data['updated_time']}) nl.nl_main_func(post_data['message'],str(post_data['id']),tag_data_dict) elif 'description' in post_data and 'message' not in post_data: (post_data_save, post_data_save_status)= models.Posts.objects.update_or_create(post_id=str(post_data['id']), defaults={'page_id': page_post,'description': post_data['description'],'created_time': post_data['created_time'],'updated_time': post_data['updated_time']}) nl.nl_main_func(post_data['description'],str(post_data['id']),tag_data_dict) else: pass print (post_data_save, post_data_save_status)