forked from civio/scraper-pge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrender_budget_summary.rb
66 lines (52 loc) · 1.94 KB
/
render_budget_summary.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env ruby
# Generate a summary with the key figures of a budget, in Markdown, so it can be
# explored more easily in Github, f.ex.
require 'csv'
require 'mustache'
require_relative 'lib/budget'
require_relative 'lib/budget_summary_view'
# XXX: This command line stuff is duplicated in the parser, should clean up
budget_id = ARGV[0]
year = budget_id[0..3] # Sometimes there's a P for 'Proposed' at the end. Ignore that bit
is_final = (budget_id.length == 4)
output_path = File.join(".", "output", budget_id)
# Do the calculations
budget = Budget.new(budget_id, is_final)
summary = BudgetSummaryView.new(budget, year)
CSV.foreach(File.join(output_path, "ingresos.csv"), col_sep: ';') do |row|
summary.add_item row
end
CSV.foreach(File.join(output_path, "gastos.csv"), col_sep: ';') do |row|
summary.add_item row
end
# Inline template
template = <<TEMPLATE
##Presupuesto {{year}}
###Ingresos
| No Financieros (I-VII) | I-VIII | Total (I-IX) | Consolidado
:--|---------------------:|-------:|-------------:|------------:
**Estado**|{{ingresos_estado}}
**Organismos autónomos**|{{ingresos_ooaa}}
**Agencias estatales**|{{ingresos_agencias}}
**Otros organismos**|{{ingresos_otros}}
**Seguridad Social**|{{ingresos_seg_social}}
(- transferencias internas)|{{ingresos_transferencias}}
**TOTAL**|{{ingresos_consolidado}}
###Gastos
| No Financieros (I-VII) | I-VIII | Total (I-IX) | Consolidado
:--|---------------------:|-------:|-------------:|------------:
**Estado**|{{gastos_estado}}
**Organismos autónomos**|{{gastos_ooaa}}
**Agencias estatales**|{{gastos_agencias}}
**Otros organismos**|{{gastos_otros}}
**Seguridad Social**|{{gastos_seg_social}}
(- transferencias internas)|{{gastos_transferencias}}
**TOTAL**|{{gastos_consolidado}}
###Comprobaciones
{{{check_budget}}}
TEMPLATE
# Render the output file
summary_filename = File.join(output_path, "README.md")
File.open(summary_filename, 'w') do |file|
file.write Mustache.render(template, summary)
end