Skip to content

Commit

Permalink
Support other URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
murray committed Jul 26, 2014
1 parent 17c1108 commit 4c3059c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 11 deletions.
4 changes: 1 addition & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,7 @@ Notes
- A standalone Windows executable with the howdoi application `is available here <https://dl.dropbox.com/u/101688/website/misc/howdoi.exe>`_.
- An Alfred Workflow for howdoi can be found at `http://blog.gleitzman.com/post/48539944559/howdoi-alfred-even-more-instant-answers <http://blog.gleitzman.com/post/48539944559/howdoi-alfred-even-more-instant-answers>`_.
- Howdoi uses a cache for faster access to previous questions. Caching functionality can be disabled by setting the HOWDOI_DISABLE_CACHE environment variable. The cache is stored in `~/.cache/howdoi`.
- You can use HOWDOI_LOCALIZATION environment variable to set the localization of your question. Using this will change the search url to the localization url of your choice. Current supported localizations are **en** and **pt-br**.
- Special thanks to Rich Jones
(`@miserlou <https://github.com/miserlou>`_) for the idea.
- You can set the HOWDOI_URL environment variable to change the source url for answers (default: stackoverflow.com).

Troubleshooting
---------------
Expand Down
10 changes: 2 additions & 8 deletions howdoi/howdoi.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,7 @@ def u(x):
else:
SEARCH_URL = 'https://www.google.com/search?q=site:{0}%20{1}'

LOCALIZATION = os.getenv('HOWDOI_LOCALIZATION') or 'en'

LOCALIZATON_URLS = {
'en': 'stackoverflow.com',
'pt-br': 'pt.stackoverflow.com',
}
URL = os.getenv('HOWDOI_URL') or 'stackoverflow.com'

USER_AGENTS = ('Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:11.0) Gecko/20100101 Firefox/11.0',
'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:22.0) Gecko/20100 101 Firefox/22.0',
Expand Down Expand Up @@ -100,8 +95,7 @@ def is_question(link):


def get_links(query):
localization_url = LOCALIZATON_URLS[LOCALIZATION]
result = get_result(SEARCH_URL.format(localization_url, url_quote(query)))
result = get_result(SEARCH_URL.format(URL, url_quote(query)))
html = pq(result)
return [a.attrib['href'] for a in html('.l')] or \
[a.attrib['href'] for a in html('.r')('a')]
Expand Down

0 comments on commit 4c3059c

Please sign in to comment.