This repository has been archived by the owner on Feb 26, 2020. It is now read-only.
forked from seykron/ogov-data
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbills-to-billit.rb
129 lines (99 loc) · 2.97 KB
/
bills-to-billit.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
require 'httparty'
require 'json'
require 'billit_representers/models/bill'
def newbillit ogovBill
bill = Billit::Bill.new
#p ogovBill
billitAuthors = [];
ogovBill["subscribers"].each { |s|
billitAuthors.push s["name"]
}
billitPaperworks = [];
ogovBill["dictums"].each { |dictum|
billitPaperwork = BillitPaperwork.new;
billitPaperwork.session = dictum["orderPaper"]
billitPaperwork.date = dictum["date"]
billitPaperwork.description = dictum["result"]
billitPaperwork.stage = "Con dictámen"
billitPaperwork.chamber = dictum["source"]
billitPaperworks.push(billitPaperwork);
}
billitDirectives = [];
ogovBill["procedures"].each { |procedure|
billitDirective = BillitDirective.new;
billitDirective.date = procedure["date"];
billitDirective.step = "Votación";
billitDirective.stage = procedure["result"];
billitDirective.link = "";
billitDirectives.push(billitDirective);
}
bill.uid = ogovBill["file"]
bill.short_uid = ogovBill["file"].split("-")[0]
bill.title = ogovBill["summary"].downcase.capitalize
bill.creation_date = ogovBill["creationTime"]
bill.source = ogovBill["source"]
bill.initial_chamber = ogovBill["source"] #This we have to find out more becase it cannot be "PE"
bill.bill_draft_link = "http://www1.hcdn.gov.ar/proyxml/expediente.asp?fundamentos=si&numexp="+ogovBill["file"]
bill.subject_areas = ogovBill["committees"]
bill.authors = billitAuthors
bill.paperworks = billitPaperworks;
bill.directives = billitDirectives;
bill.current_priority = nil; #I think we can adapt this to add priority when the project is expected to be voted on shortly (but this was not the original use case)
#We don't have any of these
bill.priorities =[]
bill.reports =[]
bill.documents =[]
bill.remarks =[]
bill.revisions =[]
return bill;
end
def check bill
req = HTTParty.get([@API_url, @model, bill].join("/"), headers: {"Accept"=>"*/*"});
# p req
# abort
puts "Checking if bill exists. Server responded code: " + req.code.to_s
if req.code == 200
return true
#put bill
else
return false
end
end
def put bill
p "put bill"
bill.put([@API_url, @model, bill.uid].join("/"), @format)
end
def post bill
p "post bill"
bill.post([@API_url, @model].join("/"), @format)
end
startbill = 0;
if (ARGV[0]) then
startbill = ARGV[0].to_i
end
billcount = 0
@model = 'bills'
@API_url = 'http://billit'
@format = 'application/json'
allbills = Dir["bills/*/*/*"].select { |billfile|
if (startbill > billcount) then
billcount = billcount + 1;
next;
end
p billfile; # "bills/39/17/3917-D-2006"
billid = billfile.split(/\//)[-1]
#if check billid
# puts "Bill already exists. No action taken."
#put bill
#else
puts "Creating new bill."
jsontext = File.read(billfile)
jsonbill = JSON.parse(jsontext)
bill = newbillit(jsonbill);
#p bill;
post bill;
#end
billcount = billcount + 1;
#if (billcount > 30) then abort end
p billcount
}