143e083dab8493df1472960cbc980e43753768ba
[swc-testing-nose.git] / Python / MakeAnimals.ipynb
1 {
2  "metadata": {
3   "name": "MakeAnimals"
4  }, 
5  "nbformat": 2, 
6  "worksheets": [
7   {
8    "cells": [
9     {
10      "cell_type": "code", 
11      "collapsed": true, 
12      "input": [
13       "animals = ('Moose', 'Elk', 'Fox', 'Owl', 'Wolf', 'Muskox', 'Ptarmigan', 'Grizzly', 'Wolverine')"
14      ], 
15      "language": "python", 
16      "outputs": [], 
17      "prompt_number": 14
18     }, 
19     {
20      "cell_type": "code", 
21      "collapsed": true, 
22      "input": [
23       "import datetime as dt", 
24       "import random"
25      ], 
26      "language": "python", 
27      "outputs": [], 
28      "prompt_number": 15
29     }, 
30     {
31      "cell_type": "code", 
32      "collapsed": false, 
33      "input": [
34       "def make_animals(filename, lines=100):", 
35       "    date = dt.date(2011, 4, 22)", 
36       "    one_day = dt.timedelta(days=1)", 
37       "", 
38       "    f = open(filename, 'w')", 
39       "", 
40       "    for _ in xrange(lines):", 
41       "        animal = random.choice(animals)", 
42       "        hour = random.randint(0, 23)", 
43       "        minute = random.randint(0, 59)", 
44       "        number = random.randint(1, 42)", 
45       "    ", 
46       "        date_str = '{}-{:02d}-{:02d}'.format(date.year, date.month, date.day)", 
47       "    ", 
48       "        time_str = '{:02d}:{:02d}'.format(hour, minute)", 
49       "    ", 
50       "        line = '{} {} {} {}\\n'.format(date_str, time_str, animal, number)", 
51       "    ", 
52       "        f.write(line)", 
53       "    ", 
54       "        if random.choice((True, False)):", 
55       "            date = date + one_day", 
56       "    ", 
57       "    f.close()"
58      ], 
59      "language": "python", 
60      "outputs": [], 
61      "prompt_number": 22
62     }, 
63     {
64      "cell_type": "code", 
65      "collapsed": true, 
66      "input": [
67       "make_animals('animals.txt', 5)"
68      ], 
69      "language": "python", 
70      "outputs": [], 
71      "prompt_number": 24
72     }, 
73     {
74      "cell_type": "code", 
75      "collapsed": true, 
76      "input": [
77       "make_animals('big_animals.txt')"
78      ], 
79      "language": "python", 
80      "outputs": [], 
81      "prompt_number": 23
82     }, 
83     {
84      "cell_type": "code", 
85      "collapsed": true, 
86      "input": [
87       "make_animals('merida_animals.txt')"
88      ], 
89      "language": "python", 
90      "outputs": [], 
91      "prompt_number": 25
92     }, 
93     {
94      "cell_type": "code", 
95      "collapsed": true, 
96      "input": [
97       "make_animals('fergus_animals.txt')"
98      ], 
99      "language": "python", 
100      "outputs": [], 
101      "prompt_number": 26
102     }, 
103     {
104      "cell_type": "code", 
105      "collapsed": true, 
106      "input": [
107       "make_animals('macguffin_animals.txt')"
108      ], 
109      "language": "python", 
110      "outputs": [], 
111      "prompt_number": 27
112     }, 
113     {
114      "cell_type": "code", 
115      "collapsed": true, 
116      "input": [
117       "make_animals('dingwall_animals.txt')"
118      ], 
119      "language": "python", 
120      "outputs": [], 
121      "prompt_number": 28
122     }, 
123     {
124      "cell_type": "code", 
125      "collapsed": true, 
126      "input": [], 
127      "language": "python", 
128      "outputs": []
129     }
130    ]
131   }
132  ]
133 }