Popular Python recipes tagged "meta:requires=datetime"http://code.activestate.com/recipes/langs/python/tags/meta:requires=datetime/2016-09-18T20:39:20-07:00ActiveState Code RecipesDBF reader and writer -- selective fields and nullreplace (Python)
2016-09-18T20:39:20-07:00Tomas Nordinhttp://code.activestate.com/recipes/users/4189558/http://code.activestate.com/recipes/580696-dbf-reader-and-writer-selective-fields-and-nullrep/
<p style="color: grey">
Python
recipe 580696
by <a href="/recipes/users/4189558/">Tomas Nordin</a>
(<a href="/recipes/tags/database/">database</a>).
</p>
<p>This fork assumes a desire for limited selection of field names. With
huge files this might be necessary on some machines.</p>
<p>Also, assuming that the meaning of null in a dbf file means zero might
be a mistake, so the fork adds an argument nullreplace as way to
choose what to replace null with. Null is sometimes used to mean
missing value. This change is decoupled from the selective names
feature.</p>
Configurable JSON Extensions for Python (Python)
2016-05-22T19:00:54-07:00Michael Blan Palmerhttp://code.activestate.com/recipes/users/4194130/http://code.activestate.com/recipes/580664-configurable-json-extensions-for-python/
<p style="color: grey">
Python
recipe 580664
by <a href="/recipes/users/4194130/">Michael Blan Palmer</a>
(<a href="/recipes/tags/json/">json</a>, <a href="/recipes/tags/python/">python</a>).
</p>
<p>The concept behind the package is to build a single class per type you want to add to json in Python. The new class will have a method for encoding to json and a method for decoding from json. The classes are then loaded into an encoder object and a decoder object that are hooked into the standard json loads
and dumps functions.</p>
vlc.py stream capture scheduler script (Python)
2015-08-19T05:00:25-07:00jwhite88http://code.activestate.com/recipes/users/4192711/http://code.activestate.com/recipes/579096-vlcpy-stream-capture-scheduler-script/
<p style="color: grey">
Python
recipe 579096
by <a href="/recipes/users/4192711/">jwhite88</a>
(<a href="/recipes/tags/recording/">recording</a>, <a href="/recipes/tags/stream/">stream</a>, <a href="/recipes/tags/vlc/">vlc</a>).
</p>
<p>Capture network streams using vlc.py on a schedule.</p>
start and end date given the year and week (Python)
2015-03-14T01:25:49-07:00Fernando Peraltahttp://code.activestate.com/recipes/users/4191815/http://code.activestate.com/recipes/579034-start-and-end-date-given-the-year-and-week/
<p style="color: grey">
Python
recipe 579034
by <a href="/recipes/users/4191815/">Fernando Peralta</a>
(<a href="/recipes/tags/and/">and</a>, <a href="/recipes/tags/date/">date</a>, <a href="/recipes/tags/end/">end</a>, <a href="/recipes/tags/given/">given</a>, <a href="/recipes/tags/start/">start</a>, <a href="/recipes/tags/week/">week</a>, <a href="/recipes/tags/year/">year</a>).
</p>
<p>Determines the starting and ending date when the year and week are specified for a by-weekly report.</p>
Analog Clock (Python)
2014-05-14T20:53:39-07:00Paulo Cavalcantihttp://code.activestate.com/recipes/users/4189949/http://code.activestate.com/recipes/578875-analog-clock/
<p style="color: grey">
Python
recipe 578875
by <a href="/recipes/users/4189949/">Paulo Cavalcanti</a>
(<a href="/recipes/tags/clock/">clock</a>).
Revision 3.
</p>
<p>A python-tkinter analog clock</p>
lru_timestamp - cache entry aging for functools.lru_cache (Python)
2014-02-02T21:28:25-08:00Peter Santorohttp://code.activestate.com/recipes/users/4189027/http://code.activestate.com/recipes/578817-lru_timestamp-cache-entry-aging-for-functoolslru_c/
<p style="color: grey">
Python
recipe 578817
by <a href="/recipes/users/4189027/">Peter Santoro</a>
(<a href="/recipes/tags/age/">age</a>, <a href="/recipes/tags/lru_cache/">lru_cache</a>).
</p>
<p>Return a timestamp string for @lru_cache decorated functions.</p>
<p>The returned timestamp is used as the value of an extra parameter
to @lru_cache decorated functions, allowing for more control over
how often cache entries are refreshed. The lru_timestamp function
should be called with the same refresh_interval value for a given
@lru_cache decorated function. The returned timestamp is for the
benefit of the @lru_cache decorator and is normally not used by
the decorated function.</p>
<p>Positional arguments:
refresh_interval -- in minutes (default 60), values less than 1
are coerced to 1, values more than 1440 are
coerced to 1440</p>
A wxPython GUI To Create Sqlite3 Databases (Python)
2013-09-18T23:05:51-07:00toufic zaarourhttp://code.activestate.com/recipes/users/4187866/http://code.activestate.com/recipes/578665-a-wxpython-gui-to-create-sqlite3-databases/
<p style="color: grey">
Python
recipe 578665
by <a href="/recipes/users/4187866/">toufic zaarour</a>
(<a href="/recipes/tags/gui/">gui</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/sqlite/">sqlite</a>, <a href="/recipes/tags/wxpython/">wxpython</a>).
Revision 2.
</p>
<p>A GUI built around wxPython in a way that will allow you to add to this application other forms and functionalities. The main DialogBox is to create,in a fast way, Sqlite3 databases that are used for web or applications development. In order to work properly, save the script in a separate directory.There is also more; each time you create a database a text file named "CreationLog.txt" will be created (for the first time you use the application or if it is not there) and updated, describing when and where was your database created and with what SQL query. I am pleased to receive all the suggestions and improvements on this site or to my e-mail directly if this is convenient to you.</p>
Analog stopclock (Python)
2013-03-15T18:30:37-07:00prashanth.chengihttp://code.activestate.com/recipes/users/4185699/http://code.activestate.com/recipes/578493-analog-stopclock/
<p style="color: grey">
Python
recipe 578493
by <a href="/recipes/users/4185699/">prashanth.chengi</a>
(<a href="/recipes/tags/analog/">analog</a>, <a href="/recipes/tags/chess/">chess</a>, <a href="/recipes/tags/clock/">clock</a>).
</p>
<p>A very simple tkinter analog stopclock</p>
Monday of first week per year (not first Monday) (Python)
2012-10-31T04:37:28-07:00Scott S-Allenhttp://code.activestate.com/recipes/users/4181178/http://code.activestate.com/recipes/578308-monday-of-first-week-per-year-not-first-monday/
<p style="color: grey">
Python
recipe 578308
by <a href="/recipes/users/4181178/">Scott S-Allen</a>
(<a href="/recipes/tags/date/">date</a>, <a href="/recipes/tags/week/">week</a>).
Revision 4.
</p>
<p>13th week of any year is ambiguous without identifying the first week. </p>
<p>This recipe calculates Monday of the first week, not the first Monday, and differs from others by not using flow-control statement (if).</p>
Python reader + writer for spss sav files (Linux, Mac & Windows) (Python)
2013-02-20T22:07:27-08:00Albert-Jan Roskamhttp://code.activestate.com/recipes/users/4177640/http://code.activestate.com/recipes/577811-python-reader-writer-for-spss-sav-files-linux-mac-/
<p style="color: grey">
Python
recipe 577811
by <a href="/recipes/users/4177640/">Albert-Jan Roskam</a>
(<a href="/recipes/tags/reader/">reader</a>, <a href="/recipes/tags/sav/">sav</a>, <a href="/recipes/tags/spss/">spss</a>, <a href="/recipes/tags/writer/">writer</a>).
Revision 12.
</p>
<p><strong>Python Program to READ & WRITE Spss system files (.sav) (Linux,Mac or Windows)</strong></p>
<ul>
<li><em>Check <a href="https://pypi.python.org/pypi/savReaderWriter/" rel="nofollow">https://pypi.python.org/pypi/savReaderWriter/</a> for the latest version (including the libraries!)</em></li>
<li>Requires libspssdio.so.1 (LINUX) or libspssdio.dylib (MAC) or spssio32.dll (WINDOWS) plus associated libaries, which can be freely downloaded from:
<a href="https://www.ibm.com/developerworks/mydeveloperworks/wikis/home/wiki/We70df3195ec8_4f95_9773_42e448fa9029/page/Downloads%2520for%2520IBM%25C2%25AE%2520SPSS%25C2%25AE%2520Statistics?lang=en" rel="nofollow">https://www.ibm.com/developerworks/mydeveloperworks/wikis/home/wiki/We70df3195ec8_4f95_9773_42e448fa9029/page/Downloads%20for%20IBM%C2%AE%20SPSS%C2%AE%20Statistics?lang=en</a></li>
<li>It is recommended to download the v21 I/O files (required for writing zlib (.zsav) compressed files)</li>
<li>December 2012 (complete rewrite):</li>
<li>Added support for slicing, indexing, array slicing + other special methods</li>
<li>Added support for writing spss date fields</li>
<li>Added support for almost all meta data (missing values, sets, roles, etc.)</li>
<li>Added support for 64 bit Windows (tested with Win7) and other OSs
(z/Linux, Solaris, HP Linux, IBM AIX (untested though)</li>
<li>Added support for reading and writing zlib compressed (.zsav) files</li>
<li>Removed pesky segfault error when freeing memory</li>
<li>Removed errors related to encoding</li>
<li>Changed some Reader defaults (verbose=False, returnHeader=False)</li>
<li>Renamed SavDataDictionaryReader into SavHeaderReader</li>
</ul>
<p><strong>LINUX:</strong></p>
<p><em>Installation (tested on Linux Ubuntu 10):</em></p>
<ul>
<li>additional packages/files needed are: intel-icc8-libs_8.0-1_i386.deb,libicu32_3.2-3_i386.deb, libstdc++5_3.3.6-20_i386.deb, libirc.so.</li>
<li>Run the following commands in your terminal: sudo apt-get install intel-icc8-libs; sudo apt-get install libicu32; sudo apt-get install libstdc++5.</li>
<li>Then convert libirc.a (static) to libirc.so (dynamic), save in same location as libspssdio.so.1:
ar vx intel-icc8-libs_8.0-1_i386.deb; tar -xzvf data.tar.gz ./usr/lib/libirc.a; ar -x libirc.a.</li>
</ul>
<p><em>Calling the program:</em></p>
<ul>
<li>In the TERMINAL type: export LD_LIBRARY_PATH=/path/of/additional/sofiles; python /some/path/wrapperToProgram.py. You may also add ld_library_path to .bashrc</li>
<li>The wrapper starts with "from SavReaderWriter import *", followed by e.g. stuff from the if __name__ == '__main__' section</li>
</ul>
<p><strong>MAC OS:</strong></p>
<ul>
<li>you must put all the dylib files that come with the IBM
SPSS_Statistics_InputOutput_Modules_* package in the macos
directory somewhere that OS X can find them</li>
<li>one simple way to accomplish this is to copy them to /usr/lib</li>
</ul>
<p><strong>WINDOWS:</strong></p>
<ul>
<li>You can also find this dll in the installation directory of SPSS (although SPSS is _not_ needed!)</li>
<li>The .dll should be saved in the same location as this program.</li>
</ul>
<p><strong>USAGE:</strong>
See docstrings + __main__ section</p>
Flexible datetime parsing (Python)
2012-08-21T07:35:34-07:00Glenn Hutchingshttp://code.activestate.com/recipes/users/4175415/http://code.activestate.com/recipes/578245-flexible-datetime-parsing/
<p style="color: grey">
Python
recipe 578245
by <a href="/recipes/users/4175415/">Glenn Hutchings</a>
(<a href="/recipes/tags/datetime/">datetime</a>, <a href="/recipes/tags/parsing/">parsing</a>).
</p>
<p>The strptime() method of datetime accepts a format string that you have to specify in advance. What if you want to be more flexible in the kinds of date your program accepts? Here's a recipe for a function that tries many different formats until it finds one that works.</p>
Ghoster - Windows program to create 0kb clone of folder or drive (Python)
2012-09-02T13:30:29-07:00commentator8http://code.activestate.com/recipes/users/4182761/http://code.activestate.com/recipes/578251-ghoster-windows-program-to-create-0kb-clone-of-fol/
<p style="color: grey">
Python
recipe 578251
by <a href="/recipes/users/4182761/">commentator8</a>
(<a href="/recipes/tags/clone/">clone</a>, <a href="/recipes/tags/copy/">copy</a>, <a href="/recipes/tags/directory/">directory</a>, <a href="/recipes/tags/windows/">windows</a>).
</p>
<p>A program that will create a "ghost" of a given directory or drive on windows systems
(easily adaptable to unix etc) to a given destination. This will consist of a copy of all folders and files with only names and extensions retained, not size.
This allows browsing of a remote drive or network location when offline.</p>
Function that supports dividing timedelta by float (Python)
2012-05-17T13:47:07-07:00Ben Hoythttp://code.activestate.com/recipes/users/4170919/http://code.activestate.com/recipes/578136-function-that-supports-dividing-timedelta-by-float/
<p style="color: grey">
Python
recipe 578136
by <a href="/recipes/users/4170919/">Ben Hoyt</a>
(<a href="/recipes/tags/datetime/">datetime</a>, <a href="/recipes/tags/division/">division</a>, <a href="/recipes/tags/float/">float</a>).
</p>
<p>Python 2.x doesn't support dividing a timedelta by a float (only works with int). This function adds support for that.</p>
Human readable format for a given time delta (Python)
2012-04-26T10:37:10-07:00Thomas Lehmannhttp://code.activestate.com/recipes/users/4174477/http://code.activestate.com/recipes/578113-human-readable-format-for-a-given-time-delta/
<p style="color: grey">
Python
recipe 578113
by <a href="/recipes/users/4174477/">Thomas Lehmann</a>
(<a href="/recipes/tags/back/">back</a>, <a href="/recipes/tags/date/">date</a>, <a href="/recipes/tags/human/">human</a>, <a href="/recipes/tags/readable/">readable</a>, <a href="/recipes/tags/time/">time</a>).
</p>
<p><strong>What is it about?</strong></p>
<ul>
<li>I need to say someting like <em>1 day ago</em>, <em>5 days ago</em>, <em>2 weeks ago</em>, ...</li>
<li>I can control to have it with/without milliseconds and microseconds.</li>
<li>I can use it automatically with current date and time or with a provide one.</li>
</ul>
<p><strong>Why?</strong></p>
<ul>
<li>I need it for next revision of my <a href="http://code.activestate.com/recipes/578111/">recipe 578111</a>.</li>
<li>I found recipes here and there but often it is always assumed that a month has 30 days and that a year has 365 days; this is not true. That's why I've left away months and years.</li>
</ul>
KYSU (Keep Your Stuff Updated) (Python)
2012-07-29T01:12:01-07:00Gamoholichttp://code.activestate.com/recipes/users/4182585/http://code.activestate.com/recipes/578174-kysu-keep-your-stuff-updated/
<p style="color: grey">
Python
recipe 578174
by <a href="/recipes/users/4182585/">Gamoholic</a>
(<a href="/recipes/tags/automatic/">automatic</a>, <a href="/recipes/tags/exe/">exe</a>, <a href="/recipes/tags/installer/">installer</a>, <a href="/recipes/tags/updated/">updated</a>, <a href="/recipes/tags/updater/">updater</a>).
Revision 5.
</p>
<p>I wrote this program to keep my Samba share up to date. The Samba share contains installers for the programs that I use to fix and update computers (ccleaner, mbam, java, .etc). It can also be used for ISO's such as clonezilla.</p>
<p>For the latest version of the script and the accompanying files please go to GitHub.</p>
<p><a href="https://github.com/Gamoholic/KYSU" rel="nofollow">https://github.com/Gamoholic/KYSU</a></p>
<p>!!! Important! The only OS I have tested this on is Ubuntu. I will test Windows soon. If it doesn't work on any other OS please let me know! Also, I have no idea how well this works with Python 3. I may test that eventually.</p>
subtract or add a month to a datetime.date or datetime.datetime (Python)
2010-06-25T18:41:19-07:00Trent Mickhttp://code.activestate.com/recipes/users/4173505/http://code.activestate.com/recipes/577274-subtract-or-add-a-month-to-a-datetimedate-or-datet/
<p style="color: grey">
Python
recipe 577274
by <a href="/recipes/users/4173505/">Trent Mick</a>
(<a href="/recipes/tags/date/">date</a>, <a href="/recipes/tags/datetime/">datetime</a>, <a href="/recipes/tags/month/">month</a>).
</p>
<p>Adding or subtracting a month to a Python <code>datetime.date</code> or <code>datetime.datetime</code> is a little bit of a pain. Here is the code I use for that. These functions return the same datetime type as given. They preserve time of day data (if that is at all important to you).</p>
<p>See also: </p>
<ul>
<li><a href="http://code.activestate.com/recipes/476197/">Recipe 476197</a>: First / Last Day of the Month.</li>
<li><a href="http://packages.python.org/MonthDelta/">monthdelta module</a></li>
</ul>
Learning to calculate (mental arithmetic) (Python)
2012-05-11T03:49:48-07:00Thomas Lehmannhttp://code.activestate.com/recipes/users/4174477/http://code.activestate.com/recipes/578111-learning-to-calculate-mental-arithmetic/
<p style="color: grey">
Python
recipe 578111
by <a href="/recipes/users/4174477/">Thomas Lehmann</a>
(<a href="/recipes/tags/learning/">learning</a>, <a href="/recipes/tags/math/">math</a>, <a href="/recipes/tags/persistence/">persistence</a>, <a href="/recipes/tags/statistic/">statistic</a>, <a href="/recipes/tags/training/">training</a>).
Revision 4.
</p>
<p><strong>What is it about?</strong></p>
<ul>
<li>Learning to use the basic math operation (+, -, *,/).</li>
<li>Print out of statistics to show you where you are.</li>
<li>Being able to define your own training sessions.</li>
<li>Sessions with number of tasks or with a time limit.</li>
</ul>
<p><strong>What has changed?</strong></p>
<ul>
<li>Revision 2: Contains now the <strong>tasks numbering</strong>.</li>
<li>Revision 2: You can see overall how long you didn't a training.</li>
<li>Revision 2: You also can see per kind of session how long you didn't a training.</li>
<li>Revision 3: <strong>Trainings parameter as kind of policy</strong> in a separate class also used as key for statistic.</li>
<li>Revision 3: <strong>New session type</strong>: timeout (as many tasks as possible until timeout exceeded)</li>
<li>Revision 3: I'm also sorry to say that this revision breaks compatibility with previously stored sessions.</li>
<li>Revision 4: <strong>Integer division</strong> supported.</li>
</ul>
make some file named year+month+day (Python)
2012-02-10T23:46:36-08:00ryotaro gotohttp://code.activestate.com/recipes/users/4180840/http://code.activestate.com/recipes/578036-make-some-file-named-yearmonthday/
<p style="color: grey">
Python
recipe 578036
by <a href="/recipes/users/4180840/">ryotaro goto</a>
(<a href="/recipes/tags/beginner/">beginner</a>, <a href="/recipes/tags/date/">date</a>, <a href="/recipes/tags/file/">file</a>, <a href="/recipes/tags/sys/">sys</a>).
Revision 6.
</p>
<p>This program make some file named year+month+day
How to use "python program argument
example:argument=01,02,...,12
If you input 02,it will return files named
20120201,...,20120228</p>
XML To Python object(next generation) with real life example: fetching US Treasure Curve (Python)
2012-02-14T01:24:28-08:00Boris Katshttp://code.activestate.com/recipes/users/4180778/http://code.activestate.com/recipes/578032-xml-to-python-objectnext-generation-with-real-life/
<p style="color: grey">
Python
recipe 578032
by <a href="/recipes/users/4180778/">Boris Kats</a>
(<a href="/recipes/tags/object/">object</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/xml/">xml</a>).
Revision 11.
</p>
<p>This middle sized python class will populate himself from any xml with reasonable restrictions.</p>
objectsignature - debugging utility, will work with containers, classes, nested classes ... almost anything (Python)
2012-02-15T23:05:44-08:00Boris Katshttp://code.activestate.com/recipes/users/4180778/http://code.activestate.com/recipes/578039-objectsignature-debugging-utility-will-work-with-c/
<p style="color: grey">
Python
recipe 578039
by <a href="/recipes/users/4180778/">Boris Kats</a>
(<a href="/recipes/tags/debugging/">debugging</a>, <a href="/recipes/tags/objectsignature/">objectsignature</a>, <a href="/recipes/tags/objectview/">objectview</a>).
Revision 3.
</p>
<p>Small debug utility will help to detect unwonted changes of user's class during program execution.</p>