Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test():
print find_phone_numbers( "PHONE: 1021-34662020/21/22/23/24")
print find_phone_numbers( "1021-34662020")
print "done.."
text = "Call me at ++1510-748-8230 if it's before 9:30, or on +703-4800500 after 10am. +971-9-4662020"
for match in phonenumbers.PhoneNumberMatcher(text, "US"):
print match
srcModuleName = event.module
eventData = event.data
sourceData = self.sf.hashstring(eventData)
if sourceData in self.results:
return None
else:
self.results[sourceData] = True
self.sf.debug("Received event, " + eventName + ", from " + srcModuleName)
if eventName in ['TARGET_WEB_CONTENT', 'DOMAIN_WHOIS', 'NETBLOCK_WHOIS']:
# Make potential phone numbers more friendly to parse
content = eventData.replace('.','-')
for match in phonenumbers.PhoneNumberMatcher(content, region=None):
n = phonenumbers.format_number(match.number,
phonenumbers.PhoneNumberFormat.E164)
evt = SpiderFootEvent("PHONE_NUMBER", n, self.__name__, event)
if event.moduleDataSource:
evt.moduleDataSource = event.moduleDataSource
else:
evt.moduleDataSource = "Unknown"
self.notifyListeners(evt)
if eventName == 'PHONE_NUMBER':
try:
number = phonenumbers.parse(eventData)
except BaseException as e:
self.sf.debug('Error parsing phone number: ' + str(e))
return None
def match(self, c):
matched = False
if partial:
for match in phonenumbers.PhoneNumberMatcher(c.value, 'FR'):
# original string is in match.raw_string
self.register_partial_match(c, self.t, 100, normalize_phone_number(match.number), (match.start, match.end))
matched = True
else:
z = phonenumbers.parse(c.value, 'FR')
score = score_phone_number(z)
if score > 0:
self.register_full_match(c, self.t, score, normalize_phone_number(z))
matched = True
if not matched:
raise TypeError('Value "{}" did not match as phone number'.format(c.value))
def iter_filth(self, text):
# create a copy of text to handle multiple phone numbers correctly
for match in phonenumbers.PhoneNumberMatcher(text, self.region):
yield PhoneFilth(
beg=match.start,
end=match.end,
text=match.raw_string,
)
query = session['last_query']['query']
stopset = set(stopwords.words('english'))
q = {
"fields": ["file"],
"query": {
"term": {"file": query}
}
}
r = es.search(body=q, index=es_index)
data = r['hits']['hits']
urls = []
pn = []
for doc in data:
urls.append(re.findall(r'(https?://[^\s]+)', doc['fields']['file'][0]))
try:
for match in phonenumbers.PhoneNumberMatcher(doc['fields']['file'][0], region=None):
pn.append({'number': phonenumbers.format_number(match.number, phonenumbers.PhoneNumberFormat.E164),
'location': geocoder.description_for_number(match.number, "en")})
except KeyError:
pass
urls = filter(lambda x: x != [], urls)
# urls_flat=reduce(lambda x,y: x.extend(y),urls)
urls_flat = [item for sublist in urls for item in sublist]
return json.dumps({'urls': dict(Counter(urls_flat)), 'pn': pn})
def count_phone_numbers(country_name, visible_text):
"""
DESCRIPTION: counts number of phone numbers that occur on NGO website
INPUT: visible_text --- all the visible text of NGO website homepage and subpages
OUTPUT: integer number of phone numbers found in visible text
"""
if country_name not in country_codes:
code = "None"
else:
code = country_codes[country_name]
print(code)
num_phone_numbers = 0
for match in phonenumbers.PhoneNumberMatcher(visible_text, code):
num_phone_numbers += 1
return num_phone_numbers
def test_phone():
print find_phone_numbers( "PHONE: 1021-34662020/21/22/23/24")
print find_phone_numbers( "1021-34662020")
print "done.."
text = "Call me at ++1510-748-8230 if it's before 9:30, or on +703-4800500 after 10am. +971-9-4662020"
for match in phonenumbers.PhoneNumberMatcher(text, "US"):
print match
text = 'call +1 (408) 912-6172 and send 100rs to 9920441344'
p = PhoneDetector(entity_name='phone_number', language='en')
p.detect_entity(text=text)
(['14089126172', '9920441344'], [u'+1 (408) 912-6172', u'9920441344'])
text = '+९१ ९८१९९८३१३२ पर कॉल करें और संदेश ९८२०३३४४१६ पर कॉल करें'
p = PhoneDetector(entity_name='phone_number', language='hi')
p.detect_entity(text=text)
(['919819983132', '9820334416'],[u'+९१ ९८१९९८३१३२', u'+९१ ९८१९९८३१३२'])
"""
self.text = text
self.phone, self.original_phone_text = [], []
for match in phonenumbers.PhoneNumberMatcher(text, self.country_code):
self.phone.append({"country_calling_code": str(match.number.country_code),
"phone_number": str(match.number.national_number)})
self.original_phone_text.append(self.text[match.start:match.end])
return self.phone, self.original_phone_text