Showing 1 changed files with 112 additions and 9 deletions
+112 -9
analyse-votes-AN
... ...
@@ -40,7 +40,9 @@ fi
40 40
 
41 41
 tempfile="/dev/shm/scrutin"
42 42
 
43
+id_cols="Scrutin Date Titre Adoption"
43 44
 typevotes="Pour Contre Abstention Non-votants"
45
+nb_cols=$(wc -w <<< "$id_cols $typevotes $typevotes")
44 46
 
45 47
 if test -n "$nom"; then
46 48
     cible="$nom ($groupe)"
... ...
@@ -49,14 +51,79 @@ else
49 51
 fi
50 52
 result="comparaisons $cible avec $groupe_ref"
51 53
 
54
+mkdir -p "/dev/shm/$result/META-INF"
55
+
56
+cat > "/dev/shm/$result/META-INF/manifest.xml" << EOmetainf
57
+<?xml version="1.0" encoding="UTF-8"?>
58
+<manifest:manifest xmlns:manifest="urn:oasis:names:tc:opendocument:xmlns:manifest:1.0" manifest:version="1.2">
59
+ <manifest:file-entry manifest:full-path="/" manifest:version="1.2" manifest:media-type="application/vnd.oasis.opendocument.spreadsheet"/>
60
+ <manifest:file-entry manifest:full-path="content.xml" manifest:media-type="text/xml"/>
61
+</manifest:manifest>
62
+EOmetainf
63
+
64
+printf 'application/vnd.oasis.opendocument.spreadsheet' > "/dev/shm/$result/mimetype"
65
+
66
+content="/dev/shm/$result/content.xml"
67
+
68
+cat > "$content" << EOcontent
69
+<?xml version="1.0" encoding="UTF-8"?>
70
+<office:document-content xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" xmlns:presentation="urn:oasis:names:tc:opendocument:xmlns:presentation:1.0" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" xmlns:math="http://www.w3.org/1998/Math/MathML" xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" xmlns:ooo="http://openoffice.org/2004/office" xmlns:ooow="http://openoffice.org/2004/writer" xmlns:oooc="http://openoffice.org/2004/calc" xmlns:dom="http://www.w3.org/2001/xml-events" xmlns:xforms="http://www.w3.org/2002/xforms" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:rpt="http://openoffice.org/2005/report" xmlns:of="urn:oasis:names:tc:opendocument:xmlns:of:1.2" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:grddl="http://www.w3.org/2003/g/data-view#" xmlns:tableooo="http://openoffice.org/2009/table" xmlns:drawooo="http://openoffice.org/2010/draw" xmlns:calcext="urn:org:documentfoundation:names:experimental:calc:xmlns:calcext:1.0" xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0" xmlns:field="urn:openoffice:names:experimental:ooo-ms-interop:xmlns:field:1.0" xmlns:formx="urn:openoffice:names:experimental:ooxml-odf-interop:xmlns:form:1.0" xmlns:css3t="http://www.w3.org/TR/css3-text/" office:version="1.2">
71
+<office:scripts/>
72
+<office:font-face-decls>
73
+<style:font-face style:name="Liberation Sans" svg:font-family="&apos;Liberation Sans&apos;" style:font-family-generic="swiss" style:font-pitch="variable"/>
74
+<style:font-face style:name="DejaVu Sans" svg:font-family="&apos;DejaVu Sans&apos;" style:font-family-generic="system" style:font-pitch="variable"/>
75
+<style:font-face style:name="FreeSans" svg:font-family="FreeSans" style:font-family-generic="system" style:font-pitch="variable"/>
76
+</office:font-face-decls>
77
+<office:automatic-styles>
78
+EOcontent
79
+
80
+for i in $(seq $nb_cols); do
81
+    cat >> "$content" << EOcontent
82
+<style:style style:name="co$i" style:family="table-column">
83
+<style:table-column-properties fo:break-before="auto" style:column-width="30.00mm"/>
84
+</style:style>
85
+EOcontent
86
+done
87
+
88
+cat >> "$content" << EOcontent
89
+<style:style style:name="ro1" style:family="table-row">
90
+<style:table-row-properties style:row-height="4.52mm" fo:break-before="auto" style:use-optimal-row-height="true"/>
91
+</style:style>
92
+<style:style style:name="ta1" style:family="table" style:master-page-name="Default">
93
+<style:table-properties table:display="true" style:writing-mode="lr-tb"/>
94
+</style:style>
95
+</office:automatic-styles>
96
+<office:body>
97
+<office:spreadsheet>
98
+<table:calculation-settings table:automatic-find-labels="false"/>
99
+<table:table table:name="$result" table:style-name="ta1">
100
+<office:forms form:automatic-focus="false" form:apply-design-mode="false"/>
101
+EOcontent
102
+
103
+for i in $(seq $nb_cols); do
104
+    echo "<table:table-column table:style-name=\"co$i\" table:default-cell-style-name=\"Default\"/>" >> "$content"
105
+done
106
+echo '<table:table-row table:style-name="ro1">' >> "$content"
107
+
108
+for colonne in $id_cols; do
109
+    cat >> "$content" << EOcontent
110
+<table:table-cell office:value-type="string" calcext:value-type="string">
111
+<text:p>$colonne</text:p>
112
+</table:table-cell>
113
+EOcontent
114
+done
52 115
 
53
-echo -n 'scrutin;date;titre;adoption;' > "$result"
54 116
 for typevote in $typevotes; do
55 117
     for g in "$cible" $groupe_ref; do
56
-        echo -n "$typevote - $g;" >> "$result"
118
+        cat >> "$content" << EOcontent
119
+<table:table-cell office:value-type="string" calcext:value-type="string">
120
+<text:p>$typevote - $g</text:p>
121
+</table:table-cell>
122
+EOcontent
57 123
     done
58 124
 done
59
-echo >> "$result"
125
+
126
+echo '</table:table-row>' >> "$content"
60 127
 
61 128
 last=$(wget -qO- 'http://www2.assemblee-nationale.fr/scrutins/liste/(legislature)/15/(type)/TOUS/(idDossier)/TOUS' | sed -rn 's,^.*<td class="denom">(.+)</td>.*$,\1,p' | head -1)
62 129
 test -r "$archive_scrutins" && first=$(tar tf "$archive_scrutins" | tail -1) || first=0
... ...
@@ -81,18 +148,54 @@ for scrutin in $(seq $last); do
81 148
     date=$(sed -rn 's,^.*<h1 class="">Analyse du scrutin n° '$scrutin'<br/>(.+) </h1>,\1,p' $tempfile)
82 149
     adoption=$(sed -rn 's,^.*<p class="annonce"><span class="annoncevote">(.+).</span></p>.*$,\1,p' $tempfile)
83 150
 
84
-    echo -n "$scrutin;$date;$title;$adoption;" >> "$result"
151
+    cat >> "$content" << EOcontent
152
+<table:table-row table:style-name="ro1">
153
+<table:table-cell office:value-type="float" office:value="$scrutin" calcext:value-type="float">
154
+<text:p>$scrutin</text:p>
155
+</table:table-cell>
156
+<table:table-cell office:value-type="string" calcext:value-type="string">
157
+<text:p>$date</text:p>
158
+</table:table-cell>
159
+<table:table-cell office:value-type="string" calcext:value-type="string">
160
+<text:p>${title//\'/&apos;}</text:p>
161
+</table:table-cell>
162
+<table:table-cell office:value-type="string" calcext:value-type="string">
163
+<text:p>${adoption//\'/&apos;}</text:p>
164
+</table:table-cell>
165
+EOcontent
85 166
 
86 167
     unset cible_votes[*] ref_votes[*]
87 168
     for typevote in $typevotes; do
88 169
         cible_votes[$typevote]=$(sed -rn "${groupes[$groupe]}p" $tempfile | sed -rn '/<p class="typevote">'${typevote}':/,/<.div>/p' | sed 's,</li>,\n,g' | grep -ic "&nbsp;<b>${nom:+${nom}</br>}")
89
-        echo -n "${cible_votes[$typevote]};" >> "$result"
90 170
         ref_votes[$typevote]=$(sed -rn  "${groupes[$groupe_ref]}p"  $tempfile | sed -rn '/<p class="typevote">'${typevote}':/,/<.div>/p' | sed 's,</li>,\n,g' | grep -c '&nbsp;<b>')
91
-        echo -n "${ref_votes[$typevote]};" >> "$result"
171
+
172
+        cat >> "$content" << EOcontent
173
+<table:table-cell office:value-type="float" office:value="${cible_votes[$typevote]}" calcext:value-type="float">
174
+<text:p>${cible_votes[$typevote]}</text:p>
175
+</table:table-cell>
176
+<table:table-cell office:value-type="float" office:value="${ref_votes[$typevote]}" calcext:value-type="float">
177
+<text:p>${ref_votes[$typevote]}</text:p>
178
+</table:table-cell>
179
+EOcontent
92 180
     done
93
-    echo >> "$result"
181
+    echo '</table:table-row>' >> "$content"
94 182
 done
183
+echo
184
+rm $tempfile
95 185
 
96
-echo $result
186
+cat >> "$content" << EOcontent
187
+</table:table>
188
+<table:named-expressions/>
189
+<table:database-ranges>
190
+<table:database-range table:name="__Anonymous_Sheet_DB__0" table:target-range-address="&apos;$result&apos;.A1:&apos;$result&apos;.$(printf "\\$(printf '%03o' $((64+$nb_cols)))")$(($last+1))" table:display-filter-buttons="true"/>
191
+</table:database-ranges>
192
+</office:spreadsheet>
193
+</office:body>
194
+</office:document-content>
195
+EOcontent
97 196
 
98
-rm $tempfile
197
+( cd "/dev/shm/$result" && zip -r ../"$result" * > /dev/null 2>&1 && cd .. && rm -fr "$result" )
198
+
199
+mv -f "/dev/shm/$result.zip" "$result.ods"
200
+
201
+echo "$result.ods"