Skip to content

Commit b998198

Browse files
authored
Resolves noreply.org issue for Location.py (#38)
* 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.
1 parent 434161f commit b998198

3 files changed

Lines changed: 8 additions & 22 deletions

File tree

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
install_requires='''
3737
enum34 >=1.0.3
3838
feedparser >=4.1
39+
requests >=2.23.0
3940
''',
4041
entry_points={
4142
'console_scripts': [ 'flashbake = flashbake.console:main',

src/flashbake/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,10 @@ def init(self):
120120
if isinstance(plugin, flashbake.plugins.AbstractMessagePlugin):
121121
logging.debug("Message Plugin: %s" % plugin_name)
122122
# TODO add notion of dependency for ordering
123-
if 'flashbake.plugins.location:Location' == plugin_name:
124-
self.msg_plugins.insert(0, plugin)
125-
else:
126-
self.msg_plugins.append(plugin)
123+
# if 'flashbake.plugins.location:Location' == plugin_name:
124+
# self.msg_plugins.insert(0, plugin)
125+
# else:
126+
self.msg_plugins.append(plugin)
127127
if isinstance(plugin, flashbake.plugins.AbstractFilePlugin):
128128
logging.debug("File Plugin: %s" % plugin_name)
129129
self.file_plugins.append(plugin)

src/flashbake/plugins/location.py

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import re
2727
import urllib
2828
import urllib2
29+
from requests import get
2930

3031

3132

@@ -141,26 +142,10 @@ def __get_text(self, node_list):
141142
return text_value
142143

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

147147
try:
148-
# open the weather API page
149-
ping_reply = opener.open(urllib2.Request(no_reply)).read()
150-
hello_line = None
151-
for line in ping_reply.split('\n'):
152-
if line.find('Hello') > 0:
153-
hello_line = line.strip()
154-
break
155-
if hello_line is None:
156-
logging.error('Failed to parse Hello with public IP address.')
157-
return None
158-
logging.debug(hello_line)
159-
m = re.search('([0-9]+\.){3}([0-9]+){1}', hello_line)
160-
if m is None:
161-
logging.error('Failed to parse Hello with public IP address.')
162-
return None
163-
ip_addr = m.group(0)
148+
ip_addr = ip_me
164149
return ip_addr
165150
except HTTPError, e:
166151
logging.error('Failed with HTTP status code %d' % e.code)

0 commit comments

Comments
 (0)