Skip to content
Snippets Groups Projects
Commit 8edb2085 authored by Helge Jung's avatar Helge Jung
Browse files

Back to Python 2

This reverts commit 99e5719e.
parent 0bb97e4e
No related branches found
No related tags found
No related merge requests found
# FFPB Status-Bot
Der Bot benötigt Python 3 und basiert auf ["Willie"](http://willie.dftba.net) welcher unverändert als Git-Submodul eingebunden ist. Hinzugefügt wurde das Plugin "[ffpb](modules/ffpb.py)" und ein [Startup-Skript](bot.sh).
Der Bot benötigt Python 2 und basiert auf ["Willie"](http://willie.dftba.net) welcher unverändert als Git-Submodul eingebunden ist. Hinzugefügt wurde das Plugin "[ffpb](modules/ffpb.py)" und ein [Startup-Skript](bot.sh).
## Funktionen
......@@ -20,8 +20,8 @@ git clone --recursive https://git.c3pb.de/freifunk-pb/status-bot.git /opt/ffpb-s
Der Bot hat Abhängigkeiten:
```
apt-get install python3-pip python3-netaddr python3-urllib3
pip3 install GitPython
apt-get install python-pip python-netaddr python-urllib2
pip install "GitPython>=0.3.2.RC1"
```
Das Start-Up-Skript erfordert einen der Parameter "start" oder "stop" und eignet sich als Init-Skript:
......
......@@ -3,15 +3,6 @@
mydir=$(readlink -f $0)
mydir=$(dirname "$mydir")
python3 -V > /dev/null 2>&1 && python3="python3"
if [ -z "$python3" ]; then
python3.4 -V > /dev/null 2>&1 && python3="python3.4"
if [ -z "$python3" ]; then
echo "Did not find neither python3 nor python3.4 in your path :-("
exit 1
fi
fi
if [ ! -r "${mydir}/bot.cfg" ]; then
echo "'bot.cfg' is missing. Have you copied 'bot.cfg.example'?"
exit 2
......@@ -21,10 +12,10 @@ case $1 in
start)
[ ! -d "${mydir}/logs" ] && mkdir "${mydir}/logs"
$python3 "${mydir}/willie/willie.py" -c "${mydir}/bot.cfg" --fork
"${mydir}/willie/willie.py" -c "${mydir}/bot.cfg" --fork
;;
stop)
$python3 "${mydir}/willie/willie.py" -c "${mydir}/bot.cfg" --quit
"${mydir}/willie/willie.py" -c "${mydir}/bot.cfg" --quit
;;
restart)
......
from __future__ import print_function
import willie
import netaddr
import urllib3
import urllib2
import re
import os
import subprocess
import socket
import socketserver
import SocketServer
import threading
msgserver = None
......@@ -21,7 +22,7 @@ msgserver_known_senders = {
"10.132.254.80": "public"
}
class MsgHandler(socketserver.BaseRequestHandler):
class MsgHandler(SocketServer.BaseRequestHandler):
def handle(self):
data = self.request.recv(2048).strip()
sender = self.client_address[0]
......@@ -37,9 +38,9 @@ class MsgHandler(socketserver.BaseRequestHandler):
if bot.config.has_section('ffpb') and not (bot.config.ffpb.msg_target is None):
target = bot.config.ffpb.msg_target
bot.msg(target, "[{0}] {1}".format(sender,str(data, "utf-8")))
bot.msg(target, "[{0}] {1}".format(sender, str(data, "utf-8"))
class ThreadingTCPServer(socketserver.ThreadingMixIn, socketserver.TCPServer):
class ThreadingTCPServer(SocketServer.ThreadingMixIn, SocketServer.TCPServer):
pass
def setup(bot):
......@@ -71,7 +72,7 @@ def shutdown(bot):
@willie.module.commands('status')
def ffpb_status(bot, trigger):
"""Status des FFPB-Netzes: Anzahl (aktiver) Knoten + Clients"""
response = urllib3.urlopen('http://nodecount.paderborn.freifunk.net/')
response = urllib2.urlopen('http://nodecount.paderborn.freifunk.net/')
html = response.read()
m = re.search('<div id="nodecount">\s*(\d+)\s*</div>', html)
nodecount = int(m.group(1))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment