-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscraper.js
152 lines (114 loc) · 3.37 KB
/
scraper.js
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
(function($) {
var projects_url = 'data/projects.html';
var places_url = 'http://viradacultural.prefeitura.sp.gov.br/programacao/locais/';
var places_data = 'data/places_02.json';
var projects = [];
var $projects = $('<div />');
$projects.load(projects_url + ' #holder-atracoes', scrap);
function scrap() {
// get places
$.ajax({
url: places_data,
dataType: 'json',
error: function() {
alert('Alguma coisa deu errado, desculpe');
},
success: doYourThing
});
function doYourThing(places) {
var hasData, c;
$projects.find('.holder-content-atracoes').each(function() {
var place = $(this).find('.tit-atracoes').text();
var $placeData = $(this);
storePlaceData(place, $placeData);
});
function storePlaceData(place, $placeData) {
var day, time;
var placeData = _.find(places, function(p) { return p.location_name.indexOf(place) !== -1; });
if(!placeData)
console.log(place);
$placeData.find('.holder-content-atracoes-boxes > *').each(function(i) {
if($(this).is('h4')) {
day = trim($(this).text());
} else if($(this).is('dt')) {
time = trim($(this).text());
} else if($(this).is('dd')) {
var project = {
name: trim($(this).text()),
day: day,
time: time,
place: place
}
_.extend(project, placeData);
projects.push(project);
}
});
}
var config = {
data: projects,
dataRef: {
lat: 'location_latitude',
lng: 'location_longitude'
},
map: {
center: [-23.60, -46.6478],
zoom: 11,
maxZoom: 18,
markers: {
cluster: true
}
},
filters: [
{
name: 's',
sourceRef: 'name',
type: 'text',
title: 'Busca por nome'
},
{
name: 'dia',
sourceRef: 'day',
type: 'multiple-select',
title: 'Dias'
},
{
name: 'local',
sourceRef: 'place',
type: 'multiple-select',
split: ',',
title: 'Local'
},
{
name: 'horario',
sourceRef: 'time',
type: 'multiple-select',
title: 'Hora'
}
],
templates: {
marker: '<h4><%= item.name %></h4><h5><%= item.place %></h5><p><%= item.day %>, às <%= item.time %></p>',
list: '<p class="category"><%= item.place %></p><h3><%= item.name %></h3><p><%= item.day %>, às <%= item.time %></p>',
single: '<p class="cat"><%= item.place %></p><h2><%= item.name %></h2><p><%= item.day %>, às <%= item.time %></p><p class="original_url"><a href="' + places_url + '<%= item.location_slug %>" target="_blank" rel="external">Ver no site oficial</a></p><h3>Informações sobre o local</h3><div class="h3-content"><p><%= item.post_content %></div></p>'
},
labels: {
title: 'VIRADA CULTURAL 2013',
subtitle: '<strong>//Visualização hackeada. Original <a href="http://viradacultural.prefeitura.sp.gov.br/programacao" target="_blank" rel="external">aqui</a></strong>',
filters: 'Filtros',
results: 'Resultados',
clear_search: 'Limpar busca',
close: 'Fechar',
view_map: 'Ver mapa',
loading: {
first: 'Carregando eventos...',
item: 'Carregando...',
error: 'Ops, parece que o servidor de dados está fora do ar. Tente novamente.'
}
}
}
carttirail.init('app', config);
}
}
function trim(str) {
return str.replace(/^\s+|\s+$/g,"");
}
})(jQuery);