| author | ymh <ymh.work@gmail.com> |
| Tue, 12 Jan 2021 13:47:11 +0100 | |
| changeset 1538 | 4e5ee8e79e7f |
| parent 1523 | 53f1b28188f0 |
| permissions | -rw-r--r-- |
|
9
bb44692e09ee
script apres traitement enmi
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
1 |
#!/usr/bin/env python |
|
bb44692e09ee
script apres traitement enmi
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
2 |
# coding=utf-8 |
|
bb44692e09ee
script apres traitement enmi
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
3 |
|
|
957
e4d0094f097b
upgrade virtualenv + script
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
888
diff
changeset
|
4 |
import argparse |
|
1496
184372ec27e2
upgrade to python 3 and twitter api
ymh <ymh.work@gmail.com>
parents:
1480
diff
changeset
|
5 |
import bisect |
|
9
bb44692e09ee
script apres traitement enmi
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
6 |
import datetime |
|
1496
184372ec27e2
upgrade to python 3 and twitter api
ymh <ymh.work@gmail.com>
parents:
1480
diff
changeset
|
7 |
import json |
|
9
bb44692e09ee
script apres traitement enmi
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
8 |
import os.path |
|
bb44692e09ee
script apres traitement enmi
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
9 |
import re |
|
bb44692e09ee
script apres traitement enmi
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
10 |
import sys |
|
1496
184372ec27e2
upgrade to python 3 and twitter api
ymh <ymh.work@gmail.com>
parents:
1480
diff
changeset
|
11 |
import uuid # @UnresolvedImport |
|
184372ec27e2
upgrade to python 3 and twitter api
ymh <ymh.work@gmail.com>
parents:
1480
diff
changeset
|
12 |
|
|
184372ec27e2
upgrade to python 3 and twitter api
ymh <ymh.work@gmail.com>
parents:
1480
diff
changeset
|
13 |
import requests |
|
184372ec27e2
upgrade to python 3 and twitter api
ymh <ymh.work@gmail.com>
parents:
1480
diff
changeset
|
14 |
from lxml import etree |
|
184372ec27e2
upgrade to python 3 and twitter api
ymh <ymh.work@gmail.com>
parents:
1480
diff
changeset
|
15 |
from sqlalchemy import BigInteger, Column, Table, bindparam, event |
|
184372ec27e2
upgrade to python 3 and twitter api
ymh <ymh.work@gmail.com>
parents:
1480
diff
changeset
|
16 |
from sqlalchemy.sql import func, select |
|
184372ec27e2
upgrade to python 3 and twitter api
ymh <ymh.work@gmail.com>
parents:
1480
diff
changeset
|
17 |
|
|
1153
02722ce55cf8
improve timezone support
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
1024
diff
changeset
|
18 |
from dateutil.parser import parse as parse_date_raw |
|
02722ce55cf8
improve timezone support
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
1024
diff
changeset
|
19 |
from dateutil.tz import tzutc |
|
1496
184372ec27e2
upgrade to python 3 and twitter api
ymh <ymh.work@gmail.com>
parents:
1480
diff
changeset
|
20 |
from iri_tweet.models import Tweet, User, setup_database |
|
184372ec27e2
upgrade to python 3 and twitter api
ymh <ymh.work@gmail.com>
parents:
1480
diff
changeset
|
21 |
from iri_tweet.utils import (get_filter_query, get_logger, set_logging, |
|
184372ec27e2
upgrade to python 3 and twitter api
ymh <ymh.work@gmail.com>
parents:
1480
diff
changeset
|
22 |
set_logging_options) |
|
9
bb44692e09ee
script apres traitement enmi
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
23 |
|
|
bb44692e09ee
script apres traitement enmi
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
24 |
#class TweetExclude(object): |
|
bb44692e09ee
script apres traitement enmi
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
25 |
# def __init__(self, id): |
|
bb44692e09ee
script apres traitement enmi
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
26 |
# self.id = id |
|
1023
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
27 |
# |
|
9
bb44692e09ee
script apres traitement enmi
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
28 |
# def __repr__(self): |
|
bb44692e09ee
script apres traitement enmi
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
29 |
# return "<TweetExclude(id=%d)>" % (self.id) |
|
bb44692e09ee
script apres traitement enmi
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
30 |
|
|
763
bc29a6fbb8e8
various correction for export tweet alchemy. Can give a project
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
487
diff
changeset
|
31 |
LDT_CONTENT_REST_API_PATH = "api/ldt/1.0/contents/" |
|
bc29a6fbb8e8
various correction for export tweet alchemy. Can give a project
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
487
diff
changeset
|
32 |
LDT_PROJECT_REST_API_PATH = "api/ldt/1.0/projects/" |
|
764
67a0cee0077f
tag synchro tool correction
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
763
diff
changeset
|
33 |
|
|
1153
02722ce55cf8
improve timezone support
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
1024
diff
changeset
|
34 |
def parse_date(datestr): |
|
02722ce55cf8
improve timezone support
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
1024
diff
changeset
|
35 |
res = parse_date_raw(datestr) |
|
02722ce55cf8
improve timezone support
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
1024
diff
changeset
|
36 |
if res.tzinfo is None: |
|
02722ce55cf8
improve timezone support
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
1024
diff
changeset
|
37 |
res = res.replace(tzinfo=tzutc()) |
|
02722ce55cf8
improve timezone support
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
1024
diff
changeset
|
38 |
return res |
|
02722ce55cf8
improve timezone support
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
1024
diff
changeset
|
39 |
|
|
1023
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
40 |
|
|
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
41 |
def re_fn(expr, item): |
|
764
67a0cee0077f
tag synchro tool correction
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
763
diff
changeset
|
42 |
reg = re.compile(expr, re.I) |
|
67a0cee0077f
tag synchro tool correction
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
763
diff
changeset
|
43 |
res = reg.search(item) |
|
67a0cee0077f
tag synchro tool correction
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
763
diff
changeset
|
44 |
if res: |
|
67a0cee0077f
tag synchro tool correction
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
763
diff
changeset
|
45 |
get_logger().debug("re_fn : " + repr(expr) + "~" + repr(item)) #@UndefinedVariable |
|
1023
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
46 |
return res is not None |
|
9
bb44692e09ee
script apres traitement enmi
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
47 |
|
|
1295
03d2aa7b4967
change default protocol
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
1153
diff
changeset
|
48 |
def parse_polemics_1(tw, extended_mode): |
|
39
c5d7dd0ec4e1
add extended mode for tweet parsing
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
31
diff
changeset
|
49 |
""" |
|
c5d7dd0ec4e1
add extended mode for tweet parsing
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
31
diff
changeset
|
50 |
parse polemics in text and return a list of polemic code. None if not polemic found |
|
c5d7dd0ec4e1
add extended mode for tweet parsing
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
31
diff
changeset
|
51 |
""" |
|
1023
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
52 |
polemics = {} |
|
1496
184372ec27e2
upgrade to python 3 and twitter api
ymh <ymh.work@gmail.com>
parents:
1480
diff
changeset
|
53 |
for m in re.finditer(r"(\+\+|\-\-|\?\?|\=\=)",tw.text): |
|
39
c5d7dd0ec4e1
add extended mode for tweet parsing
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
31
diff
changeset
|
54 |
pol_link = { |
|
1496
184372ec27e2
upgrade to python 3 and twitter api
ymh <ymh.work@gmail.com>
parents:
1480
diff
changeset
|
55 |
'++' : 'OK', |
|
184372ec27e2
upgrade to python 3 and twitter api
ymh <ymh.work@gmail.com>
parents:
1480
diff
changeset
|
56 |
'--' : 'KO', |
|
184372ec27e2
upgrade to python 3 and twitter api
ymh <ymh.work@gmail.com>
parents:
1480
diff
changeset
|
57 |
'??' : 'Q', |
|
184372ec27e2
upgrade to python 3 and twitter api
ymh <ymh.work@gmail.com>
parents:
1480
diff
changeset
|
58 |
'==' : 'REF'}[m.group(1)] |
|
39
c5d7dd0ec4e1
add extended mode for tweet parsing
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
31
diff
changeset
|
59 |
polemics[pol_link] = pol_link |
|
1023
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
60 |
|
|
39
c5d7dd0ec4e1
add extended mode for tweet parsing
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
31
diff
changeset
|
61 |
if extended_mode: |
|
c5d7dd0ec4e1
add extended mode for tweet parsing
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
31
diff
changeset
|
62 |
if "?" in tw.text: |
|
c5d7dd0ec4e1
add extended mode for tweet parsing
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
31
diff
changeset
|
63 |
polemics["Q"] = "Q" |
|
1023
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
64 |
|
|
39
c5d7dd0ec4e1
add extended mode for tweet parsing
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
31
diff
changeset
|
65 |
for entity in tw.entity_list: |
|
c5d7dd0ec4e1
add extended mode for tweet parsing
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
31
diff
changeset
|
66 |
if entity.type == "entity_url": |
|
1023
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
67 |
polemics["REF"] = "REF" |
|
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
68 |
|
|
39
c5d7dd0ec4e1
add extended mode for tweet parsing
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
31
diff
changeset
|
69 |
if len(polemics) > 0: |
|
c5d7dd0ec4e1
add extended mode for tweet parsing
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
31
diff
changeset
|
70 |
return polemics.keys() |
|
c5d7dd0ec4e1
add extended mode for tweet parsing
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
31
diff
changeset
|
71 |
else: |
|
c5d7dd0ec4e1
add extended mode for tweet parsing
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
31
diff
changeset
|
72 |
return None |
|
c5d7dd0ec4e1
add extended mode for tweet parsing
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
31
diff
changeset
|
73 |
|
|
1295
03d2aa7b4967
change default protocol
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
1153
diff
changeset
|
74 |
def parse_polemics_2(tw, extended_mode): |
|
03d2aa7b4967
change default protocol
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
1153
diff
changeset
|
75 |
""" |
|
03d2aa7b4967
change default protocol
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
1153
diff
changeset
|
76 |
parse polemics in text and return a list of polemic code. None if not polemic found |
|
03d2aa7b4967
change default protocol
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
1153
diff
changeset
|
77 |
""" |
|
03d2aa7b4967
change default protocol
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
1153
diff
changeset
|
78 |
polemics = {} |
|
1496
184372ec27e2
upgrade to python 3 and twitter api
ymh <ymh.work@gmail.com>
parents:
1480
diff
changeset
|
79 |
for m in re.finditer(r"(\+\+|\!\!|\?\?|\=\=)",tw.text): |
|
1295
03d2aa7b4967
change default protocol
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
1153
diff
changeset
|
80 |
pol_link = { |
|
1496
184372ec27e2
upgrade to python 3 and twitter api
ymh <ymh.work@gmail.com>
parents:
1480
diff
changeset
|
81 |
'++' : 'OK', |
|
184372ec27e2
upgrade to python 3 and twitter api
ymh <ymh.work@gmail.com>
parents:
1480
diff
changeset
|
82 |
'!!' : 'KO', |
|
184372ec27e2
upgrade to python 3 and twitter api
ymh <ymh.work@gmail.com>
parents:
1480
diff
changeset
|
83 |
'??' : 'Q', |
|
184372ec27e2
upgrade to python 3 and twitter api
ymh <ymh.work@gmail.com>
parents:
1480
diff
changeset
|
84 |
'==' : 'REF'}[m.group(1)] |
|
1295
03d2aa7b4967
change default protocol
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
1153
diff
changeset
|
85 |
polemics[pol_link] = pol_link |
|
03d2aa7b4967
change default protocol
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
1153
diff
changeset
|
86 |
|
|
03d2aa7b4967
change default protocol
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
1153
diff
changeset
|
87 |
if extended_mode: |
|
03d2aa7b4967
change default protocol
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
1153
diff
changeset
|
88 |
if "?" in tw.text: |
|
03d2aa7b4967
change default protocol
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
1153
diff
changeset
|
89 |
polemics["Q"] = "Q" |
|
03d2aa7b4967
change default protocol
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
1153
diff
changeset
|
90 |
|
|
03d2aa7b4967
change default protocol
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
1153
diff
changeset
|
91 |
for entity in tw.entity_list: |
|
03d2aa7b4967
change default protocol
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
1153
diff
changeset
|
92 |
if entity.type == "entity_url": |
|
03d2aa7b4967
change default protocol
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
1153
diff
changeset
|
93 |
polemics["REF"] = "REF" |
|
03d2aa7b4967
change default protocol
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
1153
diff
changeset
|
94 |
|
|
03d2aa7b4967
change default protocol
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
1153
diff
changeset
|
95 |
if len(polemics) > 0: |
|
03d2aa7b4967
change default protocol
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
1153
diff
changeset
|
96 |
return polemics.keys() |
|
03d2aa7b4967
change default protocol
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
1153
diff
changeset
|
97 |
else: |
|
03d2aa7b4967
change default protocol
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
1153
diff
changeset
|
98 |
return None |
|
03d2aa7b4967
change default protocol
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
1153
diff
changeset
|
99 |
|
|
1480
d2d28468b410
Add support for displaying new protocol
ymh <ymh.work@gmail.com>
parents:
1308
diff
changeset
|
100 |
def parse_polemics_3(tw, extended_mode): |
|
d2d28468b410
Add support for displaying new protocol
ymh <ymh.work@gmail.com>
parents:
1308
diff
changeset
|
101 |
""" |
|
d2d28468b410
Add support for displaying new protocol
ymh <ymh.work@gmail.com>
parents:
1308
diff
changeset
|
102 |
parse polemics in text and return a list of polemic code. None if not polemic found |
|
d2d28468b410
Add support for displaying new protocol
ymh <ymh.work@gmail.com>
parents:
1308
diff
changeset
|
103 |
""" |
|
d2d28468b410
Add support for displaying new protocol
ymh <ymh.work@gmail.com>
parents:
1308
diff
changeset
|
104 |
polemics = {} |
|
1496
184372ec27e2
upgrade to python 3 and twitter api
ymh <ymh.work@gmail.com>
parents:
1480
diff
changeset
|
105 |
for m in re.finditer(r"(\+\+|\?\?|\*\*|\=\=)",tw.text): |
|
1480
d2d28468b410
Add support for displaying new protocol
ymh <ymh.work@gmail.com>
parents:
1308
diff
changeset
|
106 |
pol_link = { |
|
1496
184372ec27e2
upgrade to python 3 and twitter api
ymh <ymh.work@gmail.com>
parents:
1480
diff
changeset
|
107 |
'++' : 'OK', |
|
184372ec27e2
upgrade to python 3 and twitter api
ymh <ymh.work@gmail.com>
parents:
1480
diff
changeset
|
108 |
'??' : 'KO', |
|
184372ec27e2
upgrade to python 3 and twitter api
ymh <ymh.work@gmail.com>
parents:
1480
diff
changeset
|
109 |
'**' : 'REF', |
|
184372ec27e2
upgrade to python 3 and twitter api
ymh <ymh.work@gmail.com>
parents:
1480
diff
changeset
|
110 |
'==' : 'Q'}[m.group(1)] |
|
1480
d2d28468b410
Add support for displaying new protocol
ymh <ymh.work@gmail.com>
parents:
1308
diff
changeset
|
111 |
polemics[pol_link] = pol_link |
|
d2d28468b410
Add support for displaying new protocol
ymh <ymh.work@gmail.com>
parents:
1308
diff
changeset
|
112 |
|
|
d2d28468b410
Add support for displaying new protocol
ymh <ymh.work@gmail.com>
parents:
1308
diff
changeset
|
113 |
if extended_mode: |
|
d2d28468b410
Add support for displaying new protocol
ymh <ymh.work@gmail.com>
parents:
1308
diff
changeset
|
114 |
for entity in tw.entity_list: |
|
d2d28468b410
Add support for displaying new protocol
ymh <ymh.work@gmail.com>
parents:
1308
diff
changeset
|
115 |
if entity.type == "entity_url": |
|
d2d28468b410
Add support for displaying new protocol
ymh <ymh.work@gmail.com>
parents:
1308
diff
changeset
|
116 |
polemics["REF"] = "REF" |
|
d2d28468b410
Add support for displaying new protocol
ymh <ymh.work@gmail.com>
parents:
1308
diff
changeset
|
117 |
|
|
d2d28468b410
Add support for displaying new protocol
ymh <ymh.work@gmail.com>
parents:
1308
diff
changeset
|
118 |
if len(polemics) > 0: |
|
d2d28468b410
Add support for displaying new protocol
ymh <ymh.work@gmail.com>
parents:
1308
diff
changeset
|
119 |
return polemics.keys() |
|
d2d28468b410
Add support for displaying new protocol
ymh <ymh.work@gmail.com>
parents:
1308
diff
changeset
|
120 |
else: |
|
d2d28468b410
Add support for displaying new protocol
ymh <ymh.work@gmail.com>
parents:
1308
diff
changeset
|
121 |
return None |
|
d2d28468b410
Add support for displaying new protocol
ymh <ymh.work@gmail.com>
parents:
1308
diff
changeset
|
122 |
|
|
d2d28468b410
Add support for displaying new protocol
ymh <ymh.work@gmail.com>
parents:
1308
diff
changeset
|
123 |
|
|
1295
03d2aa7b4967
change default protocol
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
1153
diff
changeset
|
124 |
protocol_version_map = { |
|
03d2aa7b4967
change default protocol
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
1153
diff
changeset
|
125 |
"1" : parse_polemics_1, |
|
1480
d2d28468b410
Add support for displaying new protocol
ymh <ymh.work@gmail.com>
parents:
1308
diff
changeset
|
126 |
"2" : parse_polemics_2, |
|
d2d28468b410
Add support for displaying new protocol
ymh <ymh.work@gmail.com>
parents:
1308
diff
changeset
|
127 |
"3" : parse_polemics_3 |
|
1295
03d2aa7b4967
change default protocol
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
1153
diff
changeset
|
128 |
} |
|
03d2aa7b4967
change default protocol
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
1153
diff
changeset
|
129 |
|
|
11
54d7f1486ac4
implement get_oauth_token
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
9
diff
changeset
|
130 |
def get_options(): |
|
1023
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
131 |
|
|
1153
02722ce55cf8
improve timezone support
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
1024
diff
changeset
|
132 |
parser = argparse.ArgumentParser(description="All date should be given using iso8601 format. If no timezone is used, the date is considered as UTC") |
|
1023
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
133 |
|
|
957
e4d0094f097b
upgrade virtualenv + script
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
888
diff
changeset
|
134 |
parser.add_argument("-f", "--file", dest="filename", |
|
84
b1029aa40ec3
add polemical timeline for opendata
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
83
diff
changeset
|
135 |
help="write export to file", metavar="FILE", default="project.ldt") |
|
957
e4d0094f097b
upgrade virtualenv + script
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
888
diff
changeset
|
136 |
parser.add_argument("-d", "--database", dest="database", |
|
9
bb44692e09ee
script apres traitement enmi
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
137 |
help="Input database", metavar="DATABASE") |
|
1295
03d2aa7b4967
change default protocol
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
1153
diff
changeset
|
138 |
parser.add_argument("-a", "--annotation-protocol", dest="protocol_version", |
|
03d2aa7b4967
change default protocol
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
1153
diff
changeset
|
139 |
help="annotation protocol version", metavar="PROTOCOL_VERSION", |
|
03d2aa7b4967
change default protocol
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
1153
diff
changeset
|
140 |
default="2") |
|
957
e4d0094f097b
upgrade virtualenv + script
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
888
diff
changeset
|
141 |
parser.add_argument("-s", "--start-date", dest="start_date", |
|
289
a5eff8f2b81d
improve session maker creation + models version + add model version in db
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
275
diff
changeset
|
142 |
help="start date", metavar="START_DATE", default=None) |
|
957
e4d0094f097b
upgrade virtualenv + script
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
888
diff
changeset
|
143 |
parser.add_argument("-e", "--end-date", dest="end_date", |
|
289
a5eff8f2b81d
improve session maker creation + models version + add model version in db
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
275
diff
changeset
|
144 |
help="end date", metavar="END_DATE", default=None) |
|
957
e4d0094f097b
upgrade virtualenv + script
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
888
diff
changeset
|
145 |
parser.add_argument("-I", "--content-file", dest="content_file", |
|
9
bb44692e09ee
script apres traitement enmi
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
146 |
help="Content file", metavar="CONTENT_FILE") |
|
957
e4d0094f097b
upgrade virtualenv + script
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
888
diff
changeset
|
147 |
parser.add_argument("-c", "--content", dest="content", |
|
9
bb44692e09ee
script apres traitement enmi
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
148 |
help="Content url", metavar="CONTENT") |
|
957
e4d0094f097b
upgrade virtualenv + script
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
888
diff
changeset
|
149 |
parser.add_argument("-V", "--video-url", dest="video", |
|
9
bb44692e09ee
script apres traitement enmi
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
150 |
help="video url", metavar="VIDEO") |
|
957
e4d0094f097b
upgrade virtualenv + script
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
888
diff
changeset
|
151 |
parser.add_argument("-i", "--content-id", dest="content_id", |
|
9
bb44692e09ee
script apres traitement enmi
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
152 |
help="Content id", metavar="CONTENT_ID") |
|
957
e4d0094f097b
upgrade virtualenv + script
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
888
diff
changeset
|
153 |
parser.add_argument("-x", "--exclude", dest="exclude", |
|
9
bb44692e09ee
script apres traitement enmi
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
154 |
help="file containing the id to exclude", metavar="EXCLUDE") |
|
957
e4d0094f097b
upgrade virtualenv + script
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
888
diff
changeset
|
155 |
parser.add_argument("-C", "--color", dest="color", |
|
9
bb44692e09ee
script apres traitement enmi
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
156 |
help="Color code", metavar="COLOR", default="16763904") |
|
957
e4d0094f097b
upgrade virtualenv + script
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
888
diff
changeset
|
157 |
parser.add_argument("-H", "--hashtag", dest="hashtag", |
|
1023
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
158 |
help="Hashtag", metavar="HASHTAG", default=[], action="append") |
|
957
e4d0094f097b
upgrade virtualenv + script
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
888
diff
changeset
|
159 |
parser.add_argument("-D", "--duration", dest="duration", type=int, |
|
9
bb44692e09ee
script apres traitement enmi
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
160 |
help="Duration", metavar="DURATION", default=None) |
|
957
e4d0094f097b
upgrade virtualenv + script
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
888
diff
changeset
|
161 |
parser.add_argument("-n", "--name", dest="name", |
|
1496
184372ec27e2
upgrade to python 3 and twitter api
ymh <ymh.work@gmail.com>
parents:
1480
diff
changeset
|
162 |
help="Cutting name", metavar="NAME", default="Tweets") |
|
957
e4d0094f097b
upgrade virtualenv + script
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
888
diff
changeset
|
163 |
parser.add_argument("-R", "--replace", dest="replace", action="store_true", |
|
e4d0094f097b
upgrade virtualenv + script
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
888
diff
changeset
|
164 |
help="Replace tweet ensemble", default=False) |
|
e4d0094f097b
upgrade virtualenv + script
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
888
diff
changeset
|
165 |
parser.add_argument("-m", "--merge", dest="merge", action="store_true", |
|
e4d0094f097b
upgrade virtualenv + script
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
888
diff
changeset
|
166 |
help="merge tweet ensemble, choose the first ensemble", default=False) |
|
e4d0094f097b
upgrade virtualenv + script
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
888
diff
changeset
|
167 |
parser.add_argument("-L", "--list-conf", dest="listconf", |
|
21
8003bcd8d9a2
correct export and add twitter metadata and polemic
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
12
diff
changeset
|
168 |
help="list of file to process", metavar="LIST_CONF", default=None) |
|
957
e4d0094f097b
upgrade virtualenv + script
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
888
diff
changeset
|
169 |
parser.add_argument("-E", "--extended", dest="extended_mode", action="store_true", |
|
e4d0094f097b
upgrade virtualenv + script
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
888
diff
changeset
|
170 |
help="Trigger polemic extended mode", default=False) |
|
e4d0094f097b
upgrade virtualenv + script
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
888
diff
changeset
|
171 |
parser.add_argument("-b", "--base-url", dest="base_url", |
|
763
bc29a6fbb8e8
various correction for export tweet alchemy. Can give a project
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
487
diff
changeset
|
172 |
help="base URL of the platform", metavar="BASE_URL", default="http://ldt.iri.centrepompidou.fr/ldtplatform/") |
|
1023
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
173 |
parser.add_argument("-p", "--project", dest="project_id", |
|
763
bc29a6fbb8e8
various correction for export tweet alchemy. Can give a project
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
487
diff
changeset
|
174 |
help="Project id", metavar="PROJECT_ID", default=None) |
|
1023
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
175 |
parser.add_argument("-P", "--post-param", dest="post_param", |
|
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
176 |
help="Post param", metavar="POST_PARAM", default=None) |
|
957
e4d0094f097b
upgrade virtualenv + script
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
888
diff
changeset
|
177 |
parser.add_argument("--user-whitelist", dest="user_whitelist", action="store", |
|
203
8124cde38141
- add white list on user to filter tweets
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
122
diff
changeset
|
178 |
help="A list of user screen name", metavar="USER_WHITELIST",default=None) |
|
1023
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
179 |
parser.add_argument("--cut", dest="cuts", action="append", |
|
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
180 |
help="A cut with the forma <ts in ms>::<duration>", metavar="CUT", default=[]) |
|
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
181 |
|
|
11
54d7f1486ac4
implement get_oauth_token
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
9
diff
changeset
|
182 |
set_logging_options(parser) |
|
9
bb44692e09ee
script apres traitement enmi
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
183 |
|
|
957
e4d0094f097b
upgrade virtualenv + script
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
888
diff
changeset
|
184 |
return (parser.parse_args(), parser) |
|
11
54d7f1486ac4
implement get_oauth_token
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
9
diff
changeset
|
185 |
|
|
54d7f1486ac4
implement get_oauth_token
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
9
diff
changeset
|
186 |
|
|
1023
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
187 |
def find_delta(deltas, ts): |
|
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
188 |
i = bisect.bisect_right(deltas, (ts+1,0)) |
|
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
189 |
if i: |
|
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
190 |
return deltas[i-1] |
|
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
191 |
return (0,0) |
|
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
192 |
|
|
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
193 |
|
|
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
194 |
def parse_duration(s): |
|
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
195 |
try: |
|
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
196 |
return int(s) |
|
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
197 |
except ValueError: |
|
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
198 |
parts = s.split(":") |
|
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
199 |
if len(parts) < 2: |
|
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
200 |
raise ValueError("Bad duration format") |
|
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
201 |
time_params = { |
|
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
202 |
'hours': int(parts[0]), |
|
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
203 |
'minutes': int(parts[1]), |
|
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
204 |
'seconds': int(parts[2]) if len(parts)>2 else 0 |
|
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
205 |
} |
|
1153
02722ce55cf8
improve timezone support
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
1024
diff
changeset
|
206 |
return int(round(datetime.timedelta(**time_params).total_seconds()*1000)) |
|
1023
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
207 |
|
|
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
208 |
|
|
11
54d7f1486ac4
implement get_oauth_token
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
9
diff
changeset
|
209 |
if __name__ == "__main__" : |
|
9
bb44692e09ee
script apres traitement enmi
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
210 |
|
|
957
e4d0094f097b
upgrade virtualenv + script
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
888
diff
changeset
|
211 |
(options, parser) = get_options() |
|
1023
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
212 |
|
|
11
54d7f1486ac4
implement get_oauth_token
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
9
diff
changeset
|
213 |
set_logging(options) |
|
1023
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
214 |
|
|
255
500cd0405c7a
improve multi processing architecture
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
243
diff
changeset
|
215 |
get_logger().debug("OPTIONS : " + repr(options)) #@UndefinedVariable |
|
1023
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
216 |
|
|
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
217 |
|
|
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
218 |
deltas = [(0,0)] |
|
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
219 |
total_delta = 0 |
|
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
220 |
if options.cuts: |
|
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
221 |
cuts_raw = sorted([tuple([parse_duration(s) for s in c.split("::")]) for c in options.cuts]) |
|
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
222 |
for c, d in cuts_raw: |
|
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
223 |
deltas.append((c+total_delta, -1)) |
|
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
224 |
total_delta += d |
|
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
225 |
deltas.append((c+total_delta, total_delta)) |
|
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
226 |
|
|
84
b1029aa40ec3
add polemical timeline for opendata
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
83
diff
changeset
|
227 |
if len(sys.argv) == 1 or options.database is None: |
|
b1029aa40ec3
add polemical timeline for opendata
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
83
diff
changeset
|
228 |
parser.print_help() |
|
b1029aa40ec3
add polemical timeline for opendata
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
83
diff
changeset
|
229 |
sys.exit(1) |
|
1023
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
230 |
|
|
255
500cd0405c7a
improve multi processing architecture
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
243
diff
changeset
|
231 |
conn_str = options.database.strip() |
|
1496
184372ec27e2
upgrade to python 3 and twitter api
ymh <ymh.work@gmail.com>
parents:
1480
diff
changeset
|
232 |
if not re.match(r"^\w+://.+", conn_str): |
|
255
500cd0405c7a
improve multi processing architecture
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
243
diff
changeset
|
233 |
conn_str = 'sqlite:///' + conn_str |
|
500cd0405c7a
improve multi processing architecture
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
243
diff
changeset
|
234 |
|
|
1023
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
235 |
engine, metadata, Session = setup_database(conn_str, echo=((options.verbose-options.quiet)>0), create_all = False) |
|
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
236 |
|
|
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
237 |
|
|
289
a5eff8f2b81d
improve session maker creation + models version + add model version in db
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
275
diff
changeset
|
238 |
conn = None |
|
9
bb44692e09ee
script apres traitement enmi
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
239 |
try : |
|
764
67a0cee0077f
tag synchro tool correction
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
763
diff
changeset
|
240 |
conn = engine.connect() |
|
67a0cee0077f
tag synchro tool correction
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
763
diff
changeset
|
241 |
@event.listens_for(conn, "begin") |
|
67a0cee0077f
tag synchro tool correction
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
763
diff
changeset
|
242 |
def do_begin(conn): |
|
1023
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
243 |
conn.connection.create_function('regexp', 2, re_fn) |
|
289
a5eff8f2b81d
improve session maker creation + models version + add model version in db
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
275
diff
changeset
|
244 |
session = None |
|
a5eff8f2b81d
improve session maker creation + models version + add model version in db
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
275
diff
changeset
|
245 |
try : |
|
1023
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
246 |
session = Session(bind=conn) |
|
9
bb44692e09ee
script apres traitement enmi
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
247 |
tweet_exclude_table = Table("tweet_exclude", metadata, Column('id', BigInteger, primary_key=True), prefixes=['TEMPORARY']) |
|
bb44692e09ee
script apres traitement enmi
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
248 |
#mapper(TweetExclude, tweet_exclude_table) |
|
289
a5eff8f2b81d
improve session maker creation + models version + add model version in db
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
275
diff
changeset
|
249 |
metadata.create_all(bind=conn, tables=[tweet_exclude_table]) |
|
1023
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
250 |
|
|
9
bb44692e09ee
script apres traitement enmi
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
251 |
if options.exclude and os.path.exists(options.exclude): |
|
bb44692e09ee
script apres traitement enmi
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
252 |
with open(options.exclude, 'r+') as f: |
|
1496
184372ec27e2
upgrade to python 3 and twitter api
ymh <ymh.work@gmail.com>
parents:
1480
diff
changeset
|
253 |
tei = tweet_exclude_table.insert() # pylint: disable=E1120 |
|
184372ec27e2
upgrade to python 3 and twitter api
ymh <ymh.work@gmail.com>
parents:
1480
diff
changeset
|
254 |
ex_regexp = re.compile(r"(?P<field>\w+)(?P<op>[~=])(?P<value>.+)", re.I) |
|
9
bb44692e09ee
script apres traitement enmi
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
255 |
for line in f: |
|
763
bc29a6fbb8e8
various correction for export tweet alchemy. Can give a project
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
487
diff
changeset
|
256 |
res = ex_regexp.match(line.strip()) |
|
bc29a6fbb8e8
various correction for export tweet alchemy. Can give a project
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
487
diff
changeset
|
257 |
if res: |
|
1023
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
258 |
if res.group('field') == "id": |
|
763
bc29a6fbb8e8
various correction for export tweet alchemy. Can give a project
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
487
diff
changeset
|
259 |
conn.execute(tei.values(id=res.group('value'))) |
|
bc29a6fbb8e8
various correction for export tweet alchemy. Can give a project
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
487
diff
changeset
|
260 |
else: |
|
bc29a6fbb8e8
various correction for export tweet alchemy. Can give a project
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
487
diff
changeset
|
261 |
exclude_query = session.query(Tweet) |
|
bc29a6fbb8e8
various correction for export tweet alchemy. Can give a project
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
487
diff
changeset
|
262 |
filter_obj = Tweet |
|
bc29a6fbb8e8
various correction for export tweet alchemy. Can give a project
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
487
diff
changeset
|
263 |
filter_field = res.group('field') |
|
764
67a0cee0077f
tag synchro tool correction
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
763
diff
changeset
|
264 |
if filter_field.startswith("user__"): |
|
67a0cee0077f
tag synchro tool correction
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
763
diff
changeset
|
265 |
exclude_query = exclude_query.outerjoin(User, Tweet.user_id==User.id) |
|
763
bc29a6fbb8e8
various correction for export tweet alchemy. Can give a project
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
487
diff
changeset
|
266 |
filter_obj = User |
|
1023
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
267 |
filter_field = filter_field[len("user__"):] |
|
763
bc29a6fbb8e8
various correction for export tweet alchemy. Can give a project
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
487
diff
changeset
|
268 |
|
|
bc29a6fbb8e8
various correction for export tweet alchemy. Can give a project
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
487
diff
changeset
|
269 |
if res.group('op') == "=": |
|
764
67a0cee0077f
tag synchro tool correction
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
763
diff
changeset
|
270 |
exclude_query = exclude_query.filter(getattr(filter_obj, filter_field) == res.group('value')) |
|
763
bc29a6fbb8e8
various correction for export tweet alchemy. Can give a project
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
487
diff
changeset
|
271 |
else: |
|
764
67a0cee0077f
tag synchro tool correction
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
763
diff
changeset
|
272 |
exclude_query = exclude_query.filter(getattr(filter_obj, filter_field).op('regexp')(res.group('value'))) |
|
1023
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
273 |
|
|
764
67a0cee0077f
tag synchro tool correction
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
763
diff
changeset
|
274 |
test_query = select([func.count()]).where(tweet_exclude_table.c.id==bindparam('t_id')) |
|
763
bc29a6fbb8e8
various correction for export tweet alchemy. Can give a project
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
487
diff
changeset
|
275 |
for t in exclude_query.all(): |
|
764
67a0cee0077f
tag synchro tool correction
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
763
diff
changeset
|
276 |
get_logger().debug("t : " + repr(t)) |
|
67a0cee0077f
tag synchro tool correction
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
763
diff
changeset
|
277 |
if conn.execute(test_query, t_id=t.id).fetchone()[0] == 0: |
|
67a0cee0077f
tag synchro tool correction
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
763
diff
changeset
|
278 |
conn.execute(tei.values(id=t.id)) |
|
1023
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
279 |
|
|
203
8124cde38141
- add white list on user to filter tweets
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
122
diff
changeset
|
280 |
user_whitelist_file = options.user_whitelist |
|
8124cde38141
- add white list on user to filter tweets
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
122
diff
changeset
|
281 |
user_whitelist = None |
|
1023
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
282 |
|
|
9
bb44692e09ee
script apres traitement enmi
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
283 |
if options.listconf: |
|
1023
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
284 |
|
|
9
bb44692e09ee
script apres traitement enmi
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
285 |
parameters = [] |
|
bb44692e09ee
script apres traitement enmi
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
286 |
confdoc = etree.parse(options.listconf) |
|
bb44692e09ee
script apres traitement enmi
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
287 |
for node in confdoc.xpath("/twitter_export/file"): |
|
bb44692e09ee
script apres traitement enmi
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
288 |
params = {} |
|
bb44692e09ee
script apres traitement enmi
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
289 |
for snode in node: |
|
bb44692e09ee
script apres traitement enmi
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
290 |
if snode.tag == "path": |
|
bb44692e09ee
script apres traitement enmi
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
291 |
params['content_file'] = snode.text |
|
763
bc29a6fbb8e8
various correction for export tweet alchemy. Can give a project
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
487
diff
changeset
|
292 |
params['content_file_write'] = snode.text |
|
bc29a6fbb8e8
various correction for export tweet alchemy. Can give a project
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
487
diff
changeset
|
293 |
elif snode.tag == "project_id": |
|
bc29a6fbb8e8
various correction for export tweet alchemy. Can give a project
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
487
diff
changeset
|
294 |
params['content_file'] = options.base_url + LDT_PROJECT_REST_API_PATH + snode.text + "/?format=json" |
|
764
67a0cee0077f
tag synchro tool correction
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
763
diff
changeset
|
295 |
params['content_file_write'] = options.base_url + LDT_PROJECT_REST_API_PATH + snode.text + "/?format=json" |
|
763
bc29a6fbb8e8
various correction for export tweet alchemy. Can give a project
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
487
diff
changeset
|
296 |
params['project_id'] = snode.text |
|
9
bb44692e09ee
script apres traitement enmi
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
297 |
elif snode.tag == "start_date": |
|
bb44692e09ee
script apres traitement enmi
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
298 |
params['start_date'] = snode.text |
|
bb44692e09ee
script apres traitement enmi
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
299 |
elif snode.tag == "end_date": |
|
bb44692e09ee
script apres traitement enmi
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
300 |
params['end_date'] = snode.text |
|
bb44692e09ee
script apres traitement enmi
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
301 |
elif snode.tag == "duration": |
|
bb44692e09ee
script apres traitement enmi
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
302 |
params['duration'] = int(snode.text) |
|
82
210dc265c70f
add script to tweet users
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
39
diff
changeset
|
303 |
elif snode.tag == "hashtags": |
|
210dc265c70f
add script to tweet users
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
39
diff
changeset
|
304 |
params['hashtags'] = [snode.text] |
|
210dc265c70f
add script to tweet users
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
39
diff
changeset
|
305 |
if options.hashtag or 'hashtags' not in params : |
|
210dc265c70f
add script to tweet users
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
39
diff
changeset
|
306 |
params['hashtags'] = options.hashtag |
|
9
bb44692e09ee
script apres traitement enmi
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
307 |
parameters.append(params) |
|
763
bc29a6fbb8e8
various correction for export tweet alchemy. Can give a project
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
487
diff
changeset
|
308 |
else: |
|
bc29a6fbb8e8
various correction for export tweet alchemy. Can give a project
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
487
diff
changeset
|
309 |
if options.project_id: |
|
bc29a6fbb8e8
various correction for export tweet alchemy. Can give a project
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
487
diff
changeset
|
310 |
content_file = options.base_url + LDT_PROJECT_REST_API_PATH + options.project_id + "/?format=json" |
|
bc29a6fbb8e8
various correction for export tweet alchemy. Can give a project
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
487
diff
changeset
|
311 |
else: |
|
1023
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
312 |
content_file = options.content_file |
|
9
bb44692e09ee
script apres traitement enmi
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
313 |
parameters = [{ |
|
bb44692e09ee
script apres traitement enmi
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
314 |
'start_date': options.start_date, |
|
bb44692e09ee
script apres traitement enmi
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
315 |
'end_date' : options.end_date, |
|
bb44692e09ee
script apres traitement enmi
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
316 |
'duration' : options.duration, |
|
763
bc29a6fbb8e8
various correction for export tweet alchemy. Can give a project
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
487
diff
changeset
|
317 |
'content_file' : content_file, |
|
bc29a6fbb8e8
various correction for export tweet alchemy. Can give a project
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
487
diff
changeset
|
318 |
'content_file_write' : content_file, |
|
bc29a6fbb8e8
various correction for export tweet alchemy. Can give a project
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
487
diff
changeset
|
319 |
'hashtags' : options.hashtag, |
|
1023
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
320 |
'project_id' : options.project_id |
|
9
bb44692e09ee
script apres traitement enmi
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
321 |
}] |
|
763
bc29a6fbb8e8
various correction for export tweet alchemy. Can give a project
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
487
diff
changeset
|
322 |
post_param = {} |
|
bc29a6fbb8e8
various correction for export tweet alchemy. Can give a project
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
487
diff
changeset
|
323 |
if options.post_param: |
|
1496
184372ec27e2
upgrade to python 3 and twitter api
ymh <ymh.work@gmail.com>
parents:
1480
diff
changeset
|
324 |
post_param = json.loads(options.post_param) |
|
763
bc29a6fbb8e8
various correction for export tweet alchemy. Can give a project
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
487
diff
changeset
|
325 |
|
|
9
bb44692e09ee
script apres traitement enmi
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
326 |
for params in parameters: |
|
1023
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
327 |
|
|
255
500cd0405c7a
improve multi processing architecture
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
243
diff
changeset
|
328 |
get_logger().debug("PARAMETERS " + repr(params)) #@UndefinedVariable |
|
1023
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
329 |
|
|
9
bb44692e09ee
script apres traitement enmi
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
330 |
start_date_str = params.get("start_date",None) |
|
bb44692e09ee
script apres traitement enmi
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
331 |
end_date_str = params.get("end_date", None) |
|
bb44692e09ee
script apres traitement enmi
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
332 |
duration = params.get("duration", None) |
|
bb44692e09ee
script apres traitement enmi
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
333 |
content_file = params.get("content_file", None) |
|
763
bc29a6fbb8e8
various correction for export tweet alchemy. Can give a project
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
487
diff
changeset
|
334 |
content_file_write = params.get("content_file_write", None) |
|
1153
02722ce55cf8
improve timezone support
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
1024
diff
changeset
|
335 |
hashtags = list(set(params.get('hashtags', []))) |
|
1023
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
336 |
|
|
203
8124cde38141
- add white list on user to filter tweets
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
122
diff
changeset
|
337 |
if user_whitelist_file: |
|
8124cde38141
- add white list on user to filter tweets
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
122
diff
changeset
|
338 |
with open(user_whitelist_file, 'r+') as f: |
|
8124cde38141
- add white list on user to filter tweets
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
122
diff
changeset
|
339 |
user_whitelist = list(set([s.strip() for s in f])) |
|
1023
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
340 |
|
|
289
a5eff8f2b81d
improve session maker creation + models version + add model version in db
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
275
diff
changeset
|
341 |
start_date = None |
|
a5eff8f2b81d
improve session maker creation + models version + add model version in db
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
275
diff
changeset
|
342 |
if start_date_str: |
|
1023
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
343 |
start_date = parse_date(start_date_str) |
|
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
344 |
|
|
9
bb44692e09ee
script apres traitement enmi
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
345 |
root = None |
|
bb44692e09ee
script apres traitement enmi
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
346 |
ensemble_parent = None |
|
1023
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
347 |
|
|
27
c3ea041c6cde
add update by api
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
23
diff
changeset
|
348 |
#to do : analyse situation ldt or iri ? filename set or not ? |
|
1023
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
349 |
|
|
27
c3ea041c6cde
add update by api
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
23
diff
changeset
|
350 |
if content_file and content_file.find("http") == 0: |
|
1023
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
351 |
|
|
255
500cd0405c7a
improve multi processing architecture
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
243
diff
changeset
|
352 |
get_logger().debug("url : " + content_file) #@UndefinedVariable |
|
1023
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
353 |
|
|
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
354 |
r = requests.get(content_file, params=post_param) |
|
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
355 |
get_logger().debug("url response " + repr(r) + " content " + repr(r.text)) #@UndefinedVariable |
|
764
67a0cee0077f
tag synchro tool correction
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
763
diff
changeset
|
356 |
project = r.json() |
|
67a0cee0077f
tag synchro tool correction
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
763
diff
changeset
|
357 |
text_match = re.match(r"\<\?\s*xml.*?\?\>(.*)", project['ldt'], re.I|re.S) |
|
67a0cee0077f
tag synchro tool correction
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
763
diff
changeset
|
358 |
root = etree.fromstring(text_match.group(1) if text_match else project['ldt']) |
|
1023
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
359 |
|
|
27
c3ea041c6cde
add update by api
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
23
diff
changeset
|
360 |
elif content_file and os.path.exists(content_file): |
|
c3ea041c6cde
add update by api
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
23
diff
changeset
|
361 |
|
|
9
bb44692e09ee
script apres traitement enmi
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
362 |
doc = etree.parse(content_file) |
|
bb44692e09ee
script apres traitement enmi
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
363 |
root = doc.getroot() |
|
1023
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
364 |
|
|
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
365 |
content_id = None |
|
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
366 |
|
|
27
c3ea041c6cde
add update by api
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
23
diff
changeset
|
367 |
if root is None: |
|
1023
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
368 |
|
|
1496
184372ec27e2
upgrade to python 3 and twitter api
ymh <ymh.work@gmail.com>
parents:
1480
diff
changeset
|
369 |
root = etree.Element("iri") |
|
1023
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
370 |
|
|
1496
184372ec27e2
upgrade to python 3 and twitter api
ymh <ymh.work@gmail.com>
parents:
1480
diff
changeset
|
371 |
project = etree.SubElement(root, "project", {"abstract":"Polemics Tweets","title":"Polemic Tweets", "user":"IRI Web", "id":str(uuid.uuid4())}) |
|
1023
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
372 |
|
|
1496
184372ec27e2
upgrade to python 3 and twitter api
ymh <ymh.work@gmail.com>
parents:
1480
diff
changeset
|
373 |
medias = etree.SubElement(root, "medias") |
|
184372ec27e2
upgrade to python 3 and twitter api
ymh <ymh.work@gmail.com>
parents:
1480
diff
changeset
|
374 |
media = etree.SubElement(medias, "media", {"pict":"", "src":options.content, "video":options.video, "id":options.content_id, "extra":""}) |
|
1023
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
375 |
|
|
1496
184372ec27e2
upgrade to python 3 and twitter api
ymh <ymh.work@gmail.com>
parents:
1480
diff
changeset
|
376 |
annotations = etree.SubElement(root, "annotations") |
|
184372ec27e2
upgrade to python 3 and twitter api
ymh <ymh.work@gmail.com>
parents:
1480
diff
changeset
|
377 |
content = etree.SubElement(annotations, "content", {"id":options.content_id}) |
|
9
bb44692e09ee
script apres traitement enmi
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
378 |
ensemble_parent = content |
|
1023
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
379 |
|
|
763
bc29a6fbb8e8
various correction for export tweet alchemy. Can give a project
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
487
diff
changeset
|
380 |
content_id = options.content_id |
|
1023
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
381 |
|
|
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
382 |
|
|
27
c3ea041c6cde
add update by api
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
23
diff
changeset
|
383 |
if ensemble_parent is None: |
|
c3ea041c6cde
add update by api
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
23
diff
changeset
|
384 |
file_type = None |
|
c3ea041c6cde
add update by api
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
23
diff
changeset
|
385 |
for node in root: |
|
c3ea041c6cde
add update by api
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
23
diff
changeset
|
386 |
if node.tag == "project": |
|
c3ea041c6cde
add update by api
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
23
diff
changeset
|
387 |
file_type = "ldt" |
|
c3ea041c6cde
add update by api
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
23
diff
changeset
|
388 |
break |
|
c3ea041c6cde
add update by api
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
23
diff
changeset
|
389 |
elif node.tag == "head": |
|
c3ea041c6cde
add update by api
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
23
diff
changeset
|
390 |
file_type = "iri" |
|
c3ea041c6cde
add update by api
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
23
diff
changeset
|
391 |
break |
|
1023
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
392 |
|
|
27
c3ea041c6cde
add update by api
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
23
diff
changeset
|
393 |
if file_type == "ldt": |
|
c3ea041c6cde
add update by api
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
23
diff
changeset
|
394 |
media_nodes = root.xpath("//media") |
|
c3ea041c6cde
add update by api
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
23
diff
changeset
|
395 |
if len(media_nodes) > 0: |
|
c3ea041c6cde
add update by api
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
23
diff
changeset
|
396 |
media = media_nodes[0] |
|
1496
184372ec27e2
upgrade to python 3 and twitter api
ymh <ymh.work@gmail.com>
parents:
1480
diff
changeset
|
397 |
annotations_node = root.find("annotations") |
|
31
93fd53a97d6d
update lml, correct export
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
27
diff
changeset
|
398 |
if annotations_node is None: |
|
1496
184372ec27e2
upgrade to python 3 and twitter api
ymh <ymh.work@gmail.com>
parents:
1480
diff
changeset
|
399 |
annotations_node = etree.SubElement(root, "annotations") |
|
184372ec27e2
upgrade to python 3 and twitter api
ymh <ymh.work@gmail.com>
parents:
1480
diff
changeset
|
400 |
content_node = annotations_node.find("content") |
|
31
93fd53a97d6d
update lml, correct export
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
27
diff
changeset
|
401 |
if content_node is None: |
|
1496
184372ec27e2
upgrade to python 3 and twitter api
ymh <ymh.work@gmail.com>
parents:
1480
diff
changeset
|
402 |
content_node = etree.SubElement(annotations_node,"content", id=media.get("id")) |
|
31
93fd53a97d6d
update lml, correct export
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
27
diff
changeset
|
403 |
ensemble_parent = content_node |
|
1496
184372ec27e2
upgrade to python 3 and twitter api
ymh <ymh.work@gmail.com>
parents:
1480
diff
changeset
|
404 |
content_id = content_node.get("id") |
|
957
e4d0094f097b
upgrade virtualenv + script
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
888
diff
changeset
|
405 |
display_nodes = root.xpath("//displays/display/content[@id='%s']" % content_id) |
|
e4d0094f097b
upgrade virtualenv + script
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
888
diff
changeset
|
406 |
if len(display_nodes) == 0: |
|
e4d0094f097b
upgrade virtualenv + script
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
888
diff
changeset
|
407 |
get_logger().info("No display node found. Will not update display") |
|
e4d0094f097b
upgrade virtualenv + script
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
888
diff
changeset
|
408 |
display_content_node = None |
|
e4d0094f097b
upgrade virtualenv + script
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
888
diff
changeset
|
409 |
else: |
|
1023
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
410 |
display_content_node = display_nodes[0] |
|
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
411 |
|
|
27
c3ea041c6cde
add update by api
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
23
diff
changeset
|
412 |
elif file_type == "iri": |
|
1496
184372ec27e2
upgrade to python 3 and twitter api
ymh <ymh.work@gmail.com>
parents:
1480
diff
changeset
|
413 |
body_node = root.find("body") |
|
27
c3ea041c6cde
add update by api
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
23
diff
changeset
|
414 |
if body_node is None: |
|
1496
184372ec27e2
upgrade to python 3 and twitter api
ymh <ymh.work@gmail.com>
parents:
1480
diff
changeset
|
415 |
body_node = etree.SubElement(root, "body") |
|
184372ec27e2
upgrade to python 3 and twitter api
ymh <ymh.work@gmail.com>
parents:
1480
diff
changeset
|
416 |
ensembles_node = body_node.find("ensembles") |
|
27
c3ea041c6cde
add update by api
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
23
diff
changeset
|
417 |
if ensembles_node is None: |
|
1496
184372ec27e2
upgrade to python 3 and twitter api
ymh <ymh.work@gmail.com>
parents:
1480
diff
changeset
|
418 |
ensembles_node = etree.SubElement(body_node, "ensembles") |
|
27
c3ea041c6cde
add update by api
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
23
diff
changeset
|
419 |
ensemble_parent = ensembles_node |
|
763
bc29a6fbb8e8
various correction for export tweet alchemy. Can give a project
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
487
diff
changeset
|
420 |
content_id = root.xpath("head/meta[@name='id']/@content")[0] |
|
957
e4d0094f097b
upgrade virtualenv + script
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
888
diff
changeset
|
421 |
display_content_node = None |
|
1023
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
422 |
|
|
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
423 |
|
|
27
c3ea041c6cde
add update by api
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
23
diff
changeset
|
424 |
if ensemble_parent is None: |
|
255
500cd0405c7a
improve multi processing architecture
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
243
diff
changeset
|
425 |
get_logger().error("Can not process file") #@UndefinedVariable |
|
27
c3ea041c6cde
add update by api
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
23
diff
changeset
|
426 |
sys.exit() |
|
1023
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
427 |
|
|
9
bb44692e09ee
script apres traitement enmi
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
428 |
if options.replace: |
|
1496
184372ec27e2
upgrade to python 3 and twitter api
ymh <ymh.work@gmail.com>
parents:
1480
diff
changeset
|
429 |
for ens in ensemble_parent.iterchildren(tag="ensemble"): |
|
1023
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
430 |
ens_id = ens.get("id","") |
|
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
431 |
if ens_id.startswith("tweet_"): |
|
9
bb44692e09ee
script apres traitement enmi
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
432 |
ensemble_parent.remove(ens) |
|
957
e4d0094f097b
upgrade virtualenv + script
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
888
diff
changeset
|
433 |
# remove in display nodes |
|
e4d0094f097b
upgrade virtualenv + script
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
888
diff
changeset
|
434 |
if display_content_node is not None: |
|
e4d0094f097b
upgrade virtualenv + script
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
888
diff
changeset
|
435 |
for cut_display in display_content_node.iterchildren(): |
|
e4d0094f097b
upgrade virtualenv + script
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
888
diff
changeset
|
436 |
if cut_display.get('idens','') == ens_id: |
|
e4d0094f097b
upgrade virtualenv + script
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
888
diff
changeset
|
437 |
display_content_node.remove(cut_display) |
|
1023
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
438 |
|
|
411
0471e6eb8a1b
add merge to export
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
379
diff
changeset
|
439 |
ensemble = None |
|
0471e6eb8a1b
add merge to export
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
379
diff
changeset
|
440 |
elements = None |
|
1023
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
441 |
|
|
411
0471e6eb8a1b
add merge to export
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
379
diff
changeset
|
442 |
if options.merge: |
|
1496
184372ec27e2
upgrade to python 3 and twitter api
ymh <ymh.work@gmail.com>
parents:
1480
diff
changeset
|
443 |
for ens in ensemble_parent.findall("ensemble"): |
|
957
e4d0094f097b
upgrade virtualenv + script
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
888
diff
changeset
|
444 |
if ens.get('id',"").startswith("tweet_"): |
|
e4d0094f097b
upgrade virtualenv + script
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
888
diff
changeset
|
445 |
ensemble = ens |
|
e4d0094f097b
upgrade virtualenv + script
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
888
diff
changeset
|
446 |
break |
|
1023
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
447 |
if ensemble is not None: |
|
1496
184372ec27e2
upgrade to python 3 and twitter api
ymh <ymh.work@gmail.com>
parents:
1480
diff
changeset
|
448 |
elements = ensemble.find(".//elements") |
|
184372ec27e2
upgrade to python 3 and twitter api
ymh <ymh.work@gmail.com>
parents:
1480
diff
changeset
|
449 |
decoupage = ensemble.find("decoupage") |
|
1023
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
450 |
|
|
411
0471e6eb8a1b
add merge to export
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
379
diff
changeset
|
451 |
if ensemble is None or elements is None: |
|
1496
184372ec27e2
upgrade to python 3 and twitter api
ymh <ymh.work@gmail.com>
parents:
1480
diff
changeset
|
452 |
ensemble = etree.SubElement(ensemble_parent, "ensemble", {"id":"tweet_" + str(uuid.uuid4()), "title":"Ensemble Twitter", "author":"IRI Web", "abstract":"Ensemble Twitter"}) |
|
184372ec27e2
upgrade to python 3 and twitter api
ymh <ymh.work@gmail.com>
parents:
1480
diff
changeset
|
453 |
decoupage = etree.SubElement(ensemble, "decoupage", {"id": str(uuid.uuid4()), "author": "IRI Web"}) |
|
1023
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
454 |
|
|
1496
184372ec27e2
upgrade to python 3 and twitter api
ymh <ymh.work@gmail.com>
parents:
1480
diff
changeset
|
455 |
etree.SubElement(decoupage, "title").text = options.name |
|
184372ec27e2
upgrade to python 3 and twitter api
ymh <ymh.work@gmail.com>
parents:
1480
diff
changeset
|
456 |
etree.SubElement(decoupage, "abstract").text = options.name |
|
1023
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
457 |
|
|
1496
184372ec27e2
upgrade to python 3 and twitter api
ymh <ymh.work@gmail.com>
parents:
1480
diff
changeset
|
458 |
elements = etree.SubElement(decoupage, "elements") |
|
411
0471e6eb8a1b
add merge to export
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
379
diff
changeset
|
459 |
|
|
1023
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
460 |
ensemble_id = ensemble.get('id', '') |
|
957
e4d0094f097b
upgrade virtualenv + script
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
888
diff
changeset
|
461 |
decoupage_id = decoupage.get('id', '') if decoupage is not None else None |
|
e4d0094f097b
upgrade virtualenv + script
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
888
diff
changeset
|
462 |
|
|
763
bc29a6fbb8e8
various correction for export tweet alchemy. Can give a project
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
487
diff
changeset
|
463 |
end_date = None |
|
bc29a6fbb8e8
various correction for export tweet alchemy. Can give a project
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
487
diff
changeset
|
464 |
if end_date_str: |
|
bc29a6fbb8e8
various correction for export tweet alchemy. Can give a project
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
487
diff
changeset
|
465 |
end_date = parse_date(end_date_str) |
|
bc29a6fbb8e8
various correction for export tweet alchemy. Can give a project
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
487
diff
changeset
|
466 |
elif start_date and duration: |
|
bc29a6fbb8e8
various correction for export tweet alchemy. Can give a project
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
487
diff
changeset
|
467 |
end_date = start_date + datetime.timedelta(seconds=duration) |
|
1023
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
468 |
elif start_date and options.base_url: |
|
763
bc29a6fbb8e8
various correction for export tweet alchemy. Can give a project
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
487
diff
changeset
|
469 |
# get duration from api |
|
bc29a6fbb8e8
various correction for export tweet alchemy. Can give a project
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
487
diff
changeset
|
470 |
content_url = options.base_url + LDT_CONTENT_REST_API_PATH + content_id + "/?format=json" |
|
bc29a6fbb8e8
various correction for export tweet alchemy. Can give a project
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
487
diff
changeset
|
471 |
r = requests.get(content_url) |
|
bc29a6fbb8e8
various correction for export tweet alchemy. Can give a project
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
487
diff
changeset
|
472 |
duration = int(r.json()['duration']) |
|
bc29a6fbb8e8
various correction for export tweet alchemy. Can give a project
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
487
diff
changeset
|
473 |
get_logger().debug("get duration " + content_url) #@UndefinedVariable |
|
bc29a6fbb8e8
various correction for export tweet alchemy. Can give a project
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
487
diff
changeset
|
474 |
get_logger().debug("get duration " + repr(duration)) #@UndefinedVariable |
|
bc29a6fbb8e8
various correction for export tweet alchemy. Can give a project
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
487
diff
changeset
|
475 |
|
|
bc29a6fbb8e8
various correction for export tweet alchemy. Can give a project
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
487
diff
changeset
|
476 |
end_date = start_date + datetime.timedelta(seconds=int(duration/1000)) |
|
1023
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
477 |
|
|
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
478 |
if end_date and deltas: |
|
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
479 |
end_date = end_date + datetime.timedelta(milliseconds=deltas[-1][1]) |
|
763
bc29a6fbb8e8
various correction for export tweet alchemy. Can give a project
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
487
diff
changeset
|
480 |
query = get_filter_query(session, start_date, end_date, hashtags, tweet_exclude_table, user_whitelist) |
|
1023
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
481 |
|
|
763
bc29a6fbb8e8
various correction for export tweet alchemy. Can give a project
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
487
diff
changeset
|
482 |
query_res = query.all() |
|
bc29a6fbb8e8
various correction for export tweet alchemy. Can give a project
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
487
diff
changeset
|
483 |
|
|
1023
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
484 |
|
|
9
bb44692e09ee
script apres traitement enmi
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
485 |
for tw in query_res: |
|
bb44692e09ee
script apres traitement enmi
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
486 |
tweet_ts_dt = tw.created_at |
|
1153
02722ce55cf8
improve timezone support
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
1024
diff
changeset
|
487 |
if tweet_ts_dt.tzinfo is None: |
|
02722ce55cf8
improve timezone support
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
1024
diff
changeset
|
488 |
tweet_ts_dt = tweet_ts_dt.replace(tzinfo=tzutc()) |
|
02722ce55cf8
improve timezone support
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
1024
diff
changeset
|
489 |
if start_date is None: |
|
02722ce55cf8
improve timezone support
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
1024
diff
changeset
|
490 |
start_date = tweet_ts_dt |
|
02722ce55cf8
improve timezone support
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
1024
diff
changeset
|
491 |
tweet_ts_rel = tweet_ts_dt-start_date |
|
02722ce55cf8
improve timezone support
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
1024
diff
changeset
|
492 |
tweet_ts_rel_milli = int(round(tweet_ts_rel.total_seconds() * 1000)) |
|
1023
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
493 |
if deltas: |
|
1153
02722ce55cf8
improve timezone support
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
1024
diff
changeset
|
494 |
d = find_delta(deltas, tweet_ts_rel_milli) |
|
1023
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
495 |
if d[1] < 0: |
|
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
496 |
continue |
|
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
497 |
else : |
|
1153
02722ce55cf8
improve timezone support
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
1024
diff
changeset
|
498 |
tweet_ts_rel_milli -= d[1] |
|
1023
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
499 |
|
|
9
bb44692e09ee
script apres traitement enmi
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
500 |
username = None |
|
83
4a759c70e40f
add profile_picture_url to the ldt element
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
82
diff
changeset
|
501 |
profile_url = "" |
|
9
bb44692e09ee
script apres traitement enmi
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
502 |
if tw.user is not None: |
|
693
2ef837069108
Starting 'listener_update' branch
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
487
diff
changeset
|
503 |
username = tw.user.screen_name |
|
1523
53f1b28188f0
Take into account change into twitter
ymh <ymh.work@gmail.com>
parents:
1496
diff
changeset
|
504 |
profile_url = tw.user.profile_image_url_https if tw.user.profile_image_url_https is not None else "" |
|
9
bb44692e09ee
script apres traitement enmi
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
505 |
if not username: |
|
bb44692e09ee
script apres traitement enmi
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
506 |
username = "anon." |
|
1023
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
507 |
|
|
1496
184372ec27e2
upgrade to python 3 and twitter api
ymh <ymh.work@gmail.com>
parents:
1480
diff
changeset
|
508 |
element = etree.SubElement(elements, "element" , {"id": "%s-%s" % (uuid.uuid4(),tw.id), "color":options.color, "author":username, "date":tweet_ts_dt.strftime("%Y/%m/%d"), "begin": str(tweet_ts_rel_milli), "dur":"0", "src":profile_url}) |
|
184372ec27e2
upgrade to python 3 and twitter api
ymh <ymh.work@gmail.com>
parents:
1480
diff
changeset
|
509 |
etree.SubElement(element, "title").text = username + ": " + tw.text |
|
184372ec27e2
upgrade to python 3 and twitter api
ymh <ymh.work@gmail.com>
parents:
1480
diff
changeset
|
510 |
etree.SubElement(element, "abstract").text = tw.text |
|
1023
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
511 |
|
|
1496
184372ec27e2
upgrade to python 3 and twitter api
ymh <ymh.work@gmail.com>
parents:
1480
diff
changeset
|
512 |
tags_node = etree.SubElement(element, "tags") |
|
1023
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
513 |
|
|
9
bb44692e09ee
script apres traitement enmi
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
514 |
for entity in tw.entity_list: |
|
1496
184372ec27e2
upgrade to python 3 and twitter api
ymh <ymh.work@gmail.com>
parents:
1480
diff
changeset
|
515 |
if entity.type == 'entity_hashtag': |
|
184372ec27e2
upgrade to python 3 and twitter api
ymh <ymh.work@gmail.com>
parents:
1480
diff
changeset
|
516 |
etree.SubElement(tags_node,"tag").text = entity.hashtag.text |
|
1023
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
517 |
|
|
1496
184372ec27e2
upgrade to python 3 and twitter api
ymh <ymh.work@gmail.com>
parents:
1480
diff
changeset
|
518 |
meta_element = etree.SubElement(element, 'meta') |
|
1023
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
519 |
|
|
1496
184372ec27e2
upgrade to python 3 and twitter api
ymh <ymh.work@gmail.com>
parents:
1480
diff
changeset
|
520 |
etree.SubElement(meta_element, "polemic_version").text = options.protocol_version |
|
1295
03d2aa7b4967
change default protocol
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
1153
diff
changeset
|
521 |
parse_polemics = protocol_version_map.get(options.protocol_version, parse_polemics_2) |
|
39
c5d7dd0ec4e1
add extended mode for tweet parsing
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
31
diff
changeset
|
522 |
polemics_list = parse_polemics(tw, options.extended_mode) |
|
c5d7dd0ec4e1
add extended mode for tweet parsing
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
31
diff
changeset
|
523 |
if polemics_list: |
|
1496
184372ec27e2
upgrade to python 3 and twitter api
ymh <ymh.work@gmail.com>
parents:
1480
diff
changeset
|
524 |
polemics_element = etree.Element('polemics') |
|
39
c5d7dd0ec4e1
add extended mode for tweet parsing
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
31
diff
changeset
|
525 |
for pol in polemics_list: |
|
1496
184372ec27e2
upgrade to python 3 and twitter api
ymh <ymh.work@gmail.com>
parents:
1480
diff
changeset
|
526 |
etree.SubElement(polemics_element, 'polemic').text = pol |
|
22
3823611919ef
set polemics as list
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
21
diff
changeset
|
527 |
meta_element.append(polemics_element) |
|
39
c5d7dd0ec4e1
add extended mode for tweet parsing
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
31
diff
changeset
|
528 |
|
|
1496
184372ec27e2
upgrade to python 3 and twitter api
ymh <ymh.work@gmail.com>
parents:
1480
diff
changeset
|
529 |
etree.SubElement(meta_element, "source", attrib={"url":"http://dev.twitter.com", "mimetype":"application/json"}).text = etree.CDATA(tw.tweet_source.original_json) |
|
1023
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
530 |
|
|
411
0471e6eb8a1b
add merge to export
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
379
diff
changeset
|
531 |
# sort by tc in |
|
0471e6eb8a1b
add merge to export
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
379
diff
changeset
|
532 |
if options.merge : |
|
0471e6eb8a1b
add merge to export
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
379
diff
changeset
|
533 |
# remove all elements and put them in a array |
|
0471e6eb8a1b
add merge to export
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
379
diff
changeset
|
534 |
# sort them with tc |
|
0471e6eb8a1b
add merge to export
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
379
diff
changeset
|
535 |
#put them back |
|
0471e6eb8a1b
add merge to export
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
379
diff
changeset
|
536 |
elements[:] = sorted(elements,key=lambda n: int(n.get('begin'))) |
|
1023
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
537 |
|
|
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
538 |
#add to display node |
|
957
e4d0094f097b
upgrade virtualenv + script
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
888
diff
changeset
|
539 |
if display_content_node is not None: |
|
e4d0094f097b
upgrade virtualenv + script
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
888
diff
changeset
|
540 |
display_dec = None |
|
1496
184372ec27e2
upgrade to python 3 and twitter api
ymh <ymh.work@gmail.com>
parents:
1480
diff
changeset
|
541 |
for dec in display_content_node.iterchildren(tag="decoupage"): |
|
957
e4d0094f097b
upgrade virtualenv + script
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
888
diff
changeset
|
542 |
if dec.get('idens','') == ensemble_id and dec.get('id', '') == decoupage_id: |
|
e4d0094f097b
upgrade virtualenv + script
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
888
diff
changeset
|
543 |
display_dec = dec |
|
e4d0094f097b
upgrade virtualenv + script
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
888
diff
changeset
|
544 |
break |
|
e4d0094f097b
upgrade virtualenv + script
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
888
diff
changeset
|
545 |
if display_dec is None and ensemble_id and decoupage_id: |
|
1496
184372ec27e2
upgrade to python 3 and twitter api
ymh <ymh.work@gmail.com>
parents:
1480
diff
changeset
|
546 |
etree.SubElement(display_content_node, "decoupage", attrib={'idens': ensemble_id, 'id': decoupage_id, 'tagsSelect':''}) |
|
1023
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
547 |
|
|
1496
184372ec27e2
upgrade to python 3 and twitter api
ymh <ymh.work@gmail.com>
parents:
1480
diff
changeset
|
548 |
output_data = etree.tostring(root, encoding="utf-8", method="xml", pretty_print=False, xml_declaration=True).decode('utf-8') |
|
1023
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
549 |
|
|
763
bc29a6fbb8e8
various correction for export tweet alchemy. Can give a project
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
487
diff
changeset
|
550 |
if content_file_write and content_file_write.find("http") == 0: |
|
1023
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
551 |
|
|
27
c3ea041c6cde
add update by api
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
23
diff
changeset
|
552 |
project["ldt"] = output_data |
|
957
e4d0094f097b
upgrade virtualenv + script
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
888
diff
changeset
|
553 |
project['owner'] = project['owner'].replace('%7E','~') |
|
e4d0094f097b
upgrade virtualenv + script
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
888
diff
changeset
|
554 |
project['contents'] = [c_url.replace('%7E','~') for c_url in project['contents']] |
|
1023
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
555 |
|
|
763
bc29a6fbb8e8
various correction for export tweet alchemy. Can give a project
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
487
diff
changeset
|
556 |
post_param = {} |
|
bc29a6fbb8e8
various correction for export tweet alchemy. Can give a project
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
487
diff
changeset
|
557 |
if options.post_param: |
|
1496
184372ec27e2
upgrade to python 3 and twitter api
ymh <ymh.work@gmail.com>
parents:
1480
diff
changeset
|
558 |
post_param = json.loads(options.post_param) |
|
763
bc29a6fbb8e8
various correction for export tweet alchemy. Can give a project
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
487
diff
changeset
|
559 |
|
|
bc29a6fbb8e8
various correction for export tweet alchemy. Can give a project
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
487
diff
changeset
|
560 |
get_logger().debug("write http " + content_file_write) #@UndefinedVariable |
|
bc29a6fbb8e8
various correction for export tweet alchemy. Can give a project
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
487
diff
changeset
|
561 |
get_logger().debug("write http " + repr(post_param)) #@UndefinedVariable |
|
bc29a6fbb8e8
various correction for export tweet alchemy. Can give a project
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
487
diff
changeset
|
562 |
get_logger().debug("write http " + repr(project)) #@UndefinedVariable |
|
1496
184372ec27e2
upgrade to python 3 and twitter api
ymh <ymh.work@gmail.com>
parents:
1480
diff
changeset
|
563 |
r = requests.put(content_file_write, data=json.dumps(project), headers={'content-type':'application/json'}, params=post_param) |
|
763
bc29a6fbb8e8
various correction for export tweet alchemy. Can give a project
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
487
diff
changeset
|
564 |
get_logger().debug("write http " + repr(r) + " content " + r.text) #@UndefinedVariable |
|
1496
184372ec27e2
upgrade to python 3 and twitter api
ymh <ymh.work@gmail.com>
parents:
1480
diff
changeset
|
565 |
if r.status_code != requests.codes.ok: # pylint: disable=E1101 |
|
763
bc29a6fbb8e8
various correction for export tweet alchemy. Can give a project
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
487
diff
changeset
|
566 |
r.raise_for_status() |
|
9
bb44692e09ee
script apres traitement enmi
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
567 |
else: |
|
763
bc29a6fbb8e8
various correction for export tweet alchemy. Can give a project
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
487
diff
changeset
|
568 |
if content_file_write and os.path.exists(content_file_write): |
|
bc29a6fbb8e8
various correction for export tweet alchemy. Can give a project
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
487
diff
changeset
|
569 |
dest_file_name = content_file_write |
|
27
c3ea041c6cde
add update by api
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
23
diff
changeset
|
570 |
else: |
|
c3ea041c6cde
add update by api
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
23
diff
changeset
|
571 |
dest_file_name = options.filename |
|
1023
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
572 |
|
|
255
500cd0405c7a
improve multi processing architecture
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
243
diff
changeset
|
573 |
get_logger().debug("WRITE : " + dest_file_name) #@UndefinedVariable |
|
82
210dc265c70f
add script to tweet users
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
39
diff
changeset
|
574 |
output = open(dest_file_name, "w") |
|
27
c3ea041c6cde
add update by api
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
23
diff
changeset
|
575 |
output.write(output_data) |
|
c3ea041c6cde
add update by api
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
23
diff
changeset
|
576 |
output.flush() |
|
c3ea041c6cde
add update by api
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
23
diff
changeset
|
577 |
output.close() |
|
1023
7d87ba8cc268
Add the capacities to have cuts.
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
957
diff
changeset
|
578 |
|
|
9
bb44692e09ee
script apres traitement enmi
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
579 |
finally: |
|
289
a5eff8f2b81d
improve session maker creation + models version + add model version in db
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
275
diff
changeset
|
580 |
if session: |
|
a5eff8f2b81d
improve session maker creation + models version + add model version in db
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
275
diff
changeset
|
581 |
session.close() |
|
9
bb44692e09ee
script apres traitement enmi
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
582 |
finally: |
|
289
a5eff8f2b81d
improve session maker creation + models version + add model version in db
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
275
diff
changeset
|
583 |
if conn: |
|
a5eff8f2b81d
improve session maker creation + models version + add model version in db
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
275
diff
changeset
|
584 |
conn.close() |