| author | ymh <ymh.work@gmail.com> |
| Tue, 22 Oct 2024 10:01:10 +0200 | |
| changeset 1569 | 455bdfbdd320 |
| parent 1542 | 82b5f22448f6 |
| permissions | -rw-r--r-- |
|
1542
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
1 |
#!/usr/bin/env python |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
2 |
# coding=utf-8 |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
3 |
|
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
4 |
import argparse |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
5 |
import datetime |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
6 |
import json |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
7 |
import os.path |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
8 |
import re |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
9 |
import sys |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
10 |
import uuid # @UnresolvedImport |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
11 |
import csv |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
12 |
from dateutil.parser import parse |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
13 |
|
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
14 |
import requests |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
15 |
|
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
16 |
import dateutil.tz |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
17 |
from iri_tweet.utils import get_logger, set_logging, set_logging_options |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
18 |
from lxml import etree |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
19 |
|
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
20 |
LDT_CONTENT_REST_API_PATH = "api/ldt/1.0/contents/" |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
21 |
LDT_PROJECT_REST_API_PATH = "api/ldt/1.0/projects/" |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
22 |
|
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
23 |
def get_options(): |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
24 |
|
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
25 |
parser = argparse.ArgumentParser(description="All date should be given using iso8601 format.") |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
26 |
|
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
27 |
parser.add_argument("-f", "--file", dest="filename", |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
28 |
help="write export to file", metavar="FILE", default="project.ldt") |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
29 |
parser.add_argument("-d", "--csv-file", dest="csv_file", |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
30 |
help="Input chap file", metavar="CSV_FILE") |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
31 |
parser.add_argument("-I", "--content-file", dest="content_file", |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
32 |
help="Content file", metavar="CONTENT_FILE") |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
33 |
parser.add_argument("-c", "--content", dest="content", |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
34 |
help="Content url", metavar="CONTENT") |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
35 |
parser.add_argument("-V", "--video-url", dest="video", |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
36 |
help="video url", metavar="VIDEO") |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
37 |
parser.add_argument("-i", "--content-id", dest="content_id", |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
38 |
help="Content id", metavar="CONTENT_ID") |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
39 |
parser.add_argument("-C", "--color", dest="color", |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
40 |
help="Color code", metavar="COLOR", default="16763904") |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
41 |
parser.add_argument("-n", "--name", dest="name", |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
42 |
help="Cutting name", metavar="NAME", default="chap") |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
43 |
parser.add_argument("-R", "--replace", dest="replace", action="store_true", |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
44 |
help="Replace ensemble", default=False) |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
45 |
parser.add_argument("-m", "--merge", dest="merge", action="store_true", |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
46 |
help="merge ensemble, choose the first ensemble", default=False) |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
47 |
parser.add_argument("-b", "--base-url", dest="base_url", |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
48 |
help="base URL of the platform", metavar="BASE_URL", default="http://ldt.iri.centrepompidou.fr/ldtplatform/") |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
49 |
parser.add_argument("-p", "--project", dest="project_id", |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
50 |
help="Project id", metavar="PROJECT_ID", default=None) |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
51 |
parser.add_argument("-P", "--post-param", dest="post_param", |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
52 |
help="Post param", metavar="POST_PARAM", default=None) |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
53 |
|
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
54 |
set_logging_options(parser) |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
55 |
|
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
56 |
return (parser.parse_args(), parser) |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
57 |
|
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
58 |
|
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
59 |
if __name__ == "__main__" : |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
60 |
|
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
61 |
(options, parser) = get_options() |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
62 |
|
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
63 |
set_logging(options) |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
64 |
|
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
65 |
get_logger().debug("OPTIONS : " + repr(options)) #@UndefinedVariable |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
66 |
|
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
67 |
|
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
68 |
if len(sys.argv) == 1 or options.csv_file is None or not options.csv_file.strip(): |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
69 |
parser.print_help() |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
70 |
sys.exit(1) |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
71 |
|
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
72 |
if options.project_id: |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
73 |
content_file = options.base_url + LDT_PROJECT_REST_API_PATH + options.project_id + "/?format=json" |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
74 |
else: |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
75 |
content_file = options.content_file |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
76 |
parameters = [{ |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
77 |
# 'start_date': options.start_date, |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
78 |
# 'end_date' : options.end_date, |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
79 |
# 'duration' : options.duration, |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
80 |
'content_file' : content_file, |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
81 |
'content_file_write' : content_file, |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
82 |
# 'hashtags' : options.hashtag, |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
83 |
'project_id' : options.project_id |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
84 |
}] |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
85 |
post_param = {} |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
86 |
if options.post_param: |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
87 |
post_param = json.loads(options.post_param) |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
88 |
|
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
89 |
display_content_node = None |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
90 |
for params in parameters: |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
91 |
|
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
92 |
get_logger().debug("PARAMETERS " + repr(params)) #@UndefinedVariable |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
93 |
|
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
94 |
content_file = params.get("content_file", None) |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
95 |
content_file_write = params.get("content_file_write", None) |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
96 |
|
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
97 |
root = None |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
98 |
ensemble_parent = None |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
99 |
project = None |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
100 |
|
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
101 |
#to do : analyse situation ldt or iri ? filename set or not ? |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
102 |
|
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
103 |
if content_file and content_file.find("http") == 0: |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
104 |
|
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
105 |
get_logger().debug("url : " + content_file) #@UndefinedVariable |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
106 |
|
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
107 |
r = requests.get(content_file, params=post_param) |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
108 |
get_logger().debug("url response " + repr(r) + " content " + repr(r.text)) #@UndefinedVariable |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
109 |
project = r.json() |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
110 |
text_match = re.match(r"\<\?\s*xml.*?\?\>(.*)", project['ldt'], re.I|re.S) |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
111 |
root = etree.fromstring(text_match.group(1) if text_match else project['ldt']) |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
112 |
|
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
113 |
elif content_file and os.path.exists(content_file): |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
114 |
|
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
115 |
doc = etree.parse(content_file) |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
116 |
root = doc.getroot() |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
117 |
for child in root: |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
118 |
if child.tag == "project": |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
119 |
project = child |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
120 |
break |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
121 |
if project is None: |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
122 |
root = None |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
123 |
|
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
124 |
content_id = None |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
125 |
|
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
126 |
if root is None: |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
127 |
|
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
128 |
root = etree.Element("iri") |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
129 |
|
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
130 |
project = etree.SubElement(root, "project", {"abstract":"Chapitrage","title":"Chapitrage", "user":"IRI Web", "id":str(uuid.uuid4())}) |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
131 |
|
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
132 |
medias = etree.SubElement(root, "medias") |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
133 |
media = etree.SubElement(medias, "media", {"pict":"", "src":options.content, "video":options.video, "id":options.content_id, "extra":""}) |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
134 |
|
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
135 |
annotations = etree.SubElement(root, "annotations") |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
136 |
content = etree.SubElement(annotations, "content", {"id":options.content_id}) |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
137 |
ensemble_parent = content |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
138 |
|
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
139 |
content_id = options.content_id |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
140 |
|
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
141 |
|
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
142 |
if ensemble_parent is None: |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
143 |
file_type = None |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
144 |
for node in root: |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
145 |
if node.tag == "project": |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
146 |
file_type = "ldt" |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
147 |
break |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
148 |
elif node.tag == "head": |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
149 |
file_type = "iri" |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
150 |
break |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
151 |
|
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
152 |
if file_type == "ldt": |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
153 |
media_nodes = root.xpath("//media") |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
154 |
media = None |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
155 |
if len(media_nodes) > 0: |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
156 |
media = media_nodes[0] |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
157 |
annotations_node = root.find("annotations") |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
158 |
if annotations_node is None: |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
159 |
annotations_node = etree.SubElement(root, "annotations") |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
160 |
content_node = annotations_node.find("content") |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
161 |
if content_node is None and media is not None: |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
162 |
content_node = etree.SubElement(annotations_node,"content", id=media.get("id")) |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
163 |
ensemble_parent = content_node |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
164 |
content_id = content_node.get("id") |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
165 |
display_nodes = root.xpath("//displays/display/content[@id='%s']" % content_id) |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
166 |
if len(display_nodes) == 0: |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
167 |
get_logger().info("No display node found. Will not update display") |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
168 |
display_content_node = None |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
169 |
else: |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
170 |
display_content_node = display_nodes[0] |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
171 |
|
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
172 |
elif file_type == "iri": |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
173 |
body_node = root.find("body") |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
174 |
if body_node is None: |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
175 |
body_node = etree.SubElement(root, "body") |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
176 |
ensembles_node = body_node.find("ensembles") |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
177 |
if ensembles_node is None: |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
178 |
ensembles_node = etree.SubElement(body_node, "ensembles") |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
179 |
ensemble_parent = ensembles_node |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
180 |
content_id = root.xpath("head/meta[@name='id']/@content")[0] |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
181 |
display_content_node = None |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
182 |
|
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
183 |
|
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
184 |
if ensemble_parent is None: |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
185 |
get_logger().error("Can not process file") #@UndefinedVariable |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
186 |
sys.exit() |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
187 |
|
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
188 |
if options.replace: |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
189 |
for ens in ensemble_parent.iterchildren(tag="ensemble"): |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
190 |
ens_id = ens.get("id","") |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
191 |
if ens_id.startswith("chap_"): |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
192 |
ensemble_parent.remove(ens) |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
193 |
# remove in display nodes |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
194 |
if display_content_node is not None: |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
195 |
for cut_display in display_content_node.iterchildren(): |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
196 |
if cut_display.get('idens','') == ens_id: |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
197 |
display_content_node.remove(cut_display) |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
198 |
|
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
199 |
ensemble = None |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
200 |
elements = None |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
201 |
decoupage = None |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
202 |
|
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
203 |
if options.merge: |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
204 |
for ens in ensemble_parent.findall("ensemble"): |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
205 |
if ens.get('id',"").startswith("chap_"): |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
206 |
ensemble = ens |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
207 |
break |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
208 |
if ensemble is not None: |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
209 |
elements = ensemble.find(".//elements") |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
210 |
decoupage = ensemble.find("decoupage") |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
211 |
|
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
212 |
if ensemble is None or elements is None: |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
213 |
ensemble = etree.SubElement(ensemble_parent, "ensemble", {"id":"chap_" + str(uuid.uuid4()), "title":"Ensemble Chapitrage", "author":"IRI Web", "abstract":"Ensemble Chapitrage"}) |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
214 |
decoupage = etree.SubElement(ensemble, "decoupage", {"id": str(uuid.uuid4()), "author": "IRI Web"}) |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
215 |
|
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
216 |
etree.SubElement(decoupage, "title").text = options.name |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
217 |
etree.SubElement(decoupage, "abstract").text = options.name |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
218 |
|
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
219 |
elements = etree.SubElement(decoupage, "elements") |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
220 |
|
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
221 |
ensemble_id = ensemble.get('id', '') |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
222 |
decoupage_id = decoupage.get('id', '') if decoupage is not None else None |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
223 |
|
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
224 |
with open(options.csv_file.strip()) as csvfilein: |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
225 |
chap_reader = csv.DictReader(csvfilein, delimiter=';') |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
226 |
for i,chap_row in enumerate(chap_reader): |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
227 |
|
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
228 |
ts_start = chap_row['START'] |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
229 |
dur = int(chap_row['END'])-int(ts_start) |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
230 |
username = "IRI" |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
231 |
color = "%s"%(int(chap_row['COLOR'].strip("#").lower(),16)) if chap_row['COLOR'] else options.color |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
232 |
title = chap_row['TITLE'] |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
233 |
desc = chap_row['DESCRIPTION'] |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
234 |
tags = chap_row['TAGS'] |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
235 |
|
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
236 |
element = etree.SubElement(elements, "element" , {"id": "%s-%s" % (uuid.uuid4(),i), "color":color, "author":username, "date":datetime.datetime.now().strftime("%Y/%m/%d"), "begin": ts_start, "dur":str(dur), "src":"manual"}) |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
237 |
etree.SubElement(element, "title").text = title[:255] |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
238 |
etree.SubElement(element, "abstract").text = desc |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
239 |
|
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
240 |
tags_node = etree.SubElement(element, "tags") |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
241 |
|
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
242 |
for tag in tags.split(","): |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
243 |
etree.SubElement(tags_node,"tag").text = tag.strip() |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
244 |
|
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
245 |
meta_element = etree.SubElement(element, 'meta') |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
246 |
|
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
247 |
etree.SubElement(meta_element, "source", attrib={"url":"http://www.iri.centrepompidou.fr", "mimetype":"text/plain"}).text = etree.CDATA(json.dumps({'row': chap_row})) |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
248 |
|
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
249 |
# sort by tc in |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
250 |
if options.merge : |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
251 |
# remove all elements and put them in a array |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
252 |
# sort them with tc |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
253 |
#put them back |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
254 |
elements[:] = sorted(elements,key=lambda n: int(n.get('begin'))) |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
255 |
|
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
256 |
#add to display node |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
257 |
if display_content_node is not None: |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
258 |
display_dec = None |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
259 |
for dec in display_content_node.iterchildren(tag="decoupage"): |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
260 |
if dec.get('idens','') == ensemble_id and dec.get('id', '') == decoupage_id: |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
261 |
display_dec = dec |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
262 |
break |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
263 |
if display_dec is None and ensemble_id and decoupage_id: |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
264 |
etree.SubElement(display_content_node, "decoupage", attrib={'idens': ensemble_id, 'id': decoupage_id, 'tagsSelect':''}) |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
265 |
|
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
266 |
output_data = etree.tostring(root, encoding="utf-8", method="xml", pretty_print=False, xml_declaration=True).decode('utf-8') |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
267 |
|
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
268 |
if content_file_write and content_file_write.find("http") == 0: |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
269 |
|
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
270 |
project["ldt"] = output_data |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
271 |
project['owner'] = project['owner'].replace('%7E','~') |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
272 |
project['contents'] = [c_url.replace('%7E','~') for c_url in project['contents']] |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
273 |
|
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
274 |
post_param = {} |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
275 |
if options.post_param: |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
276 |
post_param = json.loads(options.post_param) |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
277 |
|
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
278 |
get_logger().debug("write http " + content_file_write) #@UndefinedVariable |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
279 |
get_logger().debug("write http " + repr(post_param)) #@UndefinedVariable |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
280 |
get_logger().debug("write http " + repr(project)) #@UndefinedVariable |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
281 |
r = requests.put(content_file_write, data=json.dumps(project), headers={'content-type':'application/json'}, params=post_param) |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
282 |
get_logger().debug("write http " + repr(r) + " content " + r.text) #@UndefinedVariable |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
283 |
if r.status_code != requests.codes.ok: # pylint: disable=E1101 |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
284 |
r.raise_for_status() |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
285 |
else: |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
286 |
if content_file_write and os.path.exists(content_file_write): |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
287 |
dest_file_name = content_file_write |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
288 |
else: |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
289 |
dest_file_name = options.filename |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
290 |
|
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
291 |
get_logger().debug("WRITE : " + dest_file_name) #@UndefinedVariable |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
292 |
output = open(dest_file_name, "w") |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
293 |
output.write(output_data) |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
294 |
output.flush() |
|
82b5f22448f6
add utilities to manipulate ldt and zoom chats
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
295 |
output.close() |