author | ymh <ymh.work@gmail.com> |
Thu, 16 Oct 2014 03:22:00 +0200 | |
changeset 26 | ebfd0d3cffab |
parent 24 | eb1f7b06001f |
child 30 | c2294ac6e875 |
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 |
from lxml import etree |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
5 |
import argparse |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
6 |
import json |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
7 |
import datetime |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
8 |
import requests |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
9 |
import os.path |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
10 |
import re |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
11 |
import sys |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
12 |
import time |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
13 |
import uuid #@UnresolvedImport |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
14 |
from dateutil.parser import parse as parse_date |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
15 |
import bisect |
26
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
16 |
import logging |
24
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
17 |
|
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
18 |
#class TweetExclude(object): |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
19 |
# def __init__(self, id): |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
20 |
# self.id = id |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
21 |
# |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
22 |
# def __repr__(self): |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
23 |
# return "<TweetExclude(id=%d)>" % (self.id) |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
24 |
|
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
25 |
LDT_CONTENT_REST_API_PATH = "api/ldt/1.0/contents/" |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
26 |
LDT_PROJECT_REST_API_PATH = "api/ldt/1.0/projects/" |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
27 |
DEFAULT_ANNOTATION_CHANNEL = 'ANNOT' |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
28 |
|
26
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
29 |
def get_logger(): |
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
30 |
return logging.getLogger(__name__) |
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
31 |
|
24
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
32 |
|
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
33 |
def get_filter(start_date, end_date, events, channels, user_whitelist): |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
34 |
res = [] |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
35 |
#TODO: check timezone... |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
36 |
if start_date: |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
37 |
res.append({'name': 'ts', 'op': ">=", 'val':start_date.isoformat() }) |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
38 |
if end_date: |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
39 |
res.append({'name': 'ts', 'op': "<=", 'val':end_date.isoformat() }) |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
40 |
if events: |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
41 |
res.append({'name': 'event', 'op': "in", 'val':events }) |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
42 |
if channels: |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
43 |
res.append({'name': 'channel', 'op': "in", 'val':channels }) |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
44 |
if user_whitelist: |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
45 |
res.append({'name': 'user', 'op': "in", 'val':user_whitelist }) |
26
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
46 |
return res |
24
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
47 |
|
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
48 |
# def parse_polemics(tw, extended_mode): |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
49 |
# """ |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
50 |
# parse polemics in text and return a list of polemic code. None if not polemic found |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
51 |
# """ |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
52 |
# polemics = {} |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
53 |
# for m in re.finditer("(\+\+|\-\-|\?\?|\=\=)",tw.text): |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
54 |
# pol_link = { |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
55 |
# '++' : u'OK', |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
56 |
# '--' : u'KO', |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
57 |
# '??' : u'Q', |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
58 |
# '==' : u'REF'}[m.group(1)] |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
59 |
# polemics[pol_link] = pol_link |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
60 |
# |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
61 |
# if extended_mode: |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
62 |
# if "?" in tw.text: |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
63 |
# polemics["Q"] = "Q" |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
64 |
# |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
65 |
# for entity in tw.entity_list: |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
66 |
# if entity.type == "entity_url": |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
67 |
# polemics["REF"] = "REF" |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
68 |
# |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
69 |
# if len(polemics) > 0: |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
70 |
# return polemics.keys() |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
71 |
# else: |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
72 |
# return None |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
73 |
|
26
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
74 |
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
|
75 |
|
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
76 |
logging_config = { |
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
77 |
"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
|
78 |
"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
|
79 |
} |
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
80 |
|
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
81 |
if options.logfile == "stdout": |
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
82 |
logging_config["stream"] = sys.stdout |
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
83 |
elif options.logfile == "stderr": |
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
84 |
logging_config["stream"] = sys.stderr |
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
85 |
else: |
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
86 |
logging_config["filename"] = options.logfile |
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
87 |
|
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
88 |
logger = plogger |
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
89 |
if logger is None: |
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
90 |
logger = get_logger() #@UndefinedVariable |
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
91 |
|
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
92 |
if len(logger.handlers) == 0: |
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
93 |
filename = logging_config.get("filename") |
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
94 |
if queue is not None: |
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
95 |
hdlr = QueueHandler(queue, True) |
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
96 |
elif filename: |
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
97 |
mode = logging_config.get("filemode", 'a') |
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
98 |
hdlr = logging.FileHandler(filename, mode) #@UndefinedVariable |
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
99 |
else: |
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
100 |
stream = logging_config.get("stream") |
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
101 |
hdlr = logging.StreamHandler(stream) #@UndefinedVariable |
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
102 |
|
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
103 |
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
|
104 |
dfs = logging_config.get("datefmt", None) |
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
105 |
fmt = logging.Formatter(fs, dfs) #@UndefinedVariable |
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
106 |
hdlr.setFormatter(fmt) |
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
107 |
logger.addHandler(hdlr) |
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
108 |
level = logging_config.get("level") |
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
109 |
if level is not None: |
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
110 |
logger.setLevel(level) |
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
111 |
|
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
112 |
options.debug = (options.verbose-options.quiet > 0) |
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
113 |
return logger |
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
114 |
|
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
115 |
def set_logging_options(parser): |
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
116 |
parser.add_argument("-l", "--log", dest="logfile", |
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
117 |
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
|
118 |
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
|
119 |
help="verbose", default=0) |
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
120 |
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
|
121 |
help="quiet", default=0) |
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
122 |
|
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
123 |
|
24
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
124 |
def get_options(): |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
125 |
|
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
126 |
usage = "usage: %(prog)s [options]" |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
127 |
|
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
128 |
parser = argparse.ArgumentParser(usage) |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
129 |
|
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
130 |
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
|
131 |
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
|
132 |
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
|
133 |
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
|
134 |
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
|
135 |
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
|
136 |
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
|
137 |
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
|
138 |
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
|
139 |
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
|
140 |
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
|
141 |
help="Content url", metavar="CONTENT") |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
142 |
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
|
143 |
help="video url", metavar="VIDEO") |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
144 |
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
|
145 |
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
|
146 |
parser.add_argument("-x", "--exclude", dest="exclude", |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
147 |
help="file containing the id to exclude", metavar="EXCLUDE") |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
148 |
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
|
149 |
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
|
150 |
parser.add_argument("-H", "--channel", dest="channels", |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
151 |
help="Channel", metavar="CHANNEL", default=[DEFAULT_ANNOTATION_CHANNEL], action="append") |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
152 |
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
|
153 |
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
|
154 |
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
|
155 |
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
|
156 |
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
|
157 |
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
|
158 |
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
|
159 |
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
|
160 |
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
|
161 |
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
|
162 |
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
|
163 |
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
|
164 |
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
|
165 |
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
|
166 |
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
|
167 |
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
|
168 |
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
|
169 |
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
|
170 |
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
|
171 |
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
|
172 |
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
|
173 |
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
|
174 |
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
|
175 |
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
|
176 |
|
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
177 |
set_logging_options(parser) |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
178 |
|
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
179 |
return (parser.parse_args(), parser) |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
180 |
|
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
181 |
|
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
182 |
def find_delta(deltas, ts): |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
183 |
i = bisect.bisect_right(deltas, (ts+1,0)) |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
184 |
if i: |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
185 |
return deltas[i-1] |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
186 |
return (0,0) |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
187 |
|
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
188 |
|
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
189 |
def parse_duration(s): |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
190 |
try: |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
191 |
return int(s) |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
192 |
except ValueError: |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
193 |
parts = s.split(":") |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
194 |
if len(parts) < 2: |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
195 |
raise ValueError("Bad duration format") |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
196 |
time_params = { |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
197 |
'hours': int(parts[0]), |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
198 |
'minutes': int(parts[1]), |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
199 |
'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
|
200 |
} |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
201 |
return int(datetime.timedelta(**time_params).total_seconds()*1000) |
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 |
def build_annotation_iterator(url, params, headers): |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
204 |
page = 0 |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
205 |
page_nb = 1 |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
206 |
while page < page_nb: |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
207 |
page += 1 |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
208 |
params['page'] = page |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
209 |
resp = requests.get(url, params=params, headers=headers) |
26
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
210 |
if resp.status_code != requests.codes.ok: |
24
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
211 |
return |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
212 |
resp_json = resp.json() |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
213 |
page_nb = resp_json.get('total_pages', 1) |
26
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
214 |
for item in resp_json.get('objects', []): |
24
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
215 |
#TODO: add progress log |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
216 |
yield item |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
217 |
|
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
218 |
|
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
219 |
if __name__ == "__main__" : |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
220 |
|
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
221 |
(options, parser) = get_options() |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
222 |
|
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
223 |
set_logging(options) |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
224 |
|
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
225 |
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
|
226 |
|
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
227 |
|
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
228 |
deltas = [(0,0)] |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
229 |
total_delta = 0 |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
230 |
if options.cuts: |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
231 |
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
|
232 |
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
|
233 |
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
|
234 |
total_delta += d |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
235 |
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
|
236 |
|
26
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
237 |
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
|
238 |
parser.print_help() |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
239 |
sys.exit(1) |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
240 |
|
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
241 |
user_whitelist_file = options.user_whitelist |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
242 |
user_whitelist = None |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
243 |
|
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
244 |
annotation_url = options.annot_url |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
245 |
|
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
246 |
if options.listconf: |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
247 |
|
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
248 |
parameters = [] |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
249 |
confdoc = etree.parse(options.listconf) |
26
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
250 |
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
|
251 |
params = {} |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
252 |
for snode in node: |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
253 |
if snode.tag == "path": |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
254 |
params['content_file'] = snode.text |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
255 |
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
|
256 |
elif snode.tag == "project_id": |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
257 |
params['content_file'] = options.base_url + LDT_PROJECT_REST_API_PATH + snode.text + "/?format=json" |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
258 |
params['content_file_write'] = options.base_url + LDT_PROJECT_REST_API_PATH + snode.text + "/?format=json" |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
259 |
params['project_id'] = snode.text |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
260 |
elif snode.tag == "start_date": |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
261 |
params['start_date'] = snode.text |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
262 |
elif snode.tag == "end_date": |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
263 |
params['end_date'] = snode.text |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
264 |
elif snode.tag == "duration": |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
265 |
params['duration'] = int(snode.text) |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
266 |
elif snode.tag == "events": |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
267 |
params['events'] = [snode.text] |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
268 |
elif snode.tag == "channels": |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
269 |
params['channels'] = [snode.text] |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
270 |
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
|
271 |
params['events'] = options.events |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
272 |
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
|
273 |
params['channels'] = options.channels |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
274 |
|
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
275 |
parameters.append(params) |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
276 |
else: |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
277 |
if options.project_id: |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
278 |
content_file = options.base_url + LDT_PROJECT_REST_API_PATH + options.project_id + "/?format=json" |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
279 |
else: |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
280 |
content_file = options.content_file |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
281 |
parameters = [{ |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
282 |
'start_date' : options.start_date, |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
283 |
'end_date' : options.end_date, |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
284 |
'duration' : options.duration, |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
285 |
'events' : options.events, |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
286 |
'channels' : options.channels, |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
287 |
'content_file' : content_file, |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
288 |
'content_file_write' : content_file, |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
289 |
'project_id' : options.project_id |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
290 |
}] |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
291 |
post_param = {} |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
292 |
if options.post_param: |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
293 |
post_param = json.loads(options.post_param) |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
294 |
|
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
295 |
for params in parameters: |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
296 |
|
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
297 |
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
|
298 |
|
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
299 |
start_date_str = params.get("start_date",None) |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
300 |
end_date_str = params.get("end_date", None) |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
301 |
duration = params.get("duration", None) |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
302 |
content_file = params.get("content_file", None) |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
303 |
content_file_write = params.get("content_file_write", None) |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
304 |
channels = params.get('channels', [DEFAULT_ANNOTATION_CHANNEL]) |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
305 |
events = params.get('events', []) |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
306 |
|
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
307 |
if user_whitelist_file: |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
308 |
with open(user_whitelist_file, 'r+') as f: |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
309 |
user_whitelist = list(set([s.strip() for s in f])) |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
310 |
|
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
311 |
start_date = None |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
312 |
ts = None |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
313 |
if start_date_str: |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
314 |
start_date = parse_date(start_date_str) |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
315 |
ts = time.mktime(start_date.timetuple()) |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
316 |
|
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
317 |
|
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
318 |
root = None |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
319 |
ensemble_parent = None |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
320 |
|
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
321 |
#to do : analyse situation ldt or iri ? filename set or not ? |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
322 |
|
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
323 |
if content_file and content_file.find("http") == 0: |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
324 |
|
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
325 |
get_logger().debug("url : " + content_file) #@UndefinedVariable |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
326 |
|
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
327 |
r = requests.get(content_file, params=post_param) |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
328 |
get_logger().debug("url response " + repr(r) + " content " + repr(r.text)) #@UndefinedVariable |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
329 |
project = r.json() |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
330 |
text_match = re.match(r"\<\?\s*xml.*?\?\>(.*)", project['ldt'], re.I|re.S) |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
331 |
root = etree.fromstring(text_match.group(1) if text_match else project['ldt']) |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
332 |
|
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
333 |
elif content_file and os.path.exists(content_file): |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
334 |
|
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
335 |
doc = etree.parse(content_file) |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
336 |
root = doc.getroot() |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
337 |
|
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
338 |
content_id = None |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
339 |
|
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
340 |
if root is None: |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
341 |
|
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
342 |
root = etree.Element(u"iri") |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
343 |
|
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
344 |
project = etree.SubElement(root, u"project", {u"abstract":u"Polemics Tweets",u"title":u"Polemic Tweets", u"user":u"IRI Web", u"id":unicode(uuid.uuid4())}) |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
345 |
|
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
346 |
medias = etree.SubElement(root, u"medias") |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
347 |
media = etree.SubElement(medias, u"media", {u"pict":u"", u"src":unicode(options.content), u"video":unicode(options.video), u"id":unicode(options.content_id), u"extra":u""}) |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
348 |
|
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
349 |
annotations = etree.SubElement(root, u"annotations") |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
350 |
content = etree.SubElement(annotations, u"content", {u"id":unicode(options.content_id)}) |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
351 |
ensemble_parent = content |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
352 |
|
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
353 |
content_id = options.content_id |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
354 |
|
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
355 |
|
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
356 |
if ensemble_parent is None: |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
357 |
file_type = None |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
358 |
for node in root: |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
359 |
if node.tag == "project": |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
360 |
file_type = "ldt" |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
361 |
break |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
362 |
elif node.tag == "head": |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
363 |
file_type = "iri" |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
364 |
break |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
365 |
|
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
366 |
if file_type == "ldt": |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
367 |
media_nodes = root.xpath("//media") |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
368 |
if len(media_nodes) > 0: |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
369 |
media = media_nodes[0] |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
370 |
annotations_node = root.find(u"annotations") |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
371 |
if annotations_node is None: |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
372 |
annotations_node = etree.SubElement(root, u"annotations") |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
373 |
content_node = annotations_node.find(u"content") |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
374 |
if content_node is None: |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
375 |
content_node = etree.SubElement(annotations_node,u"content", id=media.get(u"id")) |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
376 |
ensemble_parent = content_node |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
377 |
content_id = content_node.get(u"id") |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
378 |
display_nodes = root.xpath("//displays/display/content[@id='%s']" % content_id) |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
379 |
if len(display_nodes) == 0: |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
380 |
get_logger().info("No display node found. Will not update display") |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
381 |
display_content_node = None |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
382 |
else: |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
383 |
display_content_node = display_nodes[0] |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
384 |
|
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
385 |
elif file_type == "iri": |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
386 |
body_node = root.find(u"body") |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
387 |
if body_node is None: |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
388 |
body_node = etree.SubElement(root, u"body") |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
389 |
ensembles_node = body_node.find(u"ensembles") |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
390 |
if ensembles_node is None: |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
391 |
ensembles_node = etree.SubElement(body_node, u"ensembles") |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
392 |
ensemble_parent = ensembles_node |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
393 |
content_id = root.xpath("head/meta[@name='id']/@content")[0] |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
394 |
display_content_node = None |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
395 |
|
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
396 |
|
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
397 |
if ensemble_parent is None: |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
398 |
get_logger().error("Can not process file") #@UndefinedVariable |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
399 |
sys.exit() |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
400 |
|
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
401 |
if options.replace: |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
402 |
for ens in ensemble_parent.iterchildren(tag=u"ensemble"): |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
403 |
ens_id = ens.get("id","") |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
404 |
if ens_id.startswith("annot_"): |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
405 |
ensemble_parent.remove(ens) |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
406 |
# remove in display nodes |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
407 |
if display_content_node is not None: |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
408 |
for cut_display in display_content_node.iterchildren(): |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
409 |
if cut_display.get('idens','') == ens_id: |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
410 |
display_content_node.remove(cut_display) |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
411 |
|
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
412 |
ensemble = None |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
413 |
elements = None |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
414 |
|
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
415 |
if options.merge: |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
416 |
for ens in ensemble_parent.findall(u"ensemble"): |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
417 |
if ens.get('id',"").startswith("annot_"): |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
418 |
ensemble = ens |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
419 |
break |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
420 |
if ensemble is not None: |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
421 |
elements = ensemble.find(u".//elements") |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
422 |
decoupage = ensemble.find(u"decoupage") |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
423 |
|
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
424 |
if ensemble is None or elements is None: |
26
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
425 |
ensemble = etree.SubElement(ensemble_parent, u"ensemble", {u"id":u"annot_" + unicode(uuid.uuid4()), u"title":u"Ensemble Annotation", u"author":u"IRI Web", u"abstract":u"Ensemble Annotation"}) |
24
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
426 |
decoupage = etree.SubElement(ensemble, u"decoupage", {u"id": unicode(uuid.uuid4()), u"author": u"IRI Web"}) |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
427 |
|
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
428 |
etree.SubElement(decoupage, u"title").text = unicode(options.name) |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
429 |
etree.SubElement(decoupage, u"abstract").text = unicode(options.name) |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
430 |
|
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
431 |
elements = etree.SubElement(decoupage, u"elements") |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
432 |
|
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
433 |
ensemble_id = ensemble.get('id', '') |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
434 |
decoupage_id = decoupage.get('id', '') if decoupage is not None else None |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
435 |
|
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
436 |
end_date = None |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
437 |
if end_date_str: |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
438 |
end_date = parse_date(end_date_str) |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
439 |
elif start_date and duration: |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
440 |
end_date = start_date + datetime.timedelta(seconds=duration) |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
441 |
elif start_date and options.base_url: |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
442 |
# get duration from api |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
443 |
content_url = options.base_url + LDT_CONTENT_REST_API_PATH + content_id + "/?format=json" |
26
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
444 |
get_logger().debug("get duration " + content_url) #@UndefinedVariable |
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
445 |
r = requests.get(content_url, params=post_param) |
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
446 |
get_logger().debug("get duration resp " + repr(r)) #@UndefinedVariable |
24
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
447 |
duration = int(r.json()['duration']) |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
448 |
get_logger().debug("get duration " + repr(duration)) #@UndefinedVariable |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
449 |
|
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
450 |
end_date = start_date + datetime.timedelta(seconds=int(duration/1000)) |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
451 |
|
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
452 |
if end_date and deltas: |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
453 |
end_date = end_date + datetime.timedelta(milliseconds=deltas[-1][1]) |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
454 |
|
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
455 |
|
26
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
456 |
filters = get_filter(start_date, end_date, events, channels, user_whitelist) |
24
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
457 |
|
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
458 |
headers = {'Content-Type': 'application/json'} |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
459 |
|
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
460 |
params = { 'q':json.dumps({'filters':filters}), 'results_per_page': options.batch_size} |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
461 |
|
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
462 |
|
26
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
463 |
for annot in build_annotation_iterator(annotation_url, params, headers): |
24
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
464 |
#TODO : check timezone !!! |
26
ebfd0d3cffab
Correction on export_annotation. First working version
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
465 |
annot_ts_dt = parse_date(annot['ts']) |
24
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
466 |
annot_ts = int(time.mktime(annot_ts_dt.timetuple())) |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
467 |
if ts is None: |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
468 |
ts = annot_ts |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
469 |
annot_ts_rel = (annot_ts-ts) * 1000 |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
470 |
if deltas: |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
471 |
d = find_delta(deltas, annot_ts_rel) |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
472 |
if d[1] < 0: |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
473 |
continue |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
474 |
else : |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
475 |
annot_ts_rel -= d[1] |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
476 |
annot_content = annot.get('content',{'category':'', 'user':None}) |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
477 |
|
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
478 |
username = annot_content.get('user', 'anon.') or 'anon.' |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
479 |
|
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
480 |
category = annot_content.get('category', None) |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
481 |
if category is None: |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
482 |
continue |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
483 |
|
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
484 |
element = etree.SubElement(elements, u"element" , {u"id":annot.get('uuid', uuid.uuid4()), u"color":unicode(options.color), u"author":unicode(username), u"date":unicode(annot_ts_dt.strftime("%Y/%m/%d")), u"begin": unicode(annot_ts_rel), u"dur":u"0"}) |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
485 |
etree.SubElement(element, u"title").text = unicode(username) + u": " + unicode(category.get('label', category.get('code', ''))) |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
486 |
etree.SubElement(element, u"abstract").text = unicode(category.get('label', category.get('code', ''))) |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
487 |
|
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
488 |
tags_node = etree.SubElement(element, u"tags") |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
489 |
etree.SubElement(tags_node,u"tag").text = category.get('code', '') |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
490 |
|
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
491 |
meta_element = etree.SubElement(element, u'meta') |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
492 |
|
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
493 |
polemics_element = etree.Element(u'polemics') |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
494 |
etree.SubElement(polemics_element, u'polemic').text = category.get('code', '') |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
495 |
meta_element.append(polemics_element) |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
496 |
|
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
497 |
etree.SubElement(meta_element, u"source", attrib={"url":annotation_url + "/" + annot['uuid'], "mimetype":u"application/json"}).text = etree.CDATA(json.dumps(annot)) |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
498 |
|
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
499 |
# sort by tc in |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
500 |
if options.merge : |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
501 |
# remove all elements and put them in a array |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
502 |
# sort them with tc |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
503 |
#put them back |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
504 |
elements[:] = sorted(elements,key=lambda n: int(n.get('begin'))) |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
505 |
|
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
506 |
#add to display node |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
507 |
if display_content_node is not None: |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
508 |
display_dec = None |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
509 |
for dec in display_content_node.iterchildren(tag=u"decoupage"): |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
510 |
if dec.get('idens','') == ensemble_id and dec.get('id', '') == decoupage_id: |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
511 |
display_dec = dec |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
512 |
break |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
513 |
if display_dec is None and ensemble_id and decoupage_id: |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
514 |
etree.SubElement(display_content_node, u"decoupage", attrib={'idens': ensemble_id, 'id': decoupage_id, 'tagsSelect':''}) |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
515 |
|
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
516 |
output_data = etree.tostring(root, encoding="utf-8", method="xml", pretty_print=False, xml_declaration=True) |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
517 |
|
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
518 |
if content_file_write and content_file_write.find("http") == 0: |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
519 |
|
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
520 |
project["ldt"] = output_data |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
521 |
project['owner'] = project['owner'].replace('%7E','~') |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
522 |
project['contents'] = [c_url.replace('%7E','~') for c_url in project['contents']] |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
523 |
|
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
524 |
post_param = {} |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
525 |
if options.post_param: |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
526 |
post_param = json.loads(options.post_param) |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
527 |
|
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
528 |
get_logger().debug("write http " + content_file_write) #@UndefinedVariable |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
529 |
get_logger().debug("write http " + repr(post_param)) #@UndefinedVariable |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
530 |
get_logger().debug("write http " + repr(project)) #@UndefinedVariable |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
531 |
r = requests.put(content_file_write, data=json.dumps(project), headers={'content-type':'application/json'}, params=post_param); |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
532 |
get_logger().debug("write http " + repr(r) + " content " + r.text) #@UndefinedVariable |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
533 |
if r.status_code != requests.codes.ok: # @UndefinedVariable |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
534 |
r.raise_for_status() |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
535 |
else: |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
536 |
if content_file_write and os.path.exists(content_file_write): |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
537 |
dest_file_name = content_file_write |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
538 |
else: |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
539 |
dest_file_name = options.filename |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
540 |
|
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
541 |
get_logger().debug("WRITE : " + dest_file_name) #@UndefinedVariable |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
542 |
output = open(dest_file_name, "w") |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
543 |
output.write(output_data) |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
544 |
output.flush() |
eb1f7b06001f
add api + first version (not tested) of export annotation script
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
545 |
output.close() |