Permalink
Browse files

Switch disqus feeder to use approxLoc

  • Loading branch information...
1 parent e0f6097 commit 2897c48fe9446f1aec5cf3257685949803efdef5 @dcramer dcramer committed Jun 19, 2012
Showing with 8 additions and 27 deletions.
  1. +6 −18 disqus_feeder.py
  2. +2 −9 dummy_feeder.py
View
@@ -89,7 +89,7 @@ def geocode_addr(addr):
return {}
-def anonymize(post, country_code):
+def anonymize(post):
return {
'link': post['thread']['link'],
'title': post['thread']['title'],
@@ -104,28 +104,16 @@ def main():
pub.connect(config['SERVER'])
def handle_post(post):
- if 'ipAddress' not in post:
- print 'Post %r does not have ipAddress field' % post['id']
- return
-
- result = geocode_addr(post['ipAddress'])
- if not result:
- print 'Could not geocode post %r with ipAddress=%r' % (post['id'], post['ipAddress'])
+ if 'approxyLoc' not in post:
+ print 'Post %r does not have approxyLoc field' % post['id']
return
print "New post", post['id']
- if result['metro_code']:
- loc = result['metro_code']
- elif result['city']:
- loc = '%s, %s' % (result['city'].decode('latin1'), result['country_name'].decode('latin1'))
- else:
- loc = result['country_name']
data = {
- 'post': anonymize(post, result['country_code']),
- 'loc': loc,
- 'lat': result['latitude'],
- 'lng': result['longitude'],
+ 'post': anonymize(post),
+ 'lat': post['approxLoc']['lat'],
+ 'lng': post['approxLoc']['lng'],
}
try:
queue.put_nowait(data)
View
@@ -30,7 +30,7 @@ def generate_ip():
return '%s.%s.%s.%s' % (random.randint(1, 255), random.randint(0, 255), random.randint(0, 255), random.randint(0, 255))
-def anonymize(post, country_code):
+def anonymize(post):
return {
'link': post['thread']['link'],
'title': post['thread']['title'],
@@ -1380,17 +1380,10 @@ def main():
result = geocode_addr(ip_address)
if not result:
continue
- if result['metro_code']:
- loc = result['metro_code']
- elif result['city']:
- loc = '%s, %s' % (result['city'].decode('latin1'), result['country_name'].decode('latin1'))
- else:
- loc = result['country_name']
data = {
'lat': result['latitude'],
'lng': result['longitude'],
- 'loc': loc,
- 'post': anonymize(random.choice(messages), result['country_code']),
+ 'post': anonymize(random.choice(messages)),
}
pub.send_json(data)

0 comments on commit 2897c48

Please sign in to comment.