<filename>helper.py
import requests
import pandas as pd
import tweepy #for twitter
import os
from bs4 import BeautifulSoup
import praw #for reddit
import requests
import requests.auth



def getTweets(search_terms=['counterfeit','amazonHelp']):
	consumer_key = '6CM1Yqk0Qz6KUXsDQUS8xmahS'
	consumer_secret = '<KEY>'
	access_token = '<KEY>'
	access_token_secret = '<KEY>'
	auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
	auth.set_access_token(access_token, access_token_secret)
	api = tweepy.API(auth)


	cfit_tweets = api.search(q=search_terms, count=1000)

	df = pd.DataFrame()
	df['text'] = [x.text for x in cfit_tweets]
	df['source'] = ['twitter: "counterfiet, amazonelp"' for x in cfit_tweets]
	df['url'] = [x.text[x.text.find('http'):].split('\n')[0] for x in cfit_tweets]
	df['retweets'] = [x.retweet_count for x in cfit_tweets]
	df['favorites'] = [x.favorite_count for x in cfit_tweets]
	df['iframe'] = ['https://twitframe.com/show?url=https://twitter.com/{}/status/{}'.format(x.user.screen_name, x.id) for x in cfit_tweets]

	keys = ['t'+str(x) for x in range(len(df['iframe'].tolist()))]
	values = df['iframe'].tolist()
	return dict(zip(keys, values))

def getReddits():
	'''
	#1. Get Token
	client_auth = requests.auth.HTTPBasicAuth('BXTDVNZqv8SFyw', '<KEY>')
	post_data = {"grant_type": "password", "username": "whs2k", "password": "<PASSWORD>"}
	headers = {"User-Agent": "ChangeMeClient/0.1 by YourUsername"}
	response = requests.post("https://www.reddit.com/api/v1/access_token", auth=client_auth, data=post_data, headers=headers)
	#response.json()


	#2. Use Token 
	headers = {"Authorization": "bearer <KEY>", "User-Agent": "ChangeMeClient/0.1 by YourUsername"}
	response = requests.get("https://oauth.reddit.com/api/v1/me", headers=headers)
	#response.json()
	'''

	reddit = praw.Reddit(client_id='BXTDVNZqv8SFyw',
                     client_secret='<KEY>',
                     password='<PASSWORD>',
                     user_agent='testscript by /u/whs2k',
                     username='whs2k')
	if reddit.read_only:
		print('We Are Connected to Reddit!')

	#search terms controversial, gilded, hot, new, rising, top'''
	png_urls = [x.url for x in reddit.subreddit('FulfillmentByAmazon').new(limit=1000) if '.png' in x.url]
	print('We have {} png urls'.format(len(png_urls)))

	keys = ['<KEY>) for x in range(len(df['iframe'].tolist()))]
	return dict(zip(keys, png_urls))


def getTweetsDF():
	consumer_key = '<KEY>'
	consumer_secret = '<KEY>'
	access_token = '<KEY>'
	access_token_secret = '<KEY>'
	auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
	auth.set_access_token(access_token, access_token_secret)
	api = tweepy.API(auth)


	cfit_tweets = api.search(q=['counterfeit','amazonHelp'], count=1000)
	fake_tweets = api.search(q=['fake','amazonHelp'], count=1000)

	df = pd.DataFrame()
	df['text'] = [x.text for x in cfit_tweets]
	df['source'] = ['twitter: "counterfiet, amazonelp"' for x in cfit_tweets]
	df['url'] = [x.text[x.text.find('http'):].split('\n')[0] for x in cfit_tweets]
	df['retweets'] = [x.retweet_count for x in cfit_tweets]
	df['favorites'] = [x.favorite_count for x in cfit_tweets]
	df['iframe'] = ['https://twitframe.com/show?url=https://twitter.com/{}/status/{}'.format(x.user.screen_name, x.id) for x in cfit_tweets]

	df1 = pd.DataFrame()
	df1['text'] = [x.text for x in fake_tweets]
	df1['source'] = ['twitter: "fake, amazonHelp"' for x in fake_tweets]
	df1['url'] = [x.text[x.text.find('http'):].split('\n')[0] for x in fake_tweets]
	df1['retweets'] = [x.retweet_count for x in fake_tweets]
	df1['favorites'] = [x.favorite_count for x in fake_tweets]
	df1['iframe'] = ['https://twitframe.com/show?url=https://twitter.com/{}/status/{}'.format(x.user.screen_name, x.id) for x in fake_tweets]


	df_final = df.append(df1)
	df_final.sort_values('retweets',ascending=False).drop_duplicates(['text','source']).reset_index().head(50)

	keys = ['t1', 't2']
	keys = ['t'+str(x) for x in range(len(df1['iframe'].tolist()))]
	values = df1['iframe'].tolist()
	return dict(zip(keys, values))


<filename>helper.py
import requests
import pandas as pd
import tweepy #for twitter
import os
from bs4 import BeautifulSoup
import praw #for reddit
import requests
import requests.auth



def getTweets(search_terms=['counterfeit','amazonHelp']):
	consumer_key = '6CM1Yqk0Qz6KUXsDQUS8xmahS'
	consumer_secret = '<KEY>'
	access_token = '<KEY>'
	access_token_secret = '<KEY>'
	auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
	auth.set_access_token(access_token, access_token_secret)
	api = tweepy.API(auth)


	cfit_tweets = api.search(q=search_terms, count=1000)

	df = pd.DataFrame()
	df['text'] = [x.text for x in cfit_tweets]
	df['source'] = ['twitter: "counterfiet, amazonelp"' for x in cfit_tweets]
	df['url'] = [x.text[x.text.find('http'):].split('\n')[0] for x in cfit_tweets]
	df['retweets'] = [x.retweet_count for x in cfit_tweets]
	df['favorites'] = [x.favorite_count for x in cfit_tweets]
	df['iframe'] = ['https://twitframe.com/show?url=https://twitter.com/{}/status/{}'.format(x.user.screen_name, x.id) for x in cfit_tweets]

	keys = ['t'+str(x) for x in range(len(df['iframe'].tolist()))]
	values = df['iframe'].tolist()
	return dict(zip(keys, values))

def getReddits():
	'''
	#1. Get Token
	client_auth = requests.auth.HTTPBasicAuth('BXTDVNZqv8SFyw', '<KEY>')
	post_data = {"grant_type": "password", "username": "whs2k", "password": "<PASSWORD>"}
	headers = {"User-Agent": "ChangeMeClient/0.1 by YourUsername"}
	response = requests.post("https://www.reddit.com/api/v1/access_token", auth=client_auth, data=post_data, headers=headers)
	#response.json()


	#2. Use Token 
	headers = {"Authorization": "bearer <KEY>", "User-Agent": "ChangeMeClient/0.1 by YourUsername"}
	response = requests.get("https://oauth.reddit.com/api/v1/me", headers=headers)
	#response.json()
	'''

	reddit = praw.Reddit(client_id='BXTDVNZqv8SFyw',
                     client_secret='<KEY>',
                     password='<PASSWORD>',
                     user_agent='testscript by /u/whs2k',
                     username='whs2k')
	if reddit.read_only:
		print('We Are Connected to Reddit!')

	#search terms controversial, gilded, hot, new, rising, top'''
	png_urls = [x.url for x in reddit.subreddit('FulfillmentByAmazon').new(limit=1000) if '.png' in x.url]
	print('We have {} png urls'.format(len(png_urls)))

	keys = ['<KEY>) for x in range(len(df['iframe'].tolist()))]
	return dict(zip(keys, png_urls))


def getTweetsDF():
	consumer_key = '<KEY>'
	consumer_secret = '<KEY>'
	access_token = '<KEY>'
	access_token_secret = '<KEY>'
	auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
	auth.set_access_token(access_token, access_token_secret)
	api = tweepy.API(auth)


	cfit_tweets = api.search(q=['counterfeit','amazonHelp'], count=1000)
	fake_tweets = api.search(q=['fake','amazonHelp'], count=1000)

	df = pd.DataFrame()
	df['text'] = [x.text for x in cfit_tweets]
	df['source'] = ['twitter: "counterfiet, amazonelp"' for x in cfit_tweets]
	df['url'] = [x.text[x.text.find('http'):].split('\n')[0] for x in cfit_tweets]
	df['retweets'] = [x.retweet_count for x in cfit_tweets]
	df['favorites'] = [x.favorite_count for x in cfit_tweets]
	df['iframe'] = ['https://twitframe.com/show?url=https://twitter.com/{}/status/{}'.format(x.user.screen_name, x.id) for x in cfit_tweets]

	df1 = pd.DataFrame()
	df1['text'] = [x.text for x in fake_tweets]
	df1['source'] = ['twitter: "fake, amazonHelp"' for x in fake_tweets]
	df1['url'] = [x.text[x.text.find('http'):].split('\n')[0] for x in fake_tweets]
	df1['retweets'] = [x.retweet_count for x in fake_tweets]
	df1['favorites'] = [x.favorite_count for x in fake_tweets]
	df1['iframe'] = ['https://twitframe.com/show?url=https://twitter.com/{}/status/{}'.format(x.user.screen_name, x.id) for x in fake_tweets]


	df_final = df.append(df1)
	df_final.sort_values('retweets',ascending=False).drop_duplicates(['text','source']).reset_index().head(50)

	keys = ['t1', 't2']
	keys = ['t'+str(x) for x in range(len(df1['iframe'].tolist()))]
	values = df1['iframe'].tolist()
	return dict(zip(keys, values))


#for twitter #for reddit #1. Get Token 	client_auth = requests.auth.HTTPBasicAuth('BXTDVNZqv8SFyw', '<KEY>') 	post_data = {"grant_type": "password", "username": "whs2k", "password": "<PASSWORD>"} 	headers = {"User-Agent": "ChangeMeClient/0.1 by YourUsername"} 	response = requests.post("https://www.reddit.com/api/v1/access_token", auth=client_auth, data=post_data, headers=headers) 	#response.json()   	#2. Use Token  	headers = {"Authorization": "bearer <KEY>", "User-Agent": "ChangeMeClient/0.1 by YourUsername"} 	response = requests.get("https://oauth.reddit.com/api/v1/me", headers=headers) 	#response.json() #search terms controversial, gilded, hot, new, rising, top'''