room-numbers.py 1.47 KB
Newer Older
1
# standard library imports
2
from __future__ import absolute_import, print_function
Daniel W Bond's avatar
Daniel W Bond committed
3
4
5
6
import string
import random
import re

Daniel W Bond's avatar
Daniel W Bond committed
7

Daniel W Bond's avatar
Daniel W Bond committed
8
9
10
11
# from stackoverflow https://stackoverflow.com/questions/2257441/
def slug_generator(size=6, chars=string.ascii_letters + string.digits):
    return ''.join(random.choice(chars) for _ in range(size))

Daniel W Bond's avatar
Daniel W Bond committed
12

Daniel W Bond's avatar
Daniel W Bond committed
13
14
15
16
17
# regex to separate out building names and room numbers
def building_or_room(line):

    return False

Daniel W Bond's avatar
Daniel W Bond committed
18

Daniel W Bond's avatar
Daniel W Bond committed
19
20
21
22
23
def get_floor_num(line):
    return line[0]

roomNumbers = open('room-numbers', 'r')

24
print("[{")
Daniel W Bond's avatar
Daniel W Bond committed
25
26
# for line in file

27
pk = 1
28
curFloor = 0
29
curFloorInBuilding = 1
Daniel W Bond's avatar
Daniel W Bond committed
30

31
for line in roomNumbers:
32
    line = line.rstrip('\n')
Daniel W Bond's avatar
Daniel W Bond committed
33
    if re.match('[a-zA-Z]', line):
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
        curFloor += 1
        curFloorInBuilding = 1
    else:
        if int(float(get_floor_num(line))) > curFloorInBuilding:
            curFloor += 1
            curFloorInBuilding += 1
        print("}, {\"fields\": {")
        print("    \"floor\": " + str(curFloor) + ",")
        print("    \"number\": " + str(line) + ",")
        print("    \"room_num\": \"" + str(line) + "\",")
        print("    \"slug\": \"" + slug_generator() + "\"")
        print("  },")
        print("  \"model\":\"housing.room\",")
        print("  \"pk\":" + str(pk))
        pk = pk + 1
print("}]")
Daniel W Bond's avatar
Daniel W Bond committed
50
51
52

"""
  "fields": {
53
54
55
56
57
58
    "floor": 1,
    "created": "2015-04-09T19:56:59.594Z",
    "number": 101,
    "modified": "2015-04-09T19:56:59.598Z",
    "room_num": "101",
    "slug": "G4xTdX"
Daniel W Bond's avatar
Daniel W Bond committed
59
  },
60
61
62
  "model": "housing.room",
  "pk": 1
}, {
Daniel W Bond's avatar
Daniel W Bond committed
63
"""