Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

A different approach for bookmarks.

by atlantageek (Monk)
on Nov 19, 2001 at 08:39 UTC ( [id://126210] : CUFP . print w/replies, xml ) Need Help??

Most programmers use multiple computers (at home and work) and it is often difficult to share bookmarks. You can email links to the home and office, you can use a bookmark sharing website (often requiring you to either go to the site and add the bookmark or downloading a windows only program).

I like my solution better. If you have your own cgi running website you can set up an email account that you can send your links too. Then write a perl script similar to the one below that can be run by a cronjob to rip links out of the email and save them to a flat file or database for the your website to display. The advantage in this approach is that just about all browsers have a email link option that is convient and easy to use. Here is a simple perl script that writes the links too a file.

Other possible features that could be added:
1. Using LWP to grab the title of the page.
2. Categorizing the link. Maybe the link can go into a holding area to be categorized later or you can use the subject line of the email to specify the category.

#!/usr/bin/perl use Mail::POP3Client; use strict; use Misc; #Creating PopMail Object my $pop = new Mail::POP3Client( USER => "RESU", PASSWORD => "DROWSSAP", HOST => ""); my @linkList=slurp(""); for (my $i=1; $i <= $pop->Count(); $i++) # Loop through messages { my $body = $pop->Body($i); while ($body =~ s/(http:\/\/[^\s]*)//) { push @linkList, $1; print "$1\n"; } $pop->Delete($i); } $pop->Close(); dumpOut("", @linkList); exit 0; ########################### sub slurp { my $file =shift; my $save = $/; undef $/; open FIL, "$file"; my $input= <FIL>; close FIL; my @list = split /$save/, $input; $/ = $save; return @list; } sub dumpOut { my $file = shift; open FIL, "|uniq >$file"; while(my $content = shift) { print FIL $content, "\n"; } close FIL; }

I always wanted to be somebody... I guess I should have been more specific.

Replies are listed 'Best First'.
Re: A different approach for bookmarks.
by belg4mit (Prior) on Nov 19, 2001 at 09:58 UTC
    While not a bad solution I personally prefer Roaming access via mod_roaming. Though I still end up shoving around 280k of bookmarks.

    Recently to alleviate some of this load I have been trying to not bookmark software (the biggest culprit). Instead (horrors!) I use this as a link on my personal toolbar.

    javascript:document.location=' +e='+escape(document.title)+'&URL='+escape(document.location)
    This sends the relevant data in a query string to a custom Webmin module I wrote. Where I can expound upon the link in more detail and finally dump into MySQL (uses EZDBI/EZDBI, tres cool). The final results of which can be accessed here. I think it's a pretty good solution though not complete as I currently do not have a system for managing links in the database.

    So in the end I guess the releavnt bit is, why not allow posting of the links via CGI? (If SSL w/ 401 authentication or trusted IP dump them straight in, else queue them in a spool to be verified). For me the biggest obstacle in using any other bookmark system is that it must be not much more complicated; read different from accquired habits; than C-d (or whaterver the add bookmark shortcut is for you browser/platform combo). If you allow CGI submissions as well then you use a similar bookmark. Come to think of it how about this for a personal toolbar link for your system as it is:

    javascript:document.location=''+doc +ument.location

    UPDATE: Changed mocha: to javascript:

    perl -p -e "s/(?:\w);([st])/'\$1/mg"

      jeffa's node made me realize I missed a few things.

      First, why do a substitution on the body string, it is unnecessary, a match is all you need.

      To use that javascript example you'd need to support URL's in the subject. So all in all I'd imagine you'd want to support a single URL in the subject (and use the body for annotation?), or one+ URL in the body (you currently support):


      my $URL = qr/(http:\/\/[^\s]*)/; #Since we use the expression twice it's nice to have it #as a variable. #[TheDamian]'s [cpan://Regexp::Common] would be useful once it #supplies URL matching #Until then you might want to expand this, it doesn't #support port numbers or FTP. for (my $i=1; $i <= $pop->Count(); $i++) # Loop through messages { #Support personal toolbar button for spontaneity linking foreach( $pop->Head($i) ) { #If you wanted to get fancy you could use Head in scalar #context with multi-line regexp and avoid the foreach if( /^Subject:\s+$RE/i ){; push @linkList, $1; print "$1\n"; #fetch body for description here if you want next; } } my $body = $pop->Body($i); #Just a match ma'am while ($body =~ /$RE/) { push @linkList, $1; print "$1\n"; } $pop->Delete($i); } $pop->Close();

      perl -p -e "s/(?:\w);([st])/'\$1/mg"

(jeffa) Re: A different approach for bookmarks.
by jeffa (Bishop) on Nov 19, 2001 at 22:04 UTC
    I wrote a similar script some time ago. It stored my links in a database and i set up a bookmark that used javascript so i could add the current page in one click. But that's not why i am posting. This is why i am posting:
    sub slurp { my $file =shift; my $save = $/; undef $/; open FIL, "$file"; my $input= <FIL>; close FIL; my @list = split /$save/, $input; $/ = $save; return @list; }
    After you open the file, just do this:
    my @list = <FIL>;
    No need to store $/, shove the lines into a scalar and then split em back into an array. Additionally, if you have to store the file contents into a scalar, this is a much nicer way:
    my $input = do { local $/; <FIL> };
    And, (once again!) drop this:
    for (my $i=1; $i <= $pop->Count(); $i++)
    for this:
    for my $i(1..$pop->Count())


    (the triplet paradiddle)
Re: A different approach for bookmarks.
by tstock (Curate) on Nov 19, 2001 at 11:24 UTC
    I really dont like
    open FIL, "|uniq >$file";
    how about opening the file as usual and on your while loop:
    { next if %uniq{$content}++; print FIL $content, "\n"; }
Re: A different approach for bookmarks.
by drinkd (Pilgrim) on Nov 19, 2001 at 18:56 UTC
    How about a hybrid solution.

    Instead of running the script as a cronjob, just have a submit button on the web page check the email buffer and update the links.

    I wish I knew more javascript, but might it also be possible to have a cgi program that sends the javascript to add a particular link to your local browser bookmarks? This may be not allowed for security reasons?


      It is possible but rather difficult. In Netscape this requires UniversalBrowserWrite which can only be accquired with a "Java Permissions" dialog box. I know it's possible in IE as well but I don't know if it prompts you or it it just requires really insecure settings.

      Anyways it should be hard, who wants random links to cheese factories, inkjet cartridge resellers and mortgage companies appearing in the bookmarks?

      UPDATE: Replaced 'Java Permissions dialog analog' with '"Java Permissions" dialog box'.

      perl -p -e "s/(?:\w);([st])/'\$1/mg"

Re: A different approach for bookmarks.
by hatter (Pilgrim) on Dec 10, 2001 at 21:01 UTC
    I also had the problem with not being able to get at my bookmarks very easily from various machines. So I use netscape on my external-facing machine to maintain my bookmarks (as I've not done a script to add them remotely, and that file might be in use anyhow) I set it up so it's web-accessable to anyone, because of all the times you get in conversations where every other sentence is "oh, there's a link to that in my bookmarks"

    And because I've got so many links, it folds up folders so you can explore into them.

    OTOH, there are also links and folders which are marked private (in the comment field) Straight links don't show up. Private folders show up, but aren't accessable without knowing how.

    On top of that, it runs as an SSI, you can tell it what colours to output in, and call specific folders directly. Want to add a link to the rocketry links on my website ? I just add a bookmark to the 'rocketry' folder in netscape.

    For more details, have a look at my links

    The code is rather nasty, I've been using the script for several years now (with the odd tweak between upgrades of NS) but if you want help on how to do something in your script that mine does ask, or if you just want to steal ideas, feel free. If there's lots of interest in seeing the code, I'll even finish off the rewrite I started a while ago.

    the hatter