-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgetLiveReportTotals.py
88 lines (74 loc) · 3 KB
/
getLiveReportTotals.py
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
from KalturaClient import *
from KalturaClient.Plugins.Core import *
from KalturaClient.Plugins.Schedule import *
from KalturaClient.exceptions import KalturaException
from csv import reader
import os
# Populate these with appropriate values
PARTNER_ID = "xxxxxx"
ADMIN_SECRET = "xxxxxx"
USER_ID = "test@user.com"
FROM_DATE = 1619409600
TO_DATE = 1619755200
INPUT_FILE = "xxxxxx/liveEntries.csv"
OUTPUT_DIR = "xxxxxx/Totals/"
# Input file liveEntries.csv is just a text file with entries listed such as (without the "#" at start of each line):
#1_lilipe19
#1_6adpzy86
#1_xqr5u4ws
reportTypeDict = {
KalturaReportType.HIGHLIGHTS_WEBCAST: 'highlights.csv', # 40001
KalturaReportType.ENGAGEMENT_WEBCAST: 'engagement.csv', # 40002
KalturaReportType.QUALITY_WEBCAST: 'quality.csv', # 40003
KalturaReportType.ENGAGEMENT_BREAKDOWN_WEBCAST: 'engagementBreakdown.csv' # 40010
}
# Create the output directory if it does not exist
if not os.path.exists(OUTPUT_DIR):
os.makedirs(OUTPUT_DIR)
# Get a KalturaClient
config = KalturaConfiguration(PARTNER_ID)
config.serviceUrl = "https://www.kaltura.com/"
client = KalturaClient(config)
ks = client.session.start(
ADMIN_SECRET,
USER_ID,
KalturaSessionType.ADMIN,
PARTNER_ID,
86400, # expiry
"disableentitlement") # privileges
client.setKs(ks)
# open file in read mode
with open(INPUT_FILE, 'r') as readObj:
# Iterate over each report type
for reportType in reportTypeDict:
# Create a new output file
outputFile = open(OUTPUT_DIR + reportTypeDict[reportType], 'w')
entryCount = 0
print("Generating report: " + reportTypeDict[reportType] + " ...")
# pass the file object to reader() to get the reader object
readObj.seek(0) # offset to first line
csvReader = reader(readObj)
# Iterate over each row in the csv using reader object
for row in csvReader:
# row variable is a list that represents a row in csv
sessionName = row[0]
entryId = row[1]
try:
reportInputFilter = KalturaReportInputFilter()
reportInputFilter.entryIdIn = entryId
reportInputFilter.fromDate = FROM_DATE
reportInputFilter.toDate = TO_DATE
pager = KalturaFilterPager()
objectIds = ""
responseOptions = KalturaReportResponseOptions()
result = client.report.getTotal(reportType, reportInputFilter, objectIds, responseOptions)
data = result.data
# Only print header once
if entryCount == 0:
print("SessionCode,EntryID," + result.header, file = outputFile)
print("%s,%s,%s" % (sessionName, entryId, data), file = outputFile)
entryCount += 1
except KalturaException as e:
print("Exception: %s", e.message)
# close output file
outputFile.close()