Esempio n. 1
0
def get_info(search_query):
	if isinstance(search_query, str):
		search_query = str(search_query)
	else:
		return { "Error": "Pass a string, from mine.py [7]", "Result": [None] }

	result = []
	engineGoogle = Google(license=None, throttle=0.5, language=None)
	engineBing = Bing(license=None, throttle=0.5, language=None)
	engineTwitter = Twitter(license=None, throttle=0.5, language=None)
	engineFacebook = Facebook(license=None, throttle=1.0, language='en')
	engineWikipedia = Wikipedia(license=None, throttle=5.0, language=None)
	engineFlickr = Flickr(license=None, throttle=5.0, language=None)
	engineArray = [engineGoogle, engineBing, engineTwitter, engineFacebook, engineWikipedia, engineFlickr]
	engineArray = [engineGoogle, engineTwitter]

	'''
	for i in range(1,2):
		# result = result + ([repr(plaintext(para.text)) for para in engine[0].search(search_query, type=SEARCH, start=i, count=5)])
		[result.append([result.append(repr(plaintext(para.text))) for para in engine.search(search_query, type=SEARCH, start=i, count=5)]) for engine in engineArray]
			# print repr(plaintext(para.text))
			# print repr(plaintext(para.url)) + '\n\n'
			# result.append(repr(plaintext(para.text)))
	'''

	# Google
	for i in range(1, 5):
		result = result + ([para.text for para in engineGoogle.search(search_query, type=SEARCH, start=i, count=10)])
		
	for i in range(1, 5):
		result = result + ([para.text for para in engineTwitter.search(search_query, type=SEARCH, start=i, count=10)])
	'''
	# for i in range(1,2):
		# result = result + ([repr(plaintext(para.text)) for para in engineBing.search(search_query, type=SEARCH, start=i, count=5)])
	for i in range(1,2):
		result = result + ([repr(plaintext(para.text)) for para in engineTwitter.search(search_query, type=SEARCH, start=i, count=10)])
	# for i in range(1,2):
		# result = result + ([repr(plaintext(para.text)) for para in engineFacebook.search(search_query, type=SEARCH, start=i, count=5)])
	# for i in range(1,2):
		# result = result + ([repr(plaintext(para.text)) for para in engineWikipedia.search(search_query, type=SEARCH, start=i, count=5)])
	# for i in range(1,2):
		# result = result + ([repr(plaintext(para.text)) for para in engineFlickr.search(search_query, type=SEARCH, start=i, count=5)])
	'''

	return { "Error": None, "Result": result }

	# return { "Error": None, "Result": ['Hello World', 'Bye Bye Tommy'] }
Esempio n. 2
0
def fetch_data(data="facebook.pickle",
               friends_count=1000,
               news_count=100,
               key='REMOVED MY KEY'):
    """ Fetches link data from given key for the specified number 
		of friends and the specified number of posts and saves it
		to a facebook.pickle file

		data: name of data file to save to (default: facebook.pickle)
		friends_count: number of friends to search through (default: 1000)
		news_count: number of each friends' posts to search through (default: 100)
		key: the key for pattern to access Facebook
	"""
    print "Fetching data..."

    # Get the data
    fb = Facebook(license=key)
    me = fb.profile()
    print me
    counter = 1

    link_counts = {"num_posts": 0, "num_links": 0, "num_texts": 0}

    my_friends = fb.search(me[0], type=FRIENDS, count=friends_count)
    for friend in my_friends:
        print counter
        counter += 1
        friend_news = fb.search(friend.id, type=NEWS, count=news_count)
        for news in friend_news:
            link_counts["num_posts"] += 1
            if news.url:
                link_counts["num_links"] += 1
                if news.url in link_counts:
                    link_counts[news.url][0] += 1
                    link_counts[news.url][1] += news.likes
                else:
                    link_counts[news.url] = [1, news.likes]

    # Save the data to a file
    f = open(data, 'w')
    cPickle.dump(link_counts, f)
    f.close()
Esempio n. 3
0
#    Search for all status updates that contain the word "horrible".

try:
    # We'll store the status updates in a Datasheet.
    # A Datasheet is a table of rows and columns that can be exported as a CSV-file.
    # In the first column, we'll store a unique id for each status update.
    # We only want to add new status updates, i.e., those we haven't seen yet.
    # With an index on the first column we can quickly check if an id already
    # exists.
    table = Datasheet.load(pd("opinions.csv"))
    index = set(table.columns[0])
except:
    table = Datasheet()
    index = set()

fb = Facebook()

# With Facebook.search(cached=False), a "live" request is sent to Facebook:
# we get the most recent results instead of those in the local cache.
# Keeping a local cache can also be useful (e.g., while testing)
# because a query is instant when it is executed the second time.
for status in fb.search("horrible", count=25, cached=False):
    print("=" * 100)
    print(status.id)
    print(status.text.encode("utf-8"))
    print(status.author)  # Yields an (id, name)-tuple.
    print(status.date)
    print(status.likes)
    print(status.comments)
    print()
    # Only add the tweet to the table if it doesn't already exists.
Esempio n. 4
0
from pattern.web import Facebook, NEWS, COMMENTS, LIKES

fb = Facebook(license='CAACEdEose0cBAD0FqhYX26Tg9h7062f5KxELjcZC6mt91UeyRYNeUJb8WZA\
	eJZCELWSCqqeTL7SkwbVkgyV3PxVXCnNoa0o6ywdNtSa0AmW8n7oifV5l5ImQZBBXSWD9lEE8o4pggBz\
	p9NLV5x4vqcwdyW2xZB9CcHCylZBqURoQqrwZBcpTdZATZCs5BkX0WP964JdWoO7quMg40HImUv6WA')

me = fb.profile(id='10203550007847585') 

def get_posts():
	for post in fb.search(me[0], type=NEWS, count=10):
		print 'post :'+ repr(post.text) +' likes :'+ repr(post.likes)

#Navegue, acceda al chat, mire videos, revise sus correos y redes sociales desde su celular. 
#Recargue el saldo de su telefono y adquiera el Paquete de Internet en cualquier momento y lugar. Solo tiene que enviar un mensaje de texto al 779 con la palabra clave indicada en el siguiente recuadro:
#200 MB	5D
#700 MB	10D
Esempio n. 5
0
# This example retrieves facebook publis status updates containing given keyword.

try: 
    # We store status in a Table that can be saved as a text file.
    # In the first column, we'll store a unique ID for each tweet.
    # We only want to add the latest facebook status, i.e. those we haven't previously encountered.
    # With an index on the first column we can quickly check if an ID already exists.
    # The index becomes important once more and more rows are added to the table (speed).
    table = Datasheet.load("travel.txt")
    index = dict.fromkeys(table.columns[0], True)
except:
    table = Datasheet()
    index = {}

engine = Facebook()

# With cached=False, a live request is sent to Facebook,
# so we get the latest results for the query instead of those in the local cache.
for status in engine.search("Travelling to", count=25, cached=False):
    print status.description
    print status.author
    print status.date
    print
    id = status.url
    # Only add the tweet to the table if it doesn't already contain this ID.
    if len(table) == 0 or id not in index:
        table.append([id, status.description])
        index[id] = True

table.save("travel.txt")
# -*- coding: utf-8 -*-

"""
Pattern.web can be used to extract information from Wikipedia, Facebook, Twitter, etc
Find out more: https://www.clips.uantwerpen.be/pages/pattern-web
"""

from pattern.web import Facebook
from pattern.en import sentiment
from pattern.web import Facebook, NEWS, COMMENTS, LIKES

fb = Facebook(license='568752540312810')
me = fb.profile(id=568752540312810) # user info dict

for post in fb.search(me['id'], type=NEWS, count=100):
    print repr(post.id)
    print repr(post.text)
    print repr(post.url)
    if post.comments > 0:
        print '%i comments' % post.comments 
        print [(r.text, r.author) for r in fb.search(post.id, type=COMMENTS)]
    if post.likes > 0:
        print '%i likes' % post.likes 
        print [r.author for r in fb.search(post.id, type=LIKES)]
"""
facebook = Facebook()
someTweet = None
feeling = ""

for j in range(1):
    for post in facebook.search('Teressa May', start=someTweet, count=1):