Permalink
Browse files

moar network drafts

  • Loading branch information...
1 parent 9b18308 commit d173bca8cf927b874d6af0581a17863b7c7917ca @econchick committed Jun 25, 2013
Showing with 2,212 additions and 2,218 deletions.
  1. +6 −0 .gitignore
  2. +7 −3 AUTHORS.md
  3. +12 −8 docs/_posts/Begin/2013-09-29-Setup-your-machine.md
  4. +9 −11 docs/_posts/Networks/2013-04-05-Part-0-Setup-for-IRC-Bot.md
  5. +51 −3 docs/_posts/Networks/2013-06-09-IRC-Bot-Intro.md
  6. +8 −7 docs/_posts/Networks/2013-06-14-IRC-Bot-Landing.md
  7. +164 −34 docs/_posts/Networks/2013-06-14-Part-3-Bot-module.md
  8. +394 −2 docs/_posts/Networks/2013-06-14-Part-4-Twisted-Plugin.md
  9. +78 −13 docs/_posts/Networks/2013-06-14-Part-5-Tests.md
  10. +14 −0 docs/_posts/Networks/2013-06-14-Part-6-Running-our-Bot.md
  11. +7 −7 docs/_site/Begin/setup-your-machine/index.html
  12. +12 −9 docs/_site/archives/2013/index.html
  13. +12 −9 docs/_site/archives/index.html
  14. +3 −3 docs/_site/excerpt/index.html
  15. +3 −0 docs/_site/gui/index.html
  16. +2 −0 docs/_site/index.html
  17. +12 −9 docs/_site/tags/Network/index.html
  18. +12 −9 docs/_site/tags/irc/index.html
  19. +12 −9 docs/_site/tags/networks/index.html
  20. +21 −9 docs/_site/tutorials/index.html
  21. +8 −7 docs/_site/~drafts/networks/index.html
  22. +59 −3 docs/_site/~drafts/networks/intro/index.html
  23. +10 −11 docs/_site/~drafts/networks/part-0/index.html
  24. +29 −45 docs/_site/~drafts/networks/part-1/index.html
  25. +18 −18 docs/_site/~drafts/networks/part-2/index.html
  26. +259 −73 docs/_site/~drafts/networks/part-3/index.html
  27. +570 −2 docs/_site/~drafts/networks/part-4/index.html
  28. +92 −18 docs/_site/~drafts/networks/part-5/index.html
  29. +80 −0 docs/_site/~drafts/networks/part-6/index.html
  30. +1 −0 gui/README.md
  31. +53 −8 network/README.md
  32. +0 −47 network/README.rst
  33. +1 −3 network/requirements.txt
  34. +0 −17 network/settings.py
  35. +0 −17 network/settings.py.EXAMPLE
  36. +48 −50 network/talkback/bot.py
  37. +0 −13 network/talkback/quotation_selector.py
  38. +0 −1,638 network/talkback/quotes.txt
  39. +0 −21 network/tests/test_quotation_selector.py
  40. +0 −1 network/tests/test_quote.txt
  41. +1 −1 network/tests/test_quote_picker.py
  42. +0 −17 network/tests/test_settings.py
  43. +75 −38 network/tests/test_talkbackbot.py
  44. +0 −1 network/twistd.pid
  45. +69 −24 network/twisted/plugins/talkbackbot_plugin.py
View
@@ -1,8 +1,14 @@
*.pyc
.idea
+<<<<<<< Updated upstream
docs/.DS_Store
docs/_posts/.DS_Store
docs/_posts/.DS_Store
+=======
+.coverage
+htmlcov
+settings.ini
+>>>>>>> Stashed changes
View
@@ -1,5 +1,9 @@
-## Development Lead
+### Project Lead
* [Lynn Root](mailto:lynn@lynnroot.com)
-## Contributors
-* YOU
+### Contributors
+* [Alexander Afanasiev](https://github.com/alecxe)
+* [Horst Gutmann](https://github.com/zerok)
+* [Ana Krivokapić](https://github.com/infraredgirl)
+* [Hynek Schlawack](https://github.com/hynek)
+* [Jair Trejo](https://github.com/jairtrejo)
@@ -19,7 +19,7 @@ All the needed dependencies for setting up your Mac, Linux, or Windows machine f
The installation will depend on your operating system, but overall, you will need:
* Python 2.x – there are [plans][1] to update/include Python 3.x
-* git – an intro given [here]("http://newcoder.io/Save-your-progress")
+* git – an intro given [here]( {{get_url("begin/Save-your-progress")}})
* A C compiler
* pip
* virtualenv
@@ -41,7 +41,7 @@ Type "help", "copyright", "credits" or "license" for more information.
[Python.org][3] has a good [Python on the Mac][4] page if the above does not work for you.
### git
-You will need to install [git][5] on your machine through their [download page][6]. You can then follow the [Save your Progress]("http://newcoder.io/Save-your-progress") page to set it up.
+You will need to install [git][5] on your machine through their [download page][6]. You can then follow the [Save your Progress]({{ get_url("begin/Save-your-progress")}}) page to set it up.
### C compiler
@@ -100,7 +100,7 @@ Type "help", "copyright", "credits" or "license" for more information.
```
### git
-You will need to install [git][5] either from commands below or through their [download page][6]. You can then follow the [Save your Progress]("http://newcoder.io/Save-your-progress") page to set it up.
+You will need to install [git][5] either from commands below or through their [download page][6]. You can then follow the [Save your Progress]( {{ get_url("begin/Save-your-progress")}}) page to set it up.
* Fedora: `sudo yum git`
* Ubuntu: `sudo apt-get install git`
@@ -188,15 +188,15 @@ Success! You have installed Python!
### git
-Download git [here]("http://git-scm.com/download/win").
+Download git [here][gitwin].
### C Compiler
-Download the MinGW GCC compiler [here]("http://sourceforge.net/projects/mingw/files/latest/download?source=files") and follow installation instructions [here]("http://www.mingw.org/wiki/InstallationHOWTOforMinGW").
+Download the MinGW GCC compiler [here][mingw] and follow installation instructions [here][install].
### virtualenv + pip
-1. From [here]("http://pypi.python.org/pypi/virtualenv"), under Installation, see “You can just grab the single file virtualenv.py ..”. Right-click and save-as and place in the Scripts folder that we earlier added to system PATH.
+1. From [here][virtualenv], under Installation, see “You can just grab the single file virtualenv.py ..”. Right-click and save-as and place in the Scripts folder that we earlier added to system PATH.
2. From the command line, `cd` into the directory that you want to save your Python work. **IMPORTANT TIP**: Do not create or use a directory that has spaces in the name. For instance, ‘Python Projects’ is not good, but ‘PythonProjects’ is fine.
3. Within your Python project directory, type: `virtualenv.py dataviz`. A virtual environment called “dataviz” has been created, and now lives in your Python projects directory. This also installs pip: pip is a tool that is used to install Python packages
4. You will now need to activate the virtual environment by typing in your command line: `dataviz\Scripts\activate.bat`. You should see something like this: `(dataviz) C:\PythonProjects>`
@@ -359,7 +359,7 @@ django==1.5
* within an activated virtualenv, `pip install [PACKAGE_NAME]` installs a package into the virtualenv
* within an activated virtualenv, `pip freeze` lists the packages that is installed & accessible within the virtualenv
-You’re good to go with your setup! Go start on [dataviz]("http://newcoder.io/dataviz")!
+You’re good to go with your setup! Go start on [dataviz]({{ get_url("dataviz")}})!
[1]: https://github.com/econchick/new-coder/issues/28
[2]: http://www.python.org/images/terminal-in-finder.png
@@ -371,4 +371,8 @@ You’re good to go with your setup! Go start on [dataviz]("http://newcoder.io/d
[8]: https://github.com/econchick/new-coder/issues/29
[9]: http://www.pip-installer.org/en/latest/
[10]: https://pypi.python.org/pypi/virtualenv
-[11]: http://virtualenvwrapper.readthedocs.org/en/latest/
+[11]: http://virtualenvwrapper.readthedocs.org/en/latest/
+[mingw]: http://sourceforge.net/projects/mingw/files/latest/download?source=files
+[virtualenv]: http://pypi.python.org/pypi/virtualenv
+[install]: http://www.mingw.org/wiki/InstallationHOWTOforMinGW
+[gitwin]: http://git-scm.com/download/win
@@ -9,21 +9,19 @@ Initial setup for our Network/IRC Bot Tutorial.
### Setup
-**IMPORTANT**: Please be sure to work through the [machine setup][machinesetup] before proceeding.
+**IMPORTANT**: Please be sure to work through the [machine setup]({{ get_url("/setup-your-machine")}}) before proceeding.
Within your terminal:
-* `$ cd` to get to your 'Home' directory
-* If you haven’t already made a `Projects` folder for your new coder projects (or perhaps named it something else), then: `$ mkdir Projects` to create a new 'Projects' folder. You can name it whatever you want, just remember what you named it, and where it is.
-* Move into your `Projects` directory (or whatever you named it to): `cd Projects`.
-* `$ git clone https://github.com/econchick/new-coder.git` This clones the New Coder project into the directory you're currently in, which is Projects (unless you named it something else).
-* `$ cd new-coder/network` Change into the Network tutorial.
-* If you have [virtualenv-wrapper](http://pypi.python.org/pypi/virtualenvwrapper) and followed the steps above from [Initial Requirements](#initial-requirements) installed (which you should if you are on **Mac** or **Linux**, follow [machine setup][machinesetup] if not): `$ mkvirtualenv NetworkProj` Make a virtual environment specific to your Data Viz project. You should see (DataVizProject) before your prompt, now.
-* If you have **Windows**, within your Python project directory, type: `virtualenv.py NetworkProj`. A virtual environment called “NetworkProj” will be started. Now you will need to activate it, type: `NetworkProj\Scripts\activate.bat` and you’ll see something like `(NetworkProj) C:\PythonProjects>`
-* `(NetworkProj) $ pip install -r requirements.txt` Now installing package requirements for this project. Your virtual environment will store the required packages in a self-contained area to not mess up with other Python projects.
+1. `cd` to get to your Home directory
+2. If you haven’t already made a `Projects` folder for your new coder projects (or perhaps named it something else), then: `$ mkdir Projects` to create a new 'Projects' folder. You can name it whatever you want, just remember what you named it, and where it is.
+3. Move into your `Projects` directory (or whatever you named it to): `cd Projects`.
+4. If you haven’t already cloned the repo, then `$ git clone https://github.com/econchick/new-coder.git`. This clones the New Coder project into the directory you're currently in, which is Projects (unless you named it something else).
+5. `$ cd new-coder/network` Change into the Network tutorial.
+6. If you have [virtualenv-wrapper](http://pypi.python.org/pypi/virtualenvwrapper) and followed the steps above from [Initial Requirements](#initial-requirements) installed (which you should if you are on **Mac** or **Linux**, follow [machine setup]({{ get_url("/setup-your-machine")}}) if not): `$ mkvirtualenv NetworkProj` Make a virtual environment specific to your Data Viz project. You should see `(NetworkProj)` before your prompt, now.
+7. If you have **Windows**, within your Python project directory, type: `virtualenv.py NetworkProj`. A virtual environment called “NetworkProj” will be started. Now you will need to activate it, type: `NetworkProj\Scripts\activate.bat` and you’ll see something like `(NetworkProj) C:\PythonProjects>`
+8. `(NetworkProj) $ pip install -r requirements.txt` Now installing package requirements for this project. Your virtual environment will store the required packages in a self-contained area to not mess up with other Python projects.
Now you’re ready to move onto [defining our bot settings &rarr;]( {{ get_url("/~drafts/networks/part-1/")}})
-
-[machinesetup]({{ get_url("/setup-your-machine")}})
@@ -4,7 +4,7 @@ layout: post.html
tags: [irc, network, networks]
url: "/~drafts/networks/intro/"
---
-## Intro
+
### The Project
@@ -49,13 +49,61 @@ Some paradigms include [object-oriented](http://en.wikipedia.org/wiki/Object-ori
### Intro to Logging
-**NOTE** logging module is being ripped out for Twisted’s logging.
+Logging is quite important for applications. Transferring money, the black box on an airplane, cell phone bills - they all log actions to be referenced and checked later. As such, logging is quite important for developing, debugging, maintaining, and running systems and applications.
+
+There is the `logging` module in Python’s standard library, and a great [how-to](http://docs.python.org/2/howto/logging-cookbook.html) write up for the `logging` module.
+
+But Twisted has its own logging module, `log`. The initial reason that Twisted doesn’t use the `logging` module from the Python standard library is that the Twisted logging module predates the stdlib one. There are many reasons that Twisted hasn’t moved to the stdlib logging module which you can read [here](http://twistedmatrix.com/trac/wiki/TwistedLogging).
+
+You may start out simply adding `print` statements to your application, but this isn’t ideal for anything beyond a very basic script. `print` does not allow you to set up different importance levels, e.g. `DEBUG`, `INFO`, `WARN`, `ERROR`, `CRITICAL`, or `FAIL`; it's an all or nothing with `print`.
+
+Identifying which level of importance to log a message at can get some getting use to. Use the `debug` level for granular information, such as printing out variables that change within a for-loop:
+
+```python
+def some_awesome_function(items):
+ for i, item in enumerate(items):
+ # do some complex computation/iteration
+ logger.debug('%s iteration, item=%s', i, item)
+```
+
+Use `info` for routines and such, like starting or connecting to a server:
+
+```python
+def start_IMAP_service():
+ logger.info('Starting IMAP service at port %s ...', port)
+ service.start()
+ logger.info('IMAP Service is started')
+```
+
+Use `warn` for important events happen, but no error has occurred, like a password that was incorrectly inputted. Finally, use `error` for when an exception is thrown, user isn’t found in the database, connectivity issue, etc. As the admin of an application with a logging mechanism, you would setup your desired level of logs in some configuration for instance, if you only want to see errors, you would ideally set a configuration value to something like `debug_level=error`.
+
+These above examples use Python’s `logging` module. For our tutorial, we’ll use Twisted’s `log` module, which has slightly different syntax when passing in log levels.
### Intro to Testing
-**NOTE** unittest module is being ripped out for Twisted’s testing module.
+Very similar to logging, testing is also quite important for your code base. Writing tests in parallel to writing code is considered good habit. Submitting features and patches to projects without tests can be a big faux-pas.
+
+There are different types of testing, and with this tutorial we will focus on unit testing.
+
+A unit test just focuses on one tiny bit of functionality to prove it correct, and should be independent of other unit tests.
+
+An example of a unit test using Pythons `unittest` module, taken from [python-guide.org](http://docs.python-guide.org/en/latest/writing/tests.html#unittest):
+
+```python
+import unittest
+
+def fun(x):
+ return x + 1
+
+class MyTest(unittest.TestCase):
+ def test(self):
+ self.assertEqual(fun(3), 4)
+```
+
+The main part here is `assertEqual(fun(3), 4)`, where we feed `fun` the number `3`. The test will pass if the return value of `fun(3) == 4`, else it will fail.
+We will be using Twisted’s own unit testing framework that is built upon Python’s `unittest` module with the added ability to test event-driven code.
### Approaching the tutorial
@@ -7,10 +7,11 @@ url: "/~drafts/networks/"
[Introduction to the Networking tutorial]({{ get_url("/~drafts/networks/intro/")}})
-[Part 0: Setup]({{ get_url("/~drafts/networks/part-0/")}}) – Initial setup for our Networking tutorial
-[Part 1: Settings]({{ get_url("/~drafts/networks/part-1/")}})
-[Part 2: Quote Picker]({{ get_url("/~drafts/networks/part-2/")}})
-[Part 3: Bot.py Module]({{ get_url("/~drafts/networks/part-3/")}})
-[Part 4: Custom Twisted Plugin]({{ get_url("/~drafts/networks/part-4/")}})
-[Part 5: Testing the bot]({{ get_url("/~drafts/networks/part-5/")}})
-[Extended]({{ get_url("/~drafts/networks/extended/")}})
+[Part 0: Setup]({{ get_url("/~drafts/networks/part-0/")}}) – Initial setup for our Networking tutorial.
+[Part 1: Settings]({{ get_url("/~drafts/networks/part-1/")}}) – Define our settings for our IRC bot.
+[Part 2: Quote Picker]({{ get_url("/~drafts/networks/part-2/")}}) – Walkthrough of the pseudo-random quotation picker.
+[Part 3: Bot.py Module]({{ get_url("/~drafts/networks/part-3/")}}) – Writing our `bot.py` module.
+[Part 4: Custom Twisted Plugin]({{ get_url("/~drafts/networks/part-4/")}}) – Writing our `twistd` command line plugin for easy deployment.
+[Part 5: Testing the bot]({{ get_url("/~drafts/networks/part-5/")}}) – Unit tests for our IRC Bot application.
+[Part 6: Running the bot and test suite]({{ get_url("/~drafts/networks/part-6")}}) – Running the bot application and its tests.
+[Extended]({{ get_url("/~drafts/networks/extended/")}}) – Networks used in real life, and where to go from here.
Oops, something went wrong.

0 comments on commit d173bca

Please sign in to comment.