-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add parser for twitter search URLs (#420)
* Add parser for twitter search URLs Add parser for twitter search URLs. Currently, these URLs are failing and throwing errors.
- Loading branch information
Showing
3 changed files
with
53 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
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,40 @@ | ||
module Parser | ||
class TwitterSearchItem < Base | ||
include ProviderTwitter | ||
|
||
TWITTER_SEARCH_ITEM_URL = /^https?:\/\/((0|m|mobile|www)\.)?twitter\.com\/search\?(?:[^&\s"]+&)*q=[^&\s"]+/ | ||
|
||
class << self | ||
def type | ||
'twitter_search_item'.freeze | ||
end | ||
|
||
def patterns | ||
[TWITTER_SEARCH_ITEM_URL] | ||
end | ||
end | ||
|
||
private | ||
|
||
# Main function for class | ||
def parse_data_for_parser(_doc, _original_url, _jsonld_array) | ||
handle_exceptions(StandardError) do | ||
uri = URI.parse @url | ||
params = Hash[URI.decode_www_form uri.query] | ||
src = params['src'] | ||
search_term = params['q'] | ||
|
||
@parsed_data.merge!( | ||
title: search_term, | ||
search_term: search_term, | ||
src: src, | ||
description: uri, | ||
raw: { | ||
src: src | ||
} | ||
) | ||
end | ||
parsed_data | ||
end | ||
end | ||
end |
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