Skip to content

Commit

Permalink
Zoom duration stuff. Includes:
Browse files Browse the repository at this point in the history
* use `pytimeparse` as fallback for meeting duration parsing
* calc a session duration value based on join/leave times
  • Loading branch information
lbjay committed Oct 26, 2017
1 parent 2f76e48 commit a9d9123
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
32 changes: 26 additions & 6 deletions harvest_cli/zoom.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import json
import time
import click
import arrow
import requests
from datetime import timedelta, datetime
from elasticsearch.helpers import bulk as index_bulk
Expand Down Expand Up @@ -273,6 +274,17 @@ def create_meeting_document(meeting, topic, host_id):

def create_sessions_document(session, meeting_uuid):

try:
j = arrow.get(session['join_time'])
l = arrow.get(session['leave_time'])
duration = (l - j).seconds
except Exception as e:
logger.warning(
"Failed duration calc for session '%s': %s",
session['id'], str(e)
)
duration = None

doc = {
"meeting": meeting_uuid,
"id": session['id'],
Expand All @@ -285,6 +297,7 @@ def create_sessions_document(session, meeting_uuid):
"network_type": session['network_type'],
"join_time": session['join_time'],
"leave_time": session['leave_time'],
"duration": duration,
"share_application": session['share_application'], # bool
"share_desktop": session['share_desktop'], # bool
"share_whiteboard": session['share_whiteboard'], # bool
Expand All @@ -297,12 +310,19 @@ def create_sessions_document(session, meeting_uuid):
# convert duration from MM:SS or HH:MM:SS to seconds
def to_seconds(duration):
try:
dt = datetime.strptime(duration, "%H:%M:%S")
except ValueError:
dt = datetime.strptime(duration, "%M:%S")
delta = timedelta(hours=dt.hour, minutes=dt.minute, seconds=dt.second)

return int(delta.total_seconds())
try:
dt = datetime.strptime(duration, "%H:%M:%S")
except ValueError:
dt = datetime.strptime(duration, "%M:%S")
delta = timedelta(hours=dt.hour, minutes=dt.minute, seconds=dt.second)

return int(delta.total_seconds())
except ValueError:
import pytimeparse
logger.warning("Duration parsing failed on input '%s'; falling back to pytimeparse. ", duration)
duration = pytimeparse.parse(duration)
if duration is None:
logger.warning("Even the mighty pytimeparse failed!")
return duration


1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ python-dotenv==0.7.1
requests[security]==2.8.1
redis==2.10.6
maxminddb==1.3.0
pytimeparse==1.1.7

# Elasticsearch 2.x
elasticsearch>=2,<3
Expand Down

0 comments on commit a9d9123

Please sign in to comment.