Initial bots code... probably a crack idea but let's see if I can

get something useful out of it.
This commit is contained in:
Marco Pesenti Gritti 2006-06-20 03:19:33 -04:00
parent 0df8d01dce
commit 028b15d3df
8 changed files with 72 additions and 5 deletions

7
examples/bots/LICENSE Normal file
View File

@ -0,0 +1,7 @@
This work is licensed under the Creative Commons Attribution 2.5 License. To view a copy of this license, visit http://creativecommons.org/licenses/by/2.5/ or send a letter to Creative Commons, 543 Howard Street, 5th Floor, San Francisco, California, 94105, USA.
Attributions:
chaitanya.jpg http://www.flickr.com/photos/meanestindian/166408558/
penelope.jpg http://www.flickr.com/photos/gagah/9257515/
kiu.jpg http://flickr.com/photos/31072589@N00/139234295/

View File

@ -0,0 +1,2 @@
[Activity]
python_class = bots

20
examples/bots/bots.py Normal file
View File

@ -0,0 +1,20 @@
import os
import pygtk
pygtk.require('2.0')
import gtk
from sugar.bots import Bot
basedir = os.path.dirname(__file__)
bot = Bot("Chaitanya", os.path.join(basedir, "chaitanya.jpg"))
bot.start()
bot = Bot("Kiu", os.path.join(basedir, "kiu.jpg"))
bot.start()
bot = Bot("Penelope", os.path.join(basedir, "penelope.jpg"))
bot.start()
gtk.main()

BIN
examples/bots/chaitanya.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

BIN
examples/bots/kiu.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

BIN
examples/bots/penelope.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

39
sugar/bots.py Normal file
View File

@ -0,0 +1,39 @@
import os
import random
import base64
from sugar import env
from sugar.presence import Service
from sugar.presence import Buddy
from sugar.presence import PresenceService
from sugar.p2p import Stream
class Bot:
def __init__(self, nick, icon_path):
self._nick = nick
self._icon_path = icon_path
def start(self):
fd = open(self._icon_path, "r")
self._icon = fd.read()
fd.close()
# Our presence service
port = random.randint(40000, 65000)
properties = {}
self._service = Service.Service(self._nick, Buddy.PRESENCE_SERVICE_TYPE,
domain="", address=None, port=port, properties=properties)
self._icon_stream = Stream.Stream.new_from_service(self._service)
self._icon_stream.register_reader_handler(self._handle_buddy_icon_request, "get_buddy_icon")
# Announce ourselves to the world
self._pservice = PresenceService.PresenceService.get_instance()
self._pservice.start()
self._pservice.register_service(self._service)
def _handle_buddy_icon_request(self):
"""XMLRPC method, return the owner's icon encoded with base64."""
if self._icon:
return base64.b64encode(self._icon)
return ""

View File

@ -1,13 +1,12 @@
import os
import random
import base64
from sugar import env
from sugar.presence import Service
from sugar.presence import Buddy
from sugar.presence import PresenceService
from sugar.p2p import Stream
import os
import random
import base64
class ShellOwner(object):
"""Class representing the owner of this machine/instance. This class