Skip to content

Commit

Permalink
Resolves noreply.org issue for Location.py (#38)
Browse files Browse the repository at this point in the history
* This fixes the location issue with noreply.org.

* Commented out what looks like example code for later reference.

* changed spacing and indents after commenting out code.

* Forgot to comment out else statement.
  • Loading branch information
ianpaul authored May 2, 2020
1 parent 434161f commit b998198
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 22 deletions.
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
install_requires='''
enum34 >=1.0.3
feedparser >=4.1
requests >=2.23.0
''',
entry_points={
'console_scripts': [ 'flashbake = flashbake.console:main',
Expand Down
8 changes: 4 additions & 4 deletions src/flashbake/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,10 @@ def init(self):
if isinstance(plugin, flashbake.plugins.AbstractMessagePlugin):
logging.debug("Message Plugin: %s" % plugin_name)
# TODO add notion of dependency for ordering
if 'flashbake.plugins.location:Location' == plugin_name:
self.msg_plugins.insert(0, plugin)
else:
self.msg_plugins.append(plugin)
# if 'flashbake.plugins.location:Location' == plugin_name:
# self.msg_plugins.insert(0, plugin)
# else:
self.msg_plugins.append(plugin)
if isinstance(plugin, flashbake.plugins.AbstractFilePlugin):
logging.debug("File Plugin: %s" % plugin_name)
self.file_plugins.append(plugin)
Expand Down
21 changes: 3 additions & 18 deletions src/flashbake/plugins/location.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import re
import urllib
import urllib2
from requests import get



Expand Down Expand Up @@ -141,26 +142,10 @@ def __get_text(self, node_list):
return text_value

def __get_ip(self):
no_reply = 'http://www.noreply.org'
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor())
ip_me = get('https://api.ipify.org').text

try:
# open the weather API page
ping_reply = opener.open(urllib2.Request(no_reply)).read()
hello_line = None
for line in ping_reply.split('\n'):
if line.find('Hello') > 0:
hello_line = line.strip()
break
if hello_line is None:
logging.error('Failed to parse Hello with public IP address.')
return None
logging.debug(hello_line)
m = re.search('([0-9]+\.){3}([0-9]+){1}', hello_line)
if m is None:
logging.error('Failed to parse Hello with public IP address.')
return None
ip_addr = m.group(0)
ip_addr = ip_me
return ip_addr
except HTTPError, e:
logging.error('Failed with HTTP status code %d' % e.code)
Expand Down

0 comments on commit b998198

Please sign in to comment.