Permalink
Browse files

Adding plugins to me is easier now. Now you just have to drag 'n' dro…

…p the plugin folder into the hu folder and I take care of the rest.
  • Loading branch information...
1 parent a753915 commit 577b80421a933e8b460c0ec0fdf8930216429b83 @scottjacksonx committed Jun 29, 2010
Showing with 69 additions and 39 deletions.
  1. +6 −9 README.md
  2. +54 −0 hu-notes.txt
  3. +9 −30 hu.py
View
15 README.md
@@ -28,31 +28,28 @@ This is all wishlist stuff, though. Don't get your hopes up too high just yet.
Hu is a little bit delicate at the moment.
-To use Hu, first [download the source](http://github.com/scottjacksonx/hu/zipball/master). Then, change your values for the various plugins (your last.fm username for the `hu_lastfm` plugin, your location for the `hu_googleweather` plugin, etc.). Finally, run `$ python hu.py`. That will run Hu once. Hu's notes are stored in, well, `hu-notes.txt`.
+To use Hu, first [download the source](http://github.com/scottjacksonx/hu/zipball/master). Then, change your values for the various plugins (your last.fm username for the `hu_lastfm` plugin, your location for the `hu_googleweather` plugin, etc.). Finally, run `$ python hu.py`. That will run Hu once. Hu's notes are stored in `hu-notes.txt`.
# Plugins #
-Hu has a plugin architecture. Here's how you write a plugin:
+Hu has a plugin architecture. When Hu runs, the first thing that happens is that he looks for every folder with a name that starts with `"hu_"` and treats that folder as a plugin.
-1. You come up with a name for your plugin. We'll call it `$PLUGIN`. When you see `$PLUGIN` from here on out, substitute your own plugin's name.
+Here's how you write a plugin:
+
+1. You come up with a name for your plugin (with plugins, as with bands, coming up with a name is the hardest part). We'll call it `$PLUGIN`. When you see `$PLUGIN` from here on out, substitute your own plugin's name. **_Nota bene_: your plugin's name must start with "hu_" for the reason outlined just above.**
2. You write a python script called `$PLUGIN`.py that contains a definition of a function called `getData()`. You can include other functions, classes or any other kind of code, but you _must_ define a function called `getData()`. `getData()` returns exactly what is recorded in Hu's entry, so it should be XML, complete with newlines (no newline necessary at the end). No tabs/spaces are necessary, since that's carried out from within `hu.py`.
3. Put `$PLUGIN`.py inside a folder called `$PLUGIN`. The `$PLUGIN` folder lives inside the `hu` folder.
4. Inside the `$PLUGIN` folder, have a file called `__init__.py`, which contains a single line of code: `import $PLUGIN`
-5. In `hu.py`, at the tippy-top where the plugin declarations are, add an import statement for your plugin similar to the import statements that are already there. It should look like:
-
- `import $PLUGIN.$PLUGIN`
- `plugin_modules.append($PLUGIN.$PLUGIN)`
That's all there is to it. If you're having any issues, look at how the default plugins (`hu_googleweather`, `hu_openapps`, etc.) work.
-I'm going to make plugins a little easier to add/remove in the near future.
-
# The Potential #
Once Hu has a bunch of information about you, here are the kinds of things you can start to ask:
- What application do I spend the most time in? Find the most commonly occurring frontmost application.
- What websites do I visit the most often? Get the most frequently-appearing domain.
+- How much of what I do at the Coffee Shop With the WiFi is work, and how much is refreshing Hacker News?
- How does the weather affect the kind of music I listen to? Compare the list of songs you listened to when the weather was "Cloudy" to the songs you listened to when the weather was "Fine."
- What time of day do I listen to music most at? See how many songs I listened to between 6pm and 12am and compare that number with how many songs I listened to between 9am and 3pm.
View
54 hu-notes.txt
@@ -15,4 +15,58 @@
<app name="Safari" />
</applications>
</entry>
+<entry time="Tue, 29 Jun 2010 13:14:14">
+<currentlyplaying artist="U2" title="Zoo Station" />
+<weather location="brisbane,australia" condition="Partly Cloudy" temp="16c"/>
+<lastfm>
+<track artist="Ramones" title="Chainsaw" time="1277780961" />
+<track artist="Jessica Harper" title="Carte Blanche" time="1277780878" />
+<track artist="Big Star" title="In The Street" time="1277780705" />
+</lastfm>
+<applications>
+<app name="Mail" />
+<app name="iTunes" />
+<app name="Terminal" />
+<app name="TextMate" />
+<app name="Safari" />
+</applications>
+<browser>
+<tab title="python list directories - Google Search" url="http://www.google.com/search?q=python%20list%20directories&ie=utf-8&oe=utf-8" />
+<tab title="10.1. os.path — Common pathname manipulations — Python v2.6.5 documentation" url="http://docs.python.org/library/os.path.html#module-os.path" />
+<tab title="10.1. os.path — Common pathname manipulations — Python v2.6.5 documentation" url="http://docs.python.org/library/os.path.html" />
+<tab title="15.1. os — Miscellaneous operating system interfaces — Python v2.6.5 documentation" url="http://docs.python.org/library/os.html" />
+<tab title="How do I execute a string containing Python code in Python? - Stack Overflow" url="http://stackoverflow.com/questions/701802/how-do-i-execute-a-string-containing-python-code-in-python" />
+<tab title="Stephen King - On Writing (Audiobook) (download torrent) - TPB" url="http://thepiratebay.org/torrent/4238993/Stephen_King_-_On_Writing_(Audiobook)" />
+<tab title="The.Pixar.Story.(2007).TV-RIP-PinkyBrainz.mp4 (download torrent) - TPB" url="http://thepiratebay.org/torrent/4171274/The.Pixar.Story.(2007).TV-RIP-PinkyBrainz.mp4" />
+<tab title="Welcome To Macintosh (2008) (download torrent) - TPB" url="http://thepiratebay.org/torrent/4758559/Welcome_To_Macintosh_(2008)" />
+</browser>
+<ssid name="Simon" />
+</entry>
+<entry time="Tue, 29 Jun 2010 13:17:19">
+<currentlyplaying artist="Richard O'Brien, Jessica Harper, Patricia Quinn, Barry Humphries" title="Little Black Dress" />
+<weather location="brisbane,australia" condition="Partly Cloudy" temp="16c"/>
+<lastfm>
+<track artist="U2" title="Zoo Station" time="1277781051" />
+<track artist="Ramones" title="Chainsaw" time="1277780961" />
+<track artist="Jessica Harper" title="Carte Blanche" time="1277780878" />
+</lastfm>
+<applications>
+<app name="Mail" />
+<app name="iTunes" />
+<app name="Terminal" />
+<app name="TextMate" />
+<app name="Safari" />
+</applications>
+<browser>
+<tab title="python list directories - Google Search" url="http://www.google.com/search?q=python%20list%20directories&ie=utf-8&oe=utf-8" />
+<tab title="10.1. os.path — Common pathname manipulations — Python v2.6.5 documentation" url="http://docs.python.org/library/os.path.html#module-os.path" />
+<tab title="10.1. os.path — Common pathname manipulations — Python v2.6.5 documentation" url="http://docs.python.org/library/os.path.html" />
+<tab title="15.1. os — Miscellaneous operating system interfaces — Python v2.6.5 documentation" url="http://docs.python.org/library/os.html" />
+<tab title="How do I execute a string containing Python code in Python? - Stack Overflow" url="http://stackoverflow.com/questions/701802/how-do-i-execute-a-string-containing-python-code-in-python" />
+<tab title="Stephen King - On Writing (Audiobook) (download torrent) - TPB" url="http://thepiratebay.org/torrent/4238993/Stephen_King_-_On_Writing_(Audiobook)" />
+<tab title="The.Pixar.Story.(2007).TV-RIP-PinkyBrainz.mp4 (download torrent) - TPB" url="http://thepiratebay.org/torrent/4171274/The.Pixar.Story.(2007).TV-RIP-PinkyBrainz.mp4" />
+<tab title="Welcome To Macintosh (2008) (download torrent) - TPB" url="http://thepiratebay.org/torrent/4758559/Welcome_To_Macintosh_(2008)" />
+</browser>
+<ssid name="Simon" />
+</entry>
</hu>
View
39 hu.py
@@ -1,49 +1,28 @@
-# Plugin declarations
-
-plugin_modules = []
-import hu_currentlyplaying.hu_currentlyplaying
-plugin_modules.append(hu_currentlyplaying.hu_currentlyplaying)
-
-import hu_lastfm.hu_lastfm
-plugin_modules.append(hu_lastfm.hu_lastfm)
-
-import hu_googleweather.hu_googleweather
-plugin_modules.append(hu_googleweather.hu_googleweather)
-
-import hu_ssidname.hu_ssidname
-plugin_modules.append(hu_ssidname.hu_ssidname)
-
-import hu_openbrowsertabs.hu_openbrowsertabs
-plugin_modules.append(hu_openbrowsertabs.hu_openbrowsertabs)
-
-import hu_openapps.hu_openapps
-plugin_modules.append(hu_openapps.hu_openapps)
-
-# End plugin declarations
-
import datetime
import time
+import os
class hu:
+
"""
i'm hu. i'm a big, important class. i watch you and i take notes.
i hope you like me.
"""
+ plugin_modules = []
def __init__(self):
"""
hello, world.
this is the part where i find out all of the things you want me to record.
"""
- # get current directory
-
- # get names of all folders in the current directory that start with "hu_", store as folder_name or similar
-
- # execute 'import ' + $folder_name + '.' $folder_name
- # execute 'plugin_modules.append(' + $folder_name + '.' $folder_name + ')'
+ # get names of all folders in the current directory that start with "hu_"
+ for file in os.listdir("."):
+ if file[0:3] == "hu_":
+ exec "import " + file + "." + file
+ exec "self.plugin_modules.append(" + file + "." + file + ")"
def takeSnapshot(self):
"""
@@ -57,7 +36,7 @@ def takeSnapshot(self):
snapshotTime = str(time.strftime("%a, %d %b %Y %H:%M:%S", time.localtime()))
snapshot += snapshotTime + "\">\n"
- for plugin in plugin_modules:
+ for plugin in self.plugin_modules:
entryData = plugin.getData()
if entryData != "":
snapshot += str(entryData + "\n")

0 comments on commit 577b804

Please sign in to comment.