author | rougeronj |
Thu, 16 Apr 2015 12:15:33 +0200 | |
changeset 153 | 60bd2b36b9dc |
parent 66 | 658561ea9e65 |
permissions | -rw-r--r-- |
24
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
1 |
#!/usr/bin/env python |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
2 |
# coding=utf-8 |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
3 |
|
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
4 |
import argparse |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
5 |
import datetime |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
6 |
import sys |
26
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
7 |
import logging |
24
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
8 |
|
66
658561ea9e65
export sync code in utils, and add button to synchronize annotation on eventsessionview
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
9 |
from lxml import etree |
24
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
10 |
|
66
658561ea9e65
export sync code in utils, and add button to synchronize annotation on eventsessionview
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
11 |
import utils |
30
c2294ac6e875
correct timezone support for sync script
ymh <ymh.work@gmail.com>
parents:
26
diff
changeset
|
12 |
|
26
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
13 |
def get_logger(): |
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
14 |
return logging.getLogger(__name__) |
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
15 |
|
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
16 |
def set_logging(options, plogger=None, queue=None): |
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
17 |
|
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
18 |
logging_config = { |
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
19 |
"format" : '%(asctime)s %(levelname)s:%(name)s:%(message)s', |
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
20 |
"level" : max(logging.NOTSET, min(logging.CRITICAL, logging.WARNING - 10 * options.verbose + 10 * options.quiet)), #@UndefinedVariable |
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
21 |
} |
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
22 |
|
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
23 |
if options.logfile == "stdout": |
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
24 |
logging_config["stream"] = sys.stdout |
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
25 |
elif options.logfile == "stderr": |
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
26 |
logging_config["stream"] = sys.stderr |
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
27 |
else: |
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
28 |
logging_config["filename"] = options.logfile |
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
29 |
|
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
30 |
logger = plogger |
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
31 |
if logger is None: |
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
32 |
logger = get_logger() #@UndefinedVariable |
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
33 |
|
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
34 |
if len(logger.handlers) == 0: |
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
35 |
filename = logging_config.get("filename") |
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
36 |
if queue is not None: |
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
37 |
hdlr = QueueHandler(queue, True) |
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
38 |
elif filename: |
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
39 |
mode = logging_config.get("filemode", 'a') |
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
40 |
hdlr = logging.FileHandler(filename, mode) #@UndefinedVariable |
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
41 |
else: |
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
42 |
stream = logging_config.get("stream") |
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
43 |
hdlr = logging.StreamHandler(stream) #@UndefinedVariable |
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
44 |
|
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
45 |
fs = logging_config.get("format", logging.BASIC_FORMAT) #@UndefinedVariable |
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
46 |
dfs = logging_config.get("datefmt", None) |
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
47 |
fmt = logging.Formatter(fs, dfs) #@UndefinedVariable |
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
48 |
hdlr.setFormatter(fmt) |
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
49 |
logger.addHandler(hdlr) |
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
50 |
level = logging_config.get("level") |
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
51 |
if level is not None: |
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
52 |
logger.setLevel(level) |
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
53 |
|
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
54 |
options.debug = (options.verbose-options.quiet > 0) |
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
55 |
return logger |
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
56 |
|
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
57 |
def set_logging_options(parser): |
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
58 |
parser.add_argument("-l", "--log", dest="logfile", |
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
59 |
help="log to file", metavar="LOG", default="stderr") |
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
60 |
parser.add_argument("-v", dest="verbose", action="count", |
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
61 |
help="verbose", default=0) |
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
62 |
parser.add_argument("-q", dest="quiet", action="count", |
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
63 |
help="quiet", default=0) |
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
64 |
|
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
65 |
|
24
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
66 |
def get_options(): |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
67 |
|
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
68 |
|
30
c2294ac6e875
correct timezone support for sync script
ymh <ymh.work@gmail.com>
parents:
26
diff
changeset
|
69 |
parser = argparse.ArgumentParser(description="All date should be given using iso8601 format. If no timezone is used, the date is considered as UTC") |
24
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
70 |
|
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
71 |
parser.add_argument("-f", "--file", dest="filename", |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
72 |
help="write export to file", metavar="FILE", default="project.ldt") |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
73 |
parser.add_argument("-a", "--annot-url", dest="annot_url", |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
74 |
help="annotation server url", metavar="ANNOT-URL", required=True) |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
75 |
parser.add_argument("-s", "--start-date", dest="start_date", |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
76 |
help="start date", metavar="START_DATE", default=None) |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
77 |
parser.add_argument("-e", "--end-date", dest="end_date", |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
78 |
help="end date", metavar="END_DATE", default=None) |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
79 |
parser.add_argument("-I", "--content-file", dest="content_file", |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
80 |
help="Content file", metavar="CONTENT_FILE") |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
81 |
parser.add_argument("-c", "--content", dest="content", |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
82 |
help="Content url", metavar="CONTENT") |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
83 |
parser.add_argument("-V", "--video-url", dest="video", |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
84 |
help="video url", metavar="VIDEO") |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
85 |
parser.add_argument("-i", "--content-id", dest="content_id", |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
86 |
help="Content id", metavar="CONTENT_ID") |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
87 |
parser.add_argument("-C", "--color", dest="color", |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
88 |
help="Color code", metavar="COLOR", default="16763904") |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
89 |
parser.add_argument("-H", "--channel", dest="channels", |
66
658561ea9e65
export sync code in utils, and add button to synchronize annotation on eventsessionview
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
90 |
help="Channel", metavar="CHANNEL", default=[utils.AnnotationsSynchronizer.DEFAULT_ANNOTATION_CHANNEL], action="append") |
24
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
91 |
parser.add_argument("-E", "--event", dest="events", |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
92 |
help="Event", metavar="EVENT", default=[], action="append") |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
93 |
parser.add_argument("-D", "--duration", dest="duration", type=int, |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
94 |
help="Duration", metavar="DURATION", default=None) |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
95 |
parser.add_argument("-n", "--name", dest="name", |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
96 |
help="Cutting name", metavar="NAME", default=u"annotations") |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
97 |
parser.add_argument("-R", "--replace", dest="replace", action="store_true", |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
98 |
help="Replace annotation ensemble", default=False) |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
99 |
parser.add_argument("-m", "--merge", dest="merge", action="store_true", |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
100 |
help="merge annotation ensemble, choose the first ensemble", default=False) |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
101 |
parser.add_argument("-L", "--list-conf", dest="listconf", |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
102 |
help="list of file to process", metavar="LIST_CONF", default=None) |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
103 |
parser.add_argument("-b", "--base-url", dest="base_url", |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
104 |
help="base URL of the platform", metavar="BASE_URL", default="http://ldt.iri.centrepompidou.fr/ldtplatform/") |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
105 |
parser.add_argument("-p", "--project", dest="project_id", |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
106 |
help="Project id", metavar="PROJECT_ID", default=None) |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
107 |
parser.add_argument("-P", "--post-param", dest="post_param", |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
108 |
help="Post param", metavar="POST_PARAM", default=None) |
26
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
109 |
parser.add_argument("-B", "--batch-size", dest="batch_size", type=int, |
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
110 |
help="Batch size for annotation request", metavar="BATCH_SIZE", default=500) |
24
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
111 |
parser.add_argument("--user-whitelist", dest="user_whitelist", action="store", |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
112 |
help="A list of user screen name", metavar="USER_WHITELIST",default=None) |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
113 |
parser.add_argument("--cut", dest="cuts", action="append", |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
114 |
help="A cut with the forma <ts in ms>::<duration>", metavar="CUT", default=[]) |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
115 |
|
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
116 |
set_logging_options(parser) |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
117 |
|
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
118 |
return (parser.parse_args(), parser) |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
119 |
|
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
120 |
|
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
121 |
def parse_duration(s): |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
122 |
try: |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
123 |
return int(s) |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
124 |
except ValueError: |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
125 |
parts = s.split(":") |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
126 |
if len(parts) < 2: |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
127 |
raise ValueError("Bad duration format") |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
128 |
time_params = { |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
129 |
'hours': int(parts[0]), |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
130 |
'minutes': int(parts[1]), |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
131 |
'seconds': int(parts[2]) if len(parts)>2 else 0 |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
132 |
} |
30
c2294ac6e875
correct timezone support for sync script
ymh <ymh.work@gmail.com>
parents:
26
diff
changeset
|
133 |
return int(round(datetime.timedelta(**time_params).total_seconds()*1000)) |
24
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
134 |
|
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
135 |
|
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
136 |
if __name__ == "__main__" : |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
137 |
|
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
138 |
(options, parser) = get_options() |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
139 |
|
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
140 |
set_logging(options) |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
141 |
|
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
142 |
get_logger().debug("OPTIONS : " + repr(options)) #@UndefinedVariable |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
143 |
|
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
144 |
|
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
145 |
deltas = [(0,0)] |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
146 |
total_delta = 0 |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
147 |
if options.cuts: |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
148 |
cuts_raw = sorted([tuple([parse_duration(s) for s in c.split("::")]) for c in options.cuts]) |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
149 |
for c, d in cuts_raw: |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
150 |
deltas.append((c+total_delta, -1)) |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
151 |
total_delta += d |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
152 |
deltas.append((c+total_delta, total_delta)) |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
153 |
|
26
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
154 |
if len(sys.argv) == 1 or options.annot_url is None: |
24
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
155 |
parser.print_help() |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
156 |
sys.exit(1) |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
157 |
|
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
158 |
if options.listconf: |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
159 |
|
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
160 |
parameters = [] |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
161 |
confdoc = etree.parse(options.listconf) |
26
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
162 |
for node in confdoc.xpath("/annotation_export/file"): |
24
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
163 |
params = {} |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
164 |
for snode in node: |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
165 |
if snode.tag == "path": |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
166 |
params['content_file'] = snode.text |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
167 |
params['content_file_write'] = snode.text |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
168 |
elif snode.tag == "project_id": |
66
658561ea9e65
export sync code in utils, and add button to synchronize annotation on eventsessionview
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
169 |
params['content_file'] = options.base_url + utils.AnnotationsSynchronizer.LDT_PROJECT_REST_API_PATH + snode.text + "/?format=json" |
658561ea9e65
export sync code in utils, and add button to synchronize annotation on eventsessionview
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
170 |
params['content_file_write'] = options.base_url + utils.AnnotationsSynchronizer.LDT_PROJECT_REST_API_PATH + snode.text + "/?format=json" |
24
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
171 |
params['project_id'] = snode.text |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
172 |
elif snode.tag == "start_date": |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
173 |
params['start_date'] = snode.text |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
174 |
elif snode.tag == "end_date": |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
175 |
params['end_date'] = snode.text |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
176 |
elif snode.tag == "duration": |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
177 |
params['duration'] = int(snode.text) |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
178 |
elif snode.tag == "events": |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
179 |
params['events'] = [snode.text] |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
180 |
elif snode.tag == "channels": |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
181 |
params['channels'] = [snode.text] |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
182 |
if options.events or 'events' not in params : |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
183 |
params['events'] = options.events |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
184 |
if options.channels or 'channels' not in params : |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
185 |
params['channels'] = options.channels |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
186 |
|
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
187 |
parameters.append(params) |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
188 |
else: |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
189 |
if options.project_id: |
66
658561ea9e65
export sync code in utils, and add button to synchronize annotation on eventsessionview
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
190 |
content_file = options.base_url + utils.AnnotationsSynchronizer.LDT_PROJECT_REST_API_PATH + options.project_id + "/?format=json" |
24
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
191 |
else: |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
192 |
content_file = options.content_file |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
193 |
parameters = [{ |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
194 |
'start_date' : options.start_date, |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
195 |
'end_date' : options.end_date, |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
196 |
'duration' : options.duration, |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
197 |
'events' : options.events, |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
198 |
'channels' : options.channels, |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
199 |
'content_file' : content_file, |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
200 |
'content_file_write' : content_file, |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
201 |
'project_id' : options.project_id |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
202 |
}] |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
203 |
|
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
204 |
for params in parameters: |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
205 |
|
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
206 |
get_logger().debug("PARAMETERS " + repr(params)) #@UndefinedVariable |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
207 |
|
66
658561ea9e65
export sync code in utils, and add button to synchronize annotation on eventsessionview
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
208 |
sync_args = dict(vars(options)) |
658561ea9e65
export sync code in utils, and add button to synchronize annotation on eventsessionview
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
209 |
sync_args.pop('cuts') |
658561ea9e65
export sync code in utils, and add button to synchronize annotation on eventsessionview
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
210 |
sync_args.pop('verbose') |
658561ea9e65
export sync code in utils, and add button to synchronize annotation on eventsessionview
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
211 |
sync_args.pop('quiet') |
658561ea9e65
export sync code in utils, and add button to synchronize annotation on eventsessionview
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
212 |
sync_args.pop('debug') |
658561ea9e65
export sync code in utils, and add button to synchronize annotation on eventsessionview
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
213 |
sync_args.pop('listconf') |
658561ea9e65
export sync code in utils, and add button to synchronize annotation on eventsessionview
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
214 |
sync_args.pop('logfile') |
658561ea9e65
export sync code in utils, and add button to synchronize annotation on eventsessionview
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
215 |
sync_args['deltas'] = deltas |
658561ea9e65
export sync code in utils, and add button to synchronize annotation on eventsessionview
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
216 |
sync_args['logger'] = get_logger() |
658561ea9e65
export sync code in utils, and add button to synchronize annotation on eventsessionview
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
217 |
sync_args.update(params) |
24
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
218 |
|
66
658561ea9e65
export sync code in utils, and add button to synchronize annotation on eventsessionview
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
219 |
get_logger().debug("SYNC ARGS " + repr(sync_args)) |
24
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
220 |
|
66
658561ea9e65
export sync code in utils, and add button to synchronize annotation on eventsessionview
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
221 |
sync = utils.AnnotationsSynchronizer(**sync_args) |
658561ea9e65
export sync code in utils, and add button to synchronize annotation on eventsessionview
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
222 |
sync.export_annotations() |