Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Alternative to #8

Merged
merged 4 commits into from

3 participants

@mrshu
Owner

Since duckduckgo tries to be an alternative to google so I thought it would be nice to have ability to provide users with alternatives to software. Thankfully alternativeto.net provides such data and they also have quite nice API.

The regex I propose in this pull request should be able to process queries like:

free alternative to firefox for mac
opensource omnigraffle
TextMate for windows
alternative to gmail

and provide alternatives to the user based on the query.

I am open to suggestions, feel free to speak up.

mrshu added some commits
@mrshu mrshu first commit for alt.to b9f746c
@mrshu mrshu first version of alternativeto.net spice 38fb59b
@mrshu mrshu Added (probably) working spice.pl 8f7e6ca
@mrshu mrshu Better regex for alternativeTo
The regex should now be able to process queries like:

-> free alternative to firefox for mac
-> opensource omnigraffle
-> TextMate for windows
-> alternative to gmail
7cb7eb6
@yegg
Owner

Awesome. We're working on a new core release that will make plugin integration easier, and so it will be a little bit before we get this up.

Should we translate 'open source' into opensource and any other transformations for license and platform?

@hunterlang
Owner

Thanks for your contribution, this looks awesome!
https://duckduckgo.com/?q=alternative+to+iphoto+for+mac

@hunterlang hunterlang merged commit 7f18662 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 22, 2011
  1. @mrshu

    first commit for alt.to

    mrshu authored
Commits on Nov 25, 2011
  1. @mrshu
  2. @mrshu
Commits on Nov 28, 2011
  1. @mrshu

    Better regex for alternativeTo

    mrshu authored
    The regex should now be able to process queries like:
    
    -> free alternative to firefox for mac
    -> opensource omnigraffle
    -> TextMate for windows
    -> alternative to gmail
This page is out of date. Refresh to see the latest.
View
19 alternative_to/spice.html
@@ -0,0 +1,19 @@
+<!doctype html>
+<html>
+<head>
+ <meta charset="utf-8">
+ <title>Alternative.to test</title>
+ <script src="spice.js"></script>
+ <script type="text/javascript">
+ function nra(items) {
+ document.getElementById('a').innerHTML = items[0]['a'];
+ }
+ </script>
+</head>
+<body>
+ <div id="a"></div>
+ <script src="http://yui.yahooapis.com/2.9.0/build/yahoo/yahoo-min.js"></script>
+ <script src="http://yui.yahooapis.com/2.9.0/build/dom/dom-min.js"></script>
+ <script src="http://thor.duckduckgo.com/iat/software/firefox/?platform=linux&license=free"></script>
+</body>
+</html>
View
49 alternative_to/spice.js
@@ -0,0 +1,49 @@
+d = document;
+function nrat(alts)
+{
+ // console.log(alts);
+ var out, tmp;
+ out = "";
+
+ // validity check
+ if (alts['Items']) {
+
+ for (i in alts['Items']) {
+ var item = alts['Items'][i];
+
+ wrapper = d.createElement("div");
+ box = d.createElement("div");
+
+ link = d.createElement("a");
+ link.href = item['Url'];
+ link.innerHTML = item['Name'];
+
+ img = d.createElement("img");
+ img.src = item['IconUrl'];
+
+ box.appendChild(img);
+ box.appendChild(d.createElement("br"));
+ box.appendChild(link);
+
+ YAHOO.util.Dom.setStyle(box, "text-align", "center");
+
+ YAHOO.util.Dom.setStyle(box, "float", "left");
+ YAHOO.util.Dom.setStyle(box, "margin", "10px");
+ YAHOO.util.Dom.setStyle(box, "width", "60px");
+
+ wrapper.appendChild(box);
+
+ out += wrapper.innerHTML;
+
+ }
+
+ items = new Array();
+ items[0] = new Array();
+ items[0]['a'] = out;
+ items[0]['h'] = '';
+ items[0]['s'] = 'AlternativeTo';
+ items[0]['u'] = alts['Url'];
+ nra(items);
+ }
+}
+
View
1  alternative_to/spice.namespace
@@ -0,0 +1 @@
+at
View
26 alternative_to/spice.pl
@@ -0,0 +1,26 @@
+if ($q_check_lc =~ /^(?:(free|opensource|commercial))?\s*(?:alternatives?\s*to\s*)?([\w\-]+)(?:\sfor\s(.*))?$/i) {
+ #$call_extf = qq(/js/nrat.js);
+ if ($1 and $4) {
+ # license and platform specified - queries like:
+ # -> free alternative to firefox for mac
+ # -> opensource matlab for linux
+ $call_ext = qq(/iat/software/$3/?platform=$4&license=$1);
+ } elsif ($1) {
+ # lincense secified only:
+ # -> free nod32
+ # -> opensource alternative to omnigraffle
+ $call_ext = qq(/iat/software/$3/?license=$1);
+ } elsif ($4) {
+ # platform specified:
+ # -> TextMate for windows
+ # -> alternative to vim for linux
+ $call_ext = qq(/iat/software/$3/?platform=$4);
+ } elsif($2) {
+ # license and platform not specified
+ # in this case we need to match 'alternative(s) to':
+ # -> alternative to firefox
+ $call_ext = qq(/iat/software/$3);
+ }
+ $is_kill_pre_results = 1;
+}
+
Something went wrong with that request. Please try again.