Browse Source

rename raw commands

* alfred-data -> raw-data
* batcave-status -> raw-status
Helge Jung 9 years ago
parent
commit
18df9cc95d
3 changed files with 41 additions and 94 deletions
  1. 39 92
      modules/ffpb.py
  2. 1 1
      modules/ffpb_netstatus.py
  3. 1 1
      modules/ffpb_nodeinfo.py

+ 39 - 92
modules/ffpb.py

@@ -475,101 +475,48 @@ def mac2ipv6(mac, prefix=None):
     return result
 
 
-@willie.module.interval(30)
-def ffpb_updatealfred(bot):
-    """Aktualisiere ALFRED-Daten"""
-
-    if alfred_method is None or alfred_method == "None":
-        return
-
-    updated = None
-    if alfred_method == "exec":
-        rawdata = subprocess.check_output(['alfred-json', '-z', '-r', '158'])
-        updated = datetime.now()
-
-    elif alfred_method.startswith("http"):
-        try:
-            rawdata = urllib2.urlopen(alfred_method)
-        except urllib2.URLError as err:
-            print("Failed to download ALFRED data:" + str(err))
-            return
-        last_modified = rawdata.info().getdate_tz("Last-Modified")
-        updated = datetime.fromtimestamp(mktime_tz(last_modified))
-
-    else:
-        print("Unknown ALFRED data method '{0}', cannot load new data.".format(alfred_method))
-        alfred_data = None
+def ffpb_notify_newly_seen_nodes(bot, new):
+    if not isinstance(bot, dict):
         return
-
-    try:
-        alfred_data = json.load(rawdata)
-        #print("Fetched new ALFRED data:", len(alfred_data), "entries")
-
-    except ValueError as err:
-        print("Failed to parse ALFRED data: " + str(err))
+    if len(new) == 0 or bot.memory['ffpb_in_setup']:
         return
 
-    bot.memory['alfred_data'] = alfred_data
-    bot.memory['alfred_update'] = updated
-
-    seen_nodes = bot.memory.get('seen_nodes', None)
-    if not seen_nodes is None:
-        new = []
-        for nodeid in alfred_data:
-            nodeid = str(nodeid)
-            if not nodeid in seen_nodes:
-                seen_nodes[nodeid] = updated
-                new.append((nodeid, alfred_data[nodeid]['hostname']))
-                print('First time seen: ' + str(nodeid))
-        if len(new) > 0 and not bot.memory['ffpb_in_setup']:
-            action_msg = None
-            if len(new) == 1:
-                action_msg = random.choice((
-                    'bemerkt den neuen Knoten {0}',
-                    'entdeckt {0}',
-                    'reibt sich die Augen und erblickt einen verpackungsfrischen Knoten {0}',
-                    u'heißt {0} im Mesh willkommen',
-                    'freut sich, dass {0} aufgetaucht ist',
-                    'traut seinen Augen kaum. {0} sagt zum ersten Mal: Hallo Freifunk Paderborn',
-                    u'sieht die ersten Herzschläge von {0}',
-                    u'stellt einen großen Pott Heißgetränk zu {0} und fragt ob es hier Meshpartner gibt.',
-                )).format('\'' + str(new[0][1]) + '\'')
-
-                # try to fetch location from BATCAVE in order to add a geomap URL
-                location = ffpb_get_batcave_nodefield(str.replace(new[0][0], ':', ''), 'location')
-                if not location is None:
-                    action_msg += ' http://map.paderborn.freifunk.net/geomap.html?lat=' + location['latitude'] + '&lon=' + location['longitude']
-            else:
-                action_msg = random.choice((
-                    'bemerkt die neuen Knoten {0} und {1}',
-                    'hat {0} und {1} entdeckt',
-                    'bewundert {0} sowie {1}',
-                    'freut sich, dass {0} und {1} nun auch online sind',
-                    u'heißt {0} und {1} im Mesh willkommen',
-                    'fragt sich ob die noch jungen Herzen von {0} und {1} synchron schlagen',
-                ))
-                all_but_last = [str(x[1]) for x in new[0:-1]]
-                last = str(new[-1][1])
-                action_msg = action_msg.format(
-                    '\'' + '\', \''.join(all_but_last) + '\'',
-                    '\'' + last + '\''
-                )
-            action_target = bot.config.ffpb.msg_target
-            if not bot.config.ffpb.msg_target_public is None:
-                action_target = bot.config.ffpb.msg_target_public
-            bot.msg(action_target, '\x01ACTION %s\x01' % action_msg)
-
-
-@willie.module.commands('debug-alfred')
-def ffpb_debug_alfred(bot, trigger):
-    """Show statistics of available ALFRED data."""
-
-    alfred_data = get_alfred_data(bot)
-    if alfred_data is None:
-        bot.say("Keine ALFRED-Daten vorhanden.")
+    action_msg = None
+    if len(new) == 1:
+        action_msg = random.choice((
+            'bemerkt den neuen Knoten {0}',
+            'entdeckt {0}',
+            'reibt sich die Augen und erblickt einen verpackungsfrischen Knoten {0}',
+            u'heißt {0} im Mesh willkommen',
+            'freut sich, dass {0} aufgetaucht ist',
+            'traut seinen Augen kaum. {0} sagt zum ersten Mal: Hallo Freifunk Paderborn',
+            u'sieht die ersten Herzschläge von {0}',
+            u'stellt einen großen Pott Heißgetränk zu {0} und fragt ob es hier Meshpartner gibt.',
+        )).format('\'' + str(new[0][1]) + '\'')
+
+        # try to fetch location from BATCAVE in order to add a geomap URL
+        location = __batcave.get_nodefield(str.replace(new[0][0], ':', ''), 'location')
+        if not location is None:
+            action_msg += ' http://map.paderborn.freifunk.net/geomap.html?lat=' + location['latitude'] + '&lon=' + location['longitude']
     else:
-        bot.say("ALFRED Daten: count={0} lastupdate={1}".format(
-                len(alfred_data), bot.memory['alfred_update']))
+        action_msg = random.choice((
+            'bemerkt die neuen Knoten {0} und {1}',
+            'hat {0} und {1} entdeckt',
+            'bewundert {0} sowie {1}',
+            'freut sich, dass {0} und {1} nun auch online sind',
+            u'heißt {0} und {1} im Mesh willkommen',
+            'fragt sich ob die noch jungen Herzen von {0} und {1} synchron schlagen',
+        ))
+        all_but_last = [str(x[1]) for x in new[0:-1]]
+        last = str(new[-1][1])
+        action_msg = action_msg.format(
+            '\'' + '\', \''.join(all_but_last) + '\'',
+            '\'' + last + '\''
+        )
+    action_target = bot.config.ffpb.msg_target
+    if not bot.config.ffpb.msg_target_public is None:
+        action_target = bot.config.ffpb.msg_target_public
+    bot.msg(action_target, '\x01ACTION %s\x01' % action_msg)
 
 
 @willie.module.interval(60)
@@ -767,7 +714,7 @@ def ffpb_nodemesh(bot, trigger):
 
     # query BATCAVE for neighbour's names
     data = '&'.join([str(n) for n in cave_result])
-    req = urllib2.urlopen('http://[fdca:ffee:ff12:a255::253]:8888/idmac2name', data)
+    req = urllib2.urlopen(bot.config.ffpb.batcave_url + '/idmac2name', data)
 
     # filter out duplicate names
     neighbours = set()

+ 1 - 1
modules/ffpb_netstatus.py

@@ -99,7 +99,7 @@ def ffpb_status(bot, trigger):
             stats["nodes_active"], stats["clients_unique"]))
 
 
-@willie.module.commands('batcave-status')
+@willie.module.commands('raw-status')
 def ffpb_batcave_status(bot, trigger):
     """State as given by BATCAVE."""
 

+ 1 - 1
modules/ffpb_nodeinfo.py

@@ -20,7 +20,7 @@ def shutdown(bot):
     pass
 
 
-@willie.module.commands('alfred-data')
+@willie.module.commands('raw-data')
 def ffpb_peerdata(bot, trigger):
     """Show ALFRED data of the given node."""