summaryrefslogtreecommitdiffstats
path: root/abs/mv-core/hobbitmon/hobbitstorage.py
blob: e79f8d1ff19fffef38506431e1ef75d4b4ac7081 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/usr/bin/python
# import MySQL module

import MySQLdb
import sys
import getopt
import socket
import os
import time
import string

def LIVETV():
    grandtotal=0
    global rectv_total
    global rectv_time
    global livetv_total
    global livetv_time
    # create a cursor
    cursor = db.cursor()
    # execute SQL statement

    cursor.execute("SELECT unix_timestamp(starttime),unix_timestamp(endtime),title FROM recorded where recgroup=(%s) ORDER by starttime;" , ("livetv"))
    result = cursor.fetchall()

    for row in result:
      #  print row[0], row[1] ,row [2]
        start=row[0]
        end=row[1]
        if ( end  > start ):
            total = (end - start) /60
            grandtotal+=total
    hours = grandtotal / 60.0
    days = hours / 24.0

    livetv_total=len(result)
    livetv_time=hours



def RECORDTV():
    grandtotal=0
    global rectv_total
    global rectv_time
    global livetv_total
    global livetv_time
    # create a cursor
    cursor = db.cursor()
    # execute SQL statement

    cursor.execute("SELECT unix_timestamp(starttime),unix_timestamp(endtime),title FROM recorded where not recgroup=(%s) ORDER by starttime;" , ("livetv"))
    result = cursor.fetchall()

    for row in result:
      #  print row[0], row[1] ,row [2]
        start=row[0]
        end=row[1]
        if ( end  > start ):
            total = (end - start) /60
            grandtotal+=total
    hours = grandtotal / 60.0
    days = hours / 24.0

    rectv_total=len(result)
    rectv_time=hours



def printvars():
    print rectv_time
    print rectv_total
    print livetv_time
    print livetv_total

def sendTObb():
    DATE = time.strftime("%a %b %d %H:%M:%S %Z %Y", time.localtime(time.time()))
    if os.environ['BB']:
        #print os.environ['BB']
        BB=os.environ['BB']
    if os.environ['BBDISP']:
        #print os.environ['BBDISP']
        BBDISP=os.environ['BBDISP']
    if os.environ['MACHINE']:
       # print os.environ['MACHINE']
        MACHINE=os.environ['MACHINE']

  #  MACHINE = socket.gethostname()
  #  MACHINE = string.replace(MACHINE, '.', ',')
    INFOLINE= "\n rectv_total:" + str(rectv_total)
    INFOLINE= INFOLINE + "\n rectv_time:" + str(rectv_time)
    INFOLINE= INFOLINE + "\n livetv_total:" + str(livetv_total)
    INFOLINE= INFOLINE + "\n livetv_time:" + str(livetv_time)
    INFOLINE= INFOLINE + "\n "



    LINE = "status " + MACHINE + ".storage green" + " " + DATE + " " + INFOLINE

    cmd = BB + ' ' + BBDISP + ' "' + LINE + '"'
    os.system(cmd)
    #print LINE

def main(argv):
    global db
    global rectv_total
    global rectv_time
    global livetv_total
    global livetv_time

    rectv_total=0
    rectv_time=0
    livetv_total=0
    livetv_time=0

    db = MySQLdb.connect(host="localhost", user="mythtv", passwd="mythtv", db="mythconverg")

    LIVETV()
    RECORDTV()
    #printvars()
    sendTObb()
if __name__ == "__main__":
    main(sys.argv[1:])