Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 48 additions & 57 deletions docs/html/pattern-web.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions examples/01-web/01-google.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
# The pattern.web module has a SearchEngine class,
# with a SearchEngine.search() method that yields a list of Result objects.
# Each Result has url, title, text, language, author and date and properties.
# Subclasses of SearchEngine include:
# Google, Bing, Yahoo, Twitter, Facebook, Wikipedia, Wiktionary, Flickr, ...
# Subclasses of SearchEngine include:
# Google, Bing, Twitter, Facebook, Wikipedia, Wiktionary, Flickr, ...

# This example retrieves results from Google based on a given query.
# The Google search engine can handle SEARCH type searches.
Expand All @@ -17,7 +17,7 @@
# The pattern.web module uses a test account by default,
# with a 100 free queries per day shared by all Pattern users.
# If this limit is exceeded, SearchEngineLimitError is raised.
# You should obtain your own license key at:
# You should obtain your own license key at:
# https://code.google.com/apis/console/
# Activate "Custom Search API" under "Services" and get the key under "API Access".
# Then use Google(license=[YOUR_KEY]).search().
Expand Down
8 changes: 4 additions & 4 deletions examples/01-web/11-facebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# 1) Searching for public status updates.
# Search for all status updates that contain the word "horrible".

try:
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.
Expand All @@ -33,7 +33,7 @@
# 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):
for status in fb.search(262588213843476, count=25, cached=False):
print "=" * 100
print status.id
print status.text
Expand All @@ -59,8 +59,8 @@
if license != "":
fb = Facebook(license)
# Facebook.profile() returns a dictionary with author info.
# By default, this is your own profile.
# You can also supply the id of another profile,
# By default, this is your own profile.
# You can also supply the id of another profile,
# or the name of a product page.
me = fb.profile()["id"]
for status in fb.search(me, type=NEWS, count=30, cached=False):
Expand Down
18 changes: 9 additions & 9 deletions examples/01-web/15-sort.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
import os, sys; sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", ".."))

from pattern.web import GOOGLE, YAHOO, BING, sort
from pattern.web import GOOGLE, BING, sort

# The pattern.web module includes an interesting sort() algorithm.
# Ir classifies search terms according to a search engine's total results count.
# When a context is defined, it sorts according to relevancy to the context:
# sort(terms=["black", "green", "red"], context="Darth Vader") =>
# yields "black" as the best candidate,
# yields "black" as the best candidate,
# because "black Darth Vader" yields more search results.

results = sort(
terms = [
"arnold schwarzenegger",
"chuck norris",
"dolph lundgren",
"arnold schwarzenegger",
"chuck norris",
"dolph lundgren",
"steven seagal",
"sylvester stallone",
"sylvester stallone",
"mickey mouse",
],
context = "dangerous", # Term used for sorting.
service = BING, # GOOGLE, YAHOO, BING, ...
service = BING, # GOOGLE, BING, ...
license = None, # You should supply your own API license key for the given service.
strict = True, # Wraps the query in quotes, i.e. 'mac sweet'.
strict = True, # Wraps the query in quotes, i.e. 'mac sweet'.
reverse = True, # Reverses term and context: 'sweet mac' instead of 'mac sweet'.
cached = True)

for weight, term in results:
print "%5.2f" % (weight * 100) + "%", term
Loading