Popular recipes tagged "meta:loc=124"http://code.activestate.com/recipes/tags/meta:loc=124/2016-04-28T13:21:43-07:00ActiveState Code RecipesSending Email From A Python Program (Python) 2014-01-10T20:13:45-08:00Captain DeadBoneshttp://code.activestate.com/recipes/users/4184772/http://code.activestate.com/recipes/578807-sending-email-from-a-python-program/ <p style="color: grey"> Python recipe 578807 by <a href="/recipes/users/4184772/">Captain DeadBones</a> (<a href="/recipes/tags/email/">email</a>, <a href="/recipes/tags/smtp/">smtp</a>, <a href="/recipes/tags/time/">time</a>). Revision 4. </p> <p>I put together this code for one of my programs and decided to share it. You may never know when you will need you Python Program to send an email to someone. <a href="http://thelivingpearl.com/2014/01/10/sending-email-from-python-using-command-line/">Sending Email From Python</a>. </p> <p>NOTE: You will have to change the account setup variables to your own. The server is currently configured o Gmail, but you can use this script with any server. </p> Position The Cursor Almost Anywhere Inside Standard Text Mode Python Terminal. (Python) 2012-06-17T17:10:29-07:00Barry Walkerhttp://code.activestate.com/recipes/users/4177147/http://code.activestate.com/recipes/578167-position-the-cursor-almost-anywhere-inside-standar/ <p style="color: grey"> Python recipe 578167 by <a href="/recipes/users/4177147/">Barry Walker</a> (<a href="/recipes/tags/amiga/">amiga</a>, <a href="/recipes/tags/apple/">apple</a>, <a href="/recipes/tags/cursor/">cursor</a>, <a href="/recipes/tags/demo/">demo</a>, <a href="/recipes/tags/e_uae/">e_uae</a>, <a href="/recipes/tags/linux/">linux</a>, <a href="/recipes/tags/locate/">locate</a>, <a href="/recipes/tags/macbook_pro/">macbook_pro</a>, <a href="/recipes/tags/winuae/">winuae</a>). </p> <p>A DEMO showing the power of the ANSI (ASCII) _Esc_ codes in standard text mode Python.</p> <p>ANSI _Esc_ codes here:- <a href="http://www.termsys.demon.co.uk/vtansi.htm" rel="nofollow">http://www.termsys.demon.co.uk/vtansi.htm</a></p> <p>There are only three important things from the ANSI _Esc_ codes that are needed to obtain a neat finish to a program written in standard text mode Python:-</p> <p>1) Clearing the screen. (Already done without the dedicated ANSI _Esc_ code!)</p> <p>2) Colours and other character attributes. (Already done!)</p> <p>3) A forced printing of a character or string from a given location inside the Terminal window.</p> <p>To clear the screen does NOT require another dedicated ANSI _Esc_ code, (although it exists). This code uses the print("\r\n") method which works in all cases coupled with the one function supplied......</p> <p>For The Classic AMIGA, E-UAE, WinUAE and Linux using Python(s) 1.4.0 to Python 3.2.2. Read the code for more information...</p> <p>Enjoy finding simple solutions to often very difficult problems...</p> <p>Bazza, G0LCU.</p> Dropbox file uploader via web interface using Python with urllib2 and mechanize (Python) 2016-04-28T13:21:43-07:00ccpizzahttp://code.activestate.com/recipes/users/4170754/http://code.activestate.com/recipes/578030-dropbox-file-uploader-via-web-interface-using-pyth/ <p style="color: grey"> Python recipe 578030 by <a href="/recipes/users/4170754/">ccpizza</a> (<a href="/recipes/tags/dropbox/">dropbox</a>, <a href="/recipes/tags/mechanize/">mechanize</a>). Revision 7. </p> <p>UPDATE: This is script is not maintained and does not anymore with the current version of Dropbox. For a proper command line interface to dropbox I recommend <code>dropbox_uploader</code>: <a href="https://github.com/andreafabrizi/Dropbox-Uploader" rel="nofollow">https://github.com/andreafabrizi/Dropbox-Uploader</a></p> <p>Originally inspired by the example at <a href="http://joncraton.org/blog/62/uploading-dropbox-python" rel="nofollow">http://joncraton.org/blog/62/uploading-dropbox-python</a>. </p> <p>The script uses mechanize to logon to the web page and upload the file(s) to the Dropbox root folder or to the folder supplied on the command line as <code>dir:/my_dropbox_path</code> (if present, this must be the first parameter).</p> <p>Multiple files and/or glob patterns names are accepted as script arguments.</p> <h5 id="example-usage">Example usage</h5> <pre class="prettyprint"><code>dropbox.py file1.txt # upload to root folder dropbox.py dir:/Backups/2012 file1.txt # upload to custom folder dropbox.py dir:/Backups/2012 *.txt # upload by file mask dropbox.py dir:/Backups/2020 * # upload all files in current dir </code></pre> <p>Limitations: only files in current folder are processed, subfolders are ignored.</p> <h5 id="note">NOTE</h5> <p>The script requires the <code>mechanize</code> module - use <code>pip install mechanize</code> or <code>easy_install mechanize</code> to add it to your site-packages.</p> <h5 id="note2">NOTE2</h5> <p>I have found a cleaner way to manage dropbox files from the console - see the <em>dropbox-uploade</em>r script at <a href="https://github.com/andreafabrizi/Dropbox-Uploader" rel="nofollow">https://github.com/andreafabrizi/Dropbox-Uploader</a> - it is a Bash script that works using the official Dropbox API rather than emulating a web browser.</p> Simple Sudoku (Python) 2011-06-02T14:15:02-07:00amir naghavihttp://code.activestate.com/recipes/users/4177294/http://code.activestate.com/recipes/577716-simple-sudoku/ <p style="color: grey"> Python recipe 577716 by <a href="/recipes/users/4177294/">amir naghavi</a> (<a href="/recipes/tags/algorithm/">algorithm</a>, <a href="/recipes/tags/game/">game</a>, <a href="/recipes/tags/oo/">oo</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/random/">random</a>, <a href="/recipes/tags/sudoku/">sudoku</a>). Revision 10. </p> <p>This is a simple sudoku game.</p> Item Properties (Python) 2012-05-09T23:24:55-07:00Ian Kellyhttp://code.activestate.com/recipes/users/4178016/http://code.activestate.com/recipes/577703-item-properties/ <p style="color: grey"> Python recipe 577703 by <a href="/recipes/users/4178016/">Ian Kelly</a> (<a href="/recipes/tags/decorator/">decorator</a>, <a href="/recipes/tags/descriptor/">descriptor</a>, <a href="/recipes/tags/oop/">oop</a>, <a href="/recipes/tags/property/">property</a>). Revision 2. </p> <p>A property variation that allows property access using an index or key.</p> Tiny trace/debug-logging tool with smart event filtering (Python) 2011-04-29T02:23:37-07:00Jan Kaliszewskihttp://code.activestate.com/recipes/users/4172762/http://code.activestate.com/recipes/577429-tiny-tracedebug-logging-tool-with-smart-event-filt/ <p style="color: grey"> Python recipe 577429 by <a href="/recipes/users/4172762/">Jan Kaliszewski</a> (<a href="/recipes/tags/debugging/">debugging</a>, <a href="/recipes/tags/logging/">logging</a>, <a href="/recipes/tags/trace/">trace</a>). Revision 3. </p> <ul> <li><p>Just import, call and log your selected call/return/exception/etc. events.</p></li> <li><p>You can use a standard Python logger from the <code>logging</code> module.</p></li> <li><p>Quite flexible tool and about 50 efective SLOC only (excluding the example script).</p></li> <li><p>For debugging rather than production environments (programs noticeably slow down).</p></li> </ul> BlueMon (Python) 2009-01-25T13:51:58-08:00nigel spinneyhttp://code.activestate.com/recipes/users/4113342/http://code.activestate.com/recipes/576627-bluemon/ <p style="color: grey"> Python recipe 576627 by <a href="/recipes/users/4113342/">nigel spinney</a> (<a href="/recipes/tags/automate/">automate</a>, <a href="/recipes/tags/bluetooth/">bluetooth</a>, <a href="/recipes/tags/parallel_port/">parallel_port</a>, <a href="/recipes/tags/speech/">speech</a>, <a href="/recipes/tags/ubuntu/">ubuntu</a>). </p> <p>Scans for discoverable bluetooth devices every 35 seconds, and announces (with espeak in Ubuntu) and logs, devices which come into or out of range. Idea for automated processes like turning on exterior lighting and heating by the parallel port</p> Directory Walking File Renamer (Python) 2008-12-28T08:04:34-08:00mickey Hadickhttp://code.activestate.com/recipes/users/4168585/http://code.activestate.com/recipes/576597-directory-walking-file-renamer/ <p style="color: grey"> Python recipe 576597 by <a href="/recipes/users/4168585/">mickey Hadick</a> (<a href="/recipes/tags/directory/">directory</a>, <a href="/recipes/tags/file/">file</a>, <a href="/recipes/tags/rename/">rename</a>). </p> <p>Walk through a list of directories and rename the files within those directories based on the directory name and an index value. Useful for managing photos when downloaded from a camera into directories based on the shooting date.</p> Exectute shell command on Remote *nix machine (Python) 2008-07-18T02:20:22-07:00winterTTr Donghttp://code.activestate.com/recipes/users/4164498/http://code.activestate.com/recipes/576363-exectute-shell-command-on-remote-nix-machine/ <p style="color: grey"> Python recipe 576363 by <a href="/recipes/users/4164498/">winterTTr Dong</a> (<a href="/recipes/tags/network/">network</a>). </p> <p>Use telnetlib to execute the shell command from localhost.</p> <p>An example to show the funciton. Output the result to result.log.</p> <p>from PyRemoteControl import RemoteShellCommand</p> <h4>host info</h4> <p>host_ip = '' user_name = 'fw' password = 'fw' result_file = 'result.log'</p> <h4>command List</h4> <p>cmdList = [ 'cd' , 'll' ]</p> <h4>init</h4> <p>cursor = RemoteShellCommand( host_ip , user_name , password , result_file ) cursor.AddPrompt( '[fw@localhost .<em>]\$ ') cursor.AddPrompt( '[root@localhost .</em>]# ' )</p> <h4>connect to Linux</h4> <p>cursor.Login()</p> <h4>change to root</h4> <p>cursor.SendInterActiveCmd( 'su - ' , [ ('Password: ' , 'rootPassord')] , False)</p> <h4>Exec Command</h4> <p>for cmd in cmdList : cursor.SendCmd( cmd )</p> <h4>logout</h4> <p>cursor.Logout()</p> Copying Generators (Python) 2007-10-09T07:38:06-07:00kay schluehrhttp://code.activestate.com/recipes/users/2398921/http://code.activestate.com/recipes/528949-copying-generators/ <p style="color: grey"> Python recipe 528949 by <a href="/recipes/users/2398921/">kay schluehr</a> (<a href="/recipes/tags/algorithms/">algorithms</a>). Revision 5. </p> <p>This recipe presents copy_generator(...) which a pure Python function keeping a running generator object and returns a copy of the generator object being in the same state as the original generator object.</p> Connecting to running instances of IE on your computer (Python) 2004-09-16T08:55:39-07:00Eric Koomehttp://code.activestate.com/recipes/users/171968/http://code.activestate.com/recipes/305273-connecting-to-running-instances-of-ie-on-your-comp/ <p style="color: grey"> Python recipe 305273 by <a href="/recipes/users/171968/">Eric Koome</a> (<a href="/recipes/tags/web/">web</a>). Revision 2. </p> <p>This sample connects to the running instances of IE on your computer and prints out the URL, Cookie- if any, and the HTML content of the site. It can be extended to connect to running instances on another computer using DCOM and particularly using CoCreateInstanceEx(): Extend it as you wish and let me know how useful it has been to you!</p> cgi-shell (Python) 2004-07-09T07:31:52-07:00Michael Foordhttp://code.activestate.com/recipes/users/1565518/http://code.activestate.com/recipes/286217-cgi-shell/ <p style="color: grey"> Python recipe 286217 by <a href="/recipes/users/1565518/">Michael Foord</a> (<a href="/recipes/tags/cgi/">cgi</a>). </p> <p>Run an arbitrary string on the server as a shell command. Mimics a very basic shell environment on a server using CGI.</p> cgi-shell (Python) 2004-07-09T07:30:50-07:00Michael Foordhttp://code.activestate.com/recipes/users/1565518/http://code.activestate.com/recipes/286216-cgi-shell/ <p style="color: grey"> Python recipe 286216 by <a href="/recipes/users/1565518/">Michael Foord</a> (<a href="/recipes/tags/cgi/">cgi</a>). </p> <p>Run an arbitrary string on the server as a shell command. Mimics a very basic shell environment on a server using CGI.</p> CookieInfo (Python) 2002-02-23T01:34:25-08:00Mark Nenadovhttp://code.activestate.com/recipes/users/114221/http://code.activestate.com/recipes/66454-cookieinfo/ <p style="color: grey"> Python recipe 66454 by <a href="/recipes/users/114221/">Mark Nenadov</a> (<a href="/recipes/tags/sysadmin/">sysadmin</a>). Revision 3. </p> <p>The "CookieInfo" and "Cookie" classes provide developers with an read-only interface to the "cookies.txt" that most browsers store. The CookieInfo class makes Cookie objects from the cookie file. It also provides methods to operate on the whole set of Cookies. The Cookie object provides methods to convert a cookie into both XML and SQL.</p>