<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Recent changes to test_task.py</title><link>https://sourceforge.net/p/marvin-the-robot/wiki/test_task.py/</link><description>Recent changes to test_task.py</description><atom:link href="https://sourceforge.net/p/marvin-the-robot/wiki/test_task.py/feed" rel="self"/><language>en</language><lastBuildDate>Sun, 20 Mar 2016 22:23:24 -0000</lastBuildDate><atom:link href="https://sourceforge.net/p/marvin-the-robot/wiki/test_task.py/feed" rel="self" type="application/rss+xml"/><item><title>test_task.py modified by Brett Solon</title><link>https://sourceforge.net/p/marvin-the-robot/wiki/test_task.py/</link><description>&lt;div class="markdown_content"&gt;&lt;h2 id="optmarvintaskstest_taskpy"&gt;/opt/marvin/tasks/test_task.py&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;This is a test script to for checking MARVIN's configuration:&lt;/strong&gt;&lt;br/&gt;
1. Import the speak and new_message functions from marvin&lt;br/&gt;
2. Create a new message&lt;br/&gt;
3. Assign values to various fields in marvins_message&lt;br/&gt;
4. Speak marvins_message&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Explanation:&lt;/strong&gt;&lt;br/&gt;
1. MARVIN includes built-in functions for frequent use. The &lt;em&gt;new_message&lt;/em&gt; function is designed to return a custom dictionary variable with common fields defined. The &lt;em&gt;speak&lt;/em&gt; function calls MARVIN's "mouth" to deliver the message (per MARVIN's configuration).&lt;br/&gt;
2. Create a new variable for storing the output from this task. The &lt;em&gt;new_message&lt;/em&gt; function returns a predefined variable of the dictionary type. The &lt;em&gt;metafields&lt;/em&gt; of the message (keys) are initialized with blank values. This specific format is required as the input of the &lt;em&gt;speak&lt;/em&gt; function.&lt;br/&gt;
3. Set some values so MARVIN will have something to say.&lt;br/&gt;
4. Use the &lt;em&gt;speak&lt;/em&gt; function to output the message. This will call the "mouth," which should be configured to output the message by SMTP or Syslog. This function expects a variable created by the &lt;em&gt;new_message&lt;/em&gt; function.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;THE CODE!&lt;/strong&gt;&lt;/p&gt;
&lt;table class="codehilitetable"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt; 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span class="c"&gt;#!/usr/bin/python&lt;/span&gt;

&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;marvin&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;speak&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;new_message&lt;/span&gt;

&lt;span class="n"&gt;marvins_message&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;new_message&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;marvins_message&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;'task'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;'test_task'&lt;/span&gt;
&lt;span class="n"&gt;marvins_message&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;'name'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;'MARVIN'&lt;/span&gt;
&lt;span class="n"&gt;marvins_message&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;'message'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"I'm alive!!"&lt;/span&gt;
&lt;span class="n"&gt;marvins_message&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;'sourceHostname'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;'localhost'&lt;/span&gt;
&lt;span class="n"&gt;marvins_message&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;'sourceAddress'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;'127.0.0.1'&lt;/span&gt;
&lt;span class="n"&gt;marvins_message&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;'sourcePort'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;'31337'&lt;/span&gt;
&lt;span class="n"&gt;marvins_message&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;'sourceUsername'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;'testuser'&lt;/span&gt;
&lt;span class="n"&gt;marvins_message&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;'url'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;'http://www.example.com'&lt;/span&gt;

&lt;span class="n"&gt;speak&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;marvins_message&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Brett Solon</dc:creator><pubDate>Sun, 20 Mar 2016 22:23:24 -0000</pubDate><guid>https://sourceforge.net0a9273d4e49332f916ebaea04902c7f6cd05d2aa</guid></item></channel></rss>