Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
snopes.py: search snopes and return the header of the found article
- Loading branch information
Showing
1 changed file
with
26 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import re | ||
|
||
from util import hook, http | ||
|
||
|
||
search_url = "http://search.atomz.com/search/?sp_a=00062d45-sp00000000" | ||
|
||
|
||
@hook.command | ||
def snopes(inp): | ||
search_page = http.get_html(search_url, sp_q=inp, sp_c="1") | ||
result_urls = search_page.xpath("//a[@target='_self']/@href") | ||
|
||
if not result_urls: | ||
return "no matching pages found" | ||
|
||
snopes_page = http.get_html(result_urls[0]) | ||
snopes_text = snopes_page.text_content() | ||
|
||
claim = re.search(r"Claim: .*", snopes_text).group(0) | ||
status = re.search(r"Status: .*", snopes_text).group(0) | ||
|
||
claim = re.sub(r"[\s\xa0]+", " ", claim) # compress whitespace | ||
status = re.sub(r"[\s\xa0]+", " ", status) | ||
|
||
return "%s %s %s" % (claim, status, result_urls[0]) |