manningtree

Fixing Manningtree

Category: TheShed
#blog #tools #python

Manningtree has been around almost as long as c r o s s o a k. It's been through two iterations and is now onto its third. The first was as a blogger site (you can see the remnants as pages exported from blogger like this one). Then it moved …

Analysing Crossoak

Category: TheShed
#blog #python #SysAdmin

A friend had a theory that photography, and therefore by extension c r o s s o a k is a window into my mental well being. So I did some digging which I'm capturing here (and which is in all probability a much bigger insight into my head...). If …

More on MPD

Category: TheShed
#SysAdmin #music #mpd #python

More jottings on MPD (previously on m a n n i n g t r e e)

OneDrive from Python

Category: TheShed
#programming #python #onedrive #tools #SysAdmin

A nice commandline tool (based on a Python wrapper for the OneDrive REST API) for working with OneDrive.

pywin32 0. Setup a Python Virtual Environment 1. On Windows, install pywin32 . From the venv use easy_install http://sourceforge.net/projects/pywin32/files/pywin32/Build%20219/pywin32-219.win32-py2.7.exe/download (with …

Send to Kindle

Category: TheShed
#python #Kindle #SysAdmin #tools

A nice little Python Script to send documents to Amazon Kindle via a command line.

(It works too :-)

Virtual Python

Category: TheShed
#python #Programming

A quick starter on Python Virtual Environment

Create:

mkdir workingdir
cd workingdir
virtualenv venv

On Unix/Mac OS X use:

source venv/bin/activate

On Windows use:

venv\Scripts\activate.bat

Finish:

deactivate

To move the environment somewhere else:

  1. In existing (active) environment; grab a list of dependencies with pip …

Python on Unix

Category: TheShed
#python #Programming

A fragment to let Unix boxes (and Mac OS X) know that this is a python script:

1
#!/usr/bin/env python

Add at the start of the script.

Make sure the script is executable with:

chmod +x scriptname.py

Executing a process on Windows

Category: TheShed
#Python #Programming

A fragment to execute a process on Windows:

from subprocess import Popen
proc = Popen("vi \"" + filename + "\"", shell=True )
print(proc)

Which opens filename with vi (whatever that might be on a Windows box). Note that while Python is pretty good from a crossplatform perspective, it's not the best when it …

Writing to a file in Python

Category: TheShed
#Python #filesystem #Programming

A fragment for writing to a file in Python:

f = open(filename,'w')
f.write('Hey, I'm saying Hello file! \n')
f.close()

Note that this will overwrite an existing file. Use open(filename,'a') to open in append mode. The Python documentation has details.

Python DateTime

Category: TheShed
#Python #Dates #Programming

A fragment for formatting dates and time in Python:

import datetime
date = datetime.datetime.now()
sDate = date.strftime("%Y%m%d")
sDateTime =  date.strftime("%Y%m%d %H:%M:%S")

See see https://docs.python.org/2/library/datetime.html#strftime-and-strptime-behavior for formatting for details of string formatting for dates …