Skip to content
This repository

Alternative to #8

Merged
merged 4 commits into from about 2 years ago

3 participants

Marek Šuppa Gabriel Weinberg Hunter Lang
Marek Šuppa
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.

added some commits November 22, 2011
Marek Šuppa first commit for alt.to b9f746c
Marek Šuppa first version of alternativeto.net spice 38fb59b
Marek Šuppa Added (probably) working spice.pl 8f7e6ca
Marek Šuppa 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
Gabriel Weinberg
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?

Hunter Lang
Collaborator

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

Hunter Lang hunterlang merged commit 7f18662 into from March 13, 2012
Hunter Lang hunterlang closed this March 13, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 4 unique commits by 1 author.

Nov 22, 2011
Marek Šuppa first commit for alt.to b9f746c
Nov 25, 2011
Marek Šuppa first version of alternativeto.net spice 38fb59b
Marek Šuppa Added (probably) working spice.pl 8f7e6ca
Nov 28, 2011
Marek Šuppa 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
This page is out of date. Refresh to see the latest.
19  alternative_to/spice.html
... ...
@@ -0,0 +1,19 @@
  1
+<!doctype html>
  2
+<html>
  3
+<head>
  4
+	<meta charset="utf-8">
  5
+	<title>Alternative.to test</title>
  6
+  <script src="spice.js"></script>
  7
+  <script type="text/javascript">
  8
+    function nra(items) {
  9
+      document.getElementById('a').innerHTML = items[0]['a'];
  10
+    }
  11
+  </script>
  12
+</head>
  13
+<body>
  14
+  <div id="a"></div>
  15
+  <script src="http://yui.yahooapis.com/2.9.0/build/yahoo/yahoo-min.js"></script>
  16
+  <script src="http://yui.yahooapis.com/2.9.0/build/dom/dom-min.js"></script>
  17
+  <script src="http://thor.duckduckgo.com/iat/software/firefox/?platform=linux&license=free"></script>
  18
+</body>
  19
+</html>
49  alternative_to/spice.js
... ...
@@ -0,0 +1,49 @@
  1
+d = document;
  2
+function nrat(alts) 
  3
+{
  4
+  // console.log(alts);
  5
+  var out, tmp;
  6
+  out = "";
  7
+  
  8
+  // validity check
  9
+  if (alts['Items']) {
  10
+
  11
+    for (i in alts['Items']) {
  12
+      var item = alts['Items'][i];
  13
+      
  14
+      wrapper = d.createElement("div");
  15
+      box = d.createElement("div");
  16
+
  17
+      link = d.createElement("a");
  18
+      link.href = item['Url'];
  19
+      link.innerHTML = item['Name'];
  20
+
  21
+      img = d.createElement("img");
  22
+      img.src = item['IconUrl'];
  23
+      
  24
+      box.appendChild(img);
  25
+      box.appendChild(d.createElement("br"));
  26
+      box.appendChild(link);
  27
+      
  28
+      YAHOO.util.Dom.setStyle(box, "text-align", "center");
  29
+
  30
+      YAHOO.util.Dom.setStyle(box, "float", "left");
  31
+      YAHOO.util.Dom.setStyle(box, "margin", "10px");
  32
+      YAHOO.util.Dom.setStyle(box, "width", "60px");
  33
+
  34
+      wrapper.appendChild(box);
  35
+
  36
+      out += wrapper.innerHTML;
  37
+
  38
+    }
  39
+    
  40
+    items = new Array();
  41
+    items[0] = new Array();
  42
+    items[0]['a'] = out;
  43
+    items[0]['h'] = '';
  44
+    items[0]['s'] = 'AlternativeTo';
  45
+    items[0]['u'] = alts['Url'];
  46
+    nra(items);
  47
+  }
  48
+}
  49
+
1  alternative_to/spice.namespace
... ...
@@ -0,0 +1 @@
  1
+at
26  alternative_to/spice.pl
... ...
@@ -0,0 +1,26 @@
  1
+if ($q_check_lc =~ /^(?:(free|opensource|commercial))?\s*(?:alternatives?\s*to\s*)?([\w\-]+)(?:\sfor\s(.*))?$/i) {
  2
+    #$call_extf = qq(/js/nrat.js);
  3
+    if ($1 and $4) {
  4
+        # license and platform specified - queries like:
  5
+        # -> free alternative to firefox for mac
  6
+        # -> opensource matlab for linux
  7
+        $call_ext = qq(/iat/software/$3/?platform=$4&license=$1);
  8
+    } elsif ($1) {
  9
+        # lincense secified only:
  10
+        # -> free nod32
  11
+        # -> opensource alternative to omnigraffle
  12
+        $call_ext = qq(/iat/software/$3/?license=$1);
  13
+    } elsif ($4) {
  14
+        # platform specified:
  15
+        # -> TextMate for windows
  16
+        # -> alternative to vim for linux
  17
+        $call_ext = qq(/iat/software/$3/?platform=$4);
  18
+    } elsif($2) {
  19
+        # license and platform not specified
  20
+        # in this case we need to match 'alternative(s) to':
  21
+        # -> alternative to firefox
  22
+        $call_ext = qq(/iat/software/$3);
  23
+    }   
  24
+    $is_kill_pre_results = 1;
  25
+}
  26
+
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.