Skip to content

Commit c1a11a1

Browse files
author
azazelm3dj3d
committed
Tidying up for release
- Improved URL controller. Now returns the original URL instead of "None" - Added the URL expander to the twitter_follow_links source
1 parent 31dd2b3 commit c1a11a1

3 files changed

Lines changed: 7 additions & 9 deletions

File tree

threatingestor/sources/twitter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def run(self, saved_state):
8383
try:
8484
tweet['content'] = tweet['content'].replace(url['url'], url['expanded_url'])
8585
except KeyError:
86-
# Attempts to expand the URL using custom script
86+
# Attempts to expand the URL if not available through Twitter
8787
tweet['content'] = tweet['content'].replace(url['url'], UrlController.expand_url(url['url']))
8888

8989
# Process tweet.

threatingestor/sources/twitter_follow_links.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
from __future__ import absolute_import
22

3-
43
import re
54
import requests
65
import twitter
76
from loguru import logger
8-
from threatingestor.sources import Source
97

8+
from threatingestor.sources import Source
9+
from threatingestor.utils.url_controller import UrlController
1010

1111
TWEET_URL = 'https://twitter.com/{user}/status/{id}'
12-
1312
WHITELIST_DOMAINS = r"pastebin\.com"
1413

15-
1614
class Plugin(Source):
1715

1816
def __init__(self, name, api_key, api_secret_key, access_token, access_token_secret, defanged_only=True, **kwargs):
@@ -97,8 +95,8 @@ def run(self, saved_state):
9795
logger.log('NOTIFY', f"Discovered paste: {location}")
9896

9997
except KeyError:
100-
# No url/expanded_url, continue without expanding.
101-
pass
98+
# Attempts to expand the URL if not available through Twitter
99+
tweet['content'] = tweet['content'].replace(url['url'], UrlController.expand_url(url['url']))
102100

103101
return saved_state, artifacts
104102

threatingestor/utils/url_controller.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def expand_url(url):
1111
"""
1212
Expand ingested URLs with this method.
1313
14-
If a URL is unknown or cannot be expanded, you'll get a "None" response.
14+
If a URL is unknown or cannot be expanded, you'll get the original URL back.
1515
1616
@param: url (Example: https://inquest.net)
1717
@@ -23,4 +23,4 @@ def expand_url(url):
2323
return str(expanded_link)
2424
# If unable to expand the URL, this exception is thrown
2525
except exceptions.ExpandingErrorException:
26-
return "None"
26+
return str(url)

0 commit comments

Comments
 (0)