aboutsummaryrefslogtreecommitdiff
path: root/inputs
diff options
context:
space:
mode:
authorGravatar rcoh <rcoh@mit.edu>2011-01-28 11:03:10 -0500
committerGravatar rcoh <rcoh@mit.edu>2011-01-28 11:03:10 -0500
commita7d6577e55ebd665ad9e4f45183836f11b3c6fd4 (patch)
treedd036ac439ceb577cc699f59a755667544d57539 /inputs
parent3319a58ecc391f9aac092ade45f9f50dc2af5aa6 (diff)
parent6341992254c837b1d814b3eaa24b2ab3e729c8e2 (diff)
Merge branch 'wind-behavior' into fridaydemo
Conflicts: behaviors/XYMove.py
Diffstat (limited to 'inputs')
-rwxr-xr-xinputs/HTMLInput.py29
-rw-r--r--inputs/RandomLocs.py32
2 files changed, 45 insertions, 16 deletions
diff --git a/inputs/HTMLInput.py b/inputs/HTMLInput.py
new file mode 100755
index 0000000..9697a32
--- /dev/null
+++ b/inputs/HTMLInput.py
@@ -0,0 +1,29 @@
+from operationscore.Input import *
+import urllib, re
+
+"""
+HTML Input, which takes 2 arguments:
+- 'Src': a URL to a web page, and
+- 'Regex': a Regex to parse data out of the web page.
+The input parses the source code of the web page according to the regex, and processes the parsed regex groups.
+"""
+class HTMLInput(Input):
+ def inputInit(self):
+ self.src = self.argDict['Src']
+ self.regex = self.argDict['Regex']
+
+ def getHTML(self):
+ self.sock = urllib.urlopen(self.src);
+ self.html = self.sock.read()
+ self.sock.close()
+
+ def sensingLoop(self):
+ self.getHTML()
+ self.dataList = []
+
+ pattern = re.compile(self.regex)
+ matchObj = pattern.search(self.html)
+ self.dataList = matchObj.groups()
+
+ self.respond(self.dataList)
+
diff --git a/inputs/RandomLocs.py b/inputs/RandomLocs.py
index 2719981..f4182cf 100644
--- a/inputs/RandomLocs.py
+++ b/inputs/RandomLocs.py
@@ -1,16 +1,16 @@
-import util.TimeOps as clock
-import random
-import util.Geo as Geo
-import util.Strings as Strings
-from operationscore.Input import *
-class RandomLocs(Input):
- """RandomLocs is an Input that generates RandomLocations at a preset time interval. Just a
- prototype, some assembly required."""
-
- def inputInit(self):
- self['LastEvent'] = clock.time()
- def sensingLoop(self): #TODO: move to params
- currentTime = clock.time()
- if currentTime - self['LastEvent'] > 2000:
- self.respond({Strings.LOCATION: Geo.randomLoc((50,50))})
- self['LastEvent'] = currentTime
+import util.TimeOps as clock
+import random
+import util.Geo as Geo
+import util.Strings as Strings
+from operationscore.Input import *
+class RandomLocs(Input):
+ """RandomLocs is an Input that generates RandomLocations at a preset but randomly changing time interval. Just a
+ prototype, some assembly required."""
+
+ def inputInit(self):
+ self['LastEvent'] = clock.time()
+ def sensingLoop(self): #TODO: move to params
+ currentTime = clock.time()
+ if currentTime - self['LastEvent'] > 200+500*random.random():
+ self.respond({Strings.LOCATION: Geo.randomLoc((200,200))})
+ self['LastEvent'] = currentTime