-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow social event exchange anonymous betweed clients, MQTT broker wi…
…ll hide users' ip and personal information.
- Loading branch information
Showing
6 changed files
with
59 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
from logging_handler import LoggingHandler | ||
from socketio_handler import SocketIoHandler | ||
from colored_logging_handler import ColoredLoggingHandler | ||
from social_handler import SocialHandler |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import unicode_literals | ||
|
||
from pokemongo_bot.event_manager import EventHandler | ||
import thread | ||
import paho.mqtt.client as mqtt | ||
class MyMQTTClass: | ||
def __init__(self, clientid=None): | ||
self._mqttc = mqtt.Client(clientid) | ||
self._mqttc.on_message = self.mqtt_on_message | ||
#self._mqttc.on_connect = self.mqtt_on_connect | ||
#self._mqttc.on_publish = self.mqtt_on_publish | ||
#self._mqttc.on_subscribe = self.mqtt_on_subscribe | ||
#def mqtt_on_connect(self, mqttc, obj, flags, rc): | ||
#print "rc: "+str(rc) | ||
def mqtt_on_message(self, mqttc, obj, msg): | ||
print msg.topic+" "+str(msg.qos)+" "+str(msg.payload) | ||
#def mqtt_on_publish(self, mqttc, obj, mid): | ||
#print "mid: "+str(mid) | ||
#def mqtt_on_subscribe(self, mqttc, obj, mid, granted_qos): | ||
# print "Subscribed: "+str(mid)+" "+str(granted_qos) | ||
#def mqtt_on_log(self, mqttc, obj, level, string): | ||
# print string | ||
def publish(self, channel, message): | ||
self._mqttc.publish(channel, message) | ||
def connect_to_mqtt(self): | ||
self._mqttc.connect("test.mosca.io", 1883, 60) | ||
self._mqttc.subscribe("$GOF/Social/#", 0) | ||
def run(self): | ||
self._mqttc.loop_forever() | ||
class SocialHandler(EventHandler): | ||
def __init__(self): | ||
self.mqttc = MyMQTTClass() | ||
self.mqttc.connect_to_mqtt() | ||
thread.start_new_thread(self.mqttc.run) | ||
def handle_event(self, event, sender, level, formatted_msg, data): | ||
#sender_name = type(sender).__name__ | ||
if formatted_msg: | ||
message = "[{}] {}".format(event, formatted_msg) | ||
else: | ||
message = '{}: {}'.format(event, str(data)) | ||
if event == 'catchable_pokemon': | ||
self.mqttc.publish("$GOF/Social/Catchable", message) | ||
#print 'have catchable_pokemon' | ||
#print message |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,3 +22,4 @@ mock==2.0.0 | |
timeout-decorator==0.3.2 | ||
raven==5.23.0 | ||
demjson==2.2.4 | ||
paho-mqtt==1.2 |
4c324ad
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Such a nice idea and great code! Thank you for doing so much good to open source!