Skip to content

Instantly share code, notes, and snippets.

View lfcipriani's full-sized avatar
💪
www.beat81.com

Luis Cipriani lfcipriani

💪
www.beat81.com
View GitHub Profile
function startComparison() {
// creates 2 search subscriptions and send the request to Collecta XMPP API via Strophejs
console.log("Subscribing to nodes: "+ terms[0] +" and "+ terms[1]);
connection.send(Collecta.subscribeSearchStanza(terms[0]).tree());
connection.send(Collecta.subscribeSearchStanza(terms[1]).tree());
}
var Collecta = {
subscribeSearchStanza: function(searchName) {
// generate XML for a search subscription on Collecta XMPP API
return $iq({type: 'set', from: anonymous_jid, to: 'search.collecta.com', id: searchName })
.c('pubsub', {xmlns: 'http://jabber.org/protocol/pubsub'})
.c('subscribe', {node: 'search', jid: anonymous_jid})
.up().c('options')
.c('x', {xmlns: 'jabber:x:data', type: 'submit'})
.c('field', {"var": 'FORM_TYPE', type: 'hidden'})
.c('value').t('http://jabber.org/protocol/pubsub#subscribe_options')
function onIq(xml) {
// in this case, the IQ stanzas handled are just subscription results
xmlDom = $(xml);
var iqId = xmlDom.attr('id');
if (iqId == terms[0] || iqId == terms[1]) {
if (xmlDom.find('subscription:first').attr('subscription') == 'subscribed') {
console.log("Subscribed to "+iqId);
}
}
return true;
function onMessage(msg) {
// messages stanzas are converted to JSON and then prepended to the correspondent panel in the UI
var result = Collecta.processItem($(msg));
for (var i=0; i < result.length; i++) {
$('#term'+ result[i].term +"panel")
.prepend("<p>["+result[i].category+"] - <a href=\""+result[i].url+"\" target=\"_blank\" title=\" Access "+terms[result[i].term]+" information\">"+result[i].title+"</a><br />..."+result[i].description+"...<br />Published in "+result[i].published+"</p>");
};
return true;
}
@lfcipriani
lfcipriani / feiralivre.html
Created April 19, 2012 03:26
crappy HTML from a public government website
<HTML>
<HEAD></HEAD>
<BODY>
<HEAD><TITLE>ENDERECO DAS FEIRAS POR DIA </TITLE>
</HEAD>
<BODY bgcolor="f9cd8a">
<!--BODY background="/img_feiras/feiras.GIF"--><br>
<center>
<!--img src="/img_feiras/logo1.GIF" border=0 align=top><BR>
<font color=#006666 size=5><B><I>RELAÇÃO DE FEIRAS</I></B></FONT><BR-->
<table xmlns="http://query.yahooapis.com/v1/schema/table.xsd">
<meta>
<author>Luis Cipriani (@lfcipriani)</author>
<description>
Busca por Feiras Livres em São Paulo, por dia da semana e zona da cidade.
- As zonas possíveis são: CENTRAL, NORTE, SUL, LESTE e OESTE.
- Os dias da semana possíveis são: DOMINGO, TERCA, QUARTA, QUINTA, SEXTA, SÁBADO.
- Deixe o dia da semana em branco para pesquisar em todos os dias de uma vez só.
</description>
<sampleQuery><![CDATA[ SELECT * FROM {table} WHERE zone = 'CENTRAL' ]]></sampleQuery>
<table>
<meta>...</meta>
<bindings>
<select itemPath="" produces="JSON" >
<urls>
<url>http://www3.prefeitura.sp.gov.br/feiras/feiras.asp</url>
</urls>
<inputs>
<key id="dayOfTheWeek" type="xs:string" paramType="variable" default="todos" />
<key id="zone" type="xs:string" paramType="variable" required="true" />
<markets>
<market>
<dayOfTheWeek>DOMINGO</dayOfTheWeek>
<address>RUA CONDE DE PORTO ALEGRE, Sao Paulo, Brazil</address>
</market>
<market>
<dayOfTheWeek>DOMINGO</dayOfTheWeek>
<address>AV AMADEU DA SILVA SAMELLO, Sao Paulo, Brazil</address>
</market>
...
var postData = "zona="+ zone +"&amp;dia=" + dayOfTheWeek;
var data = request.accept('text/html').
contentType("application/x-www-form-urlencoded").
post(postData).response;
var xdata = y.xpath(data, "//font[@color='Red']");
default xml namespace = '';
for each (var item in xdata) {
if (i == 0) {
day = item.toString().trim();
} else if (i == 1) {
address += item.toString().trim() + ", ";
} else if (i == 2) {
number = item.toString().trim();
if (number != "S/N" &amp;&amp; number.length != 0) {
address += number + ", ";