#!/bin/csh -f # # Brent Chivers 2005/Feb/13 # # Create a collage of userpics from your friends' LiveJournal accounts. # Output is HTML that can be pasted into a LiveJournal post. # Turn off LJ preformatting or else you'll get one picture per line. 8-( # # After the rewrite of 2006/Feb, this may not paste cleanly into # a journal entry. (It works for updating a page on my web site.) # # You need to save this to local disk and view it with an editor. # If you're looking at it with a browser, there's stuff in here # that your browser may interpret as HTML, so you may not see # what's really here. (So don't use copy/paste to copy it!) # # This code works under MacOS X 10.2. It should work under # (or port easily to) other flavors of Unix. If you have # questions I will be glad to try to help. (That sed and # awk stuff on the actual URL retrieval is UGLY.) # # This script was placed on the web pretty much as soon as # it was functional. There were several improvements in # the first 24 hours, and a few since then. You should check # here http://bdchivers.home.comcast.net/lj/lj.collage.txt # again before you run it to be sure you've got the latest # and greatest. # # If the userpic comments contain double-quote (") characters, # the HTML this script produces will make LJ unhappy. # (But after you post, LJ will give you a pretty good clue # where the error is and you can find it and clean it up. # # Change the header line of friends names to LJ-User tags. 2005/Feb/14 # (This turned out to simpler than I thought. I thought I # would need to keep track of user/community/feed types, # but LJ will do that for me. Just one tag type! ;-) # # There's a line below to uncomment if you want # your collage to start each friend on a new line. # # There's a line below to uncomment if you want a # LJ-User tag preceeding each friend's set of icons. # # lpetrazickis's friends list revealed a bug. 2005/May/15 # Filter [DEL: :DEL] sequences out of the accounts info page, # so we don't think we're out of the Friends section of info. # Pick up entries from the "Also Friend of:" section. # (I think that was added to the account-info page after I wrote this.) # # LJ's user's-icons page has changed. 2006/Feb/08 # REWRITE IN PROGRESS.... # # Set up internal links to friends' icons. 2006/Feb/11 # # Rewrite made little tables for each icon so I could associate text # (first part of keywords) with them. I couldn't get little tables to # flow like text, so I had to turn each row of tables into a table of # tables. These look good on my screen (1024x768) at 8 icons/row, so # that's how it's set. (Sorry, but I don't know how to make it adapt # to screen size.) # This is much more complex than it used to be. It now finds any URLs # provided with the icons (either already on the icon or in the keywords) # and uses them to make the images into links on my collage. aliza250 # and aome had complex things going on with their icons. # And the icons without keywords didn't fit my expected 2 lines of input # per icon -- image and keywords, output both when you get keywords. # # Image URLs may be http://www.livejournal.com/userpic/ BDC 2007/Mar/12 # OR http://userpic.livejournal.com/. # "userpic" string is no longer surrounded by "//". # # LJ account-userpics page has changed. Links are now BDC 2008/Apr/08 # http://p-userpic.livejournal.com/ instead of http://userpic.livejournal.com/. # # LJ account's profile page changed a few months back, BDC 2009/Jan/23 # so finding the account's list of friends must change to match. # # Userpic URLs have changed from BDC 2009/Apr/12 # from http://p-userpic.livejournal.com/ # to http://l-userpic.livejournal.com/ # the next two lines can be uncommented for diagnostics # set verbose # see commands before variable substitution # set echo # see commands after variable substitution unset histchars # get user's history characters out of the way unalias * # get user's .cshrc stuff out of the way ## set nonomatch # don't require wildcard matches set cmd_name = $0 # $0:t construction doesn't work! set cmd_name = $cmd_name:t # the name of this command if ($#argv != 1) then # none or multiple arguments provided echo "usage: $cmd_name lj_acct" exit # I don't think it makes sense to run this for multiple endif # accounts. If you disagree, "foreach acct ($*)".... set acct = $1 # LJ account # Much of this script was taken from another script that # looped through multiple accounts. Rather than changing # "$acct" to "$1" everywhere, I opted to "set acct". # Get the account's friends from the user-info page. # URL for full user info. # Remove leading blanks from page retrieved. # Any blank line, ":", or "[" means we're starting a new info section. # The sections we care about say "Friends", "Also Friend of", "Watching", or "Member of". # ("Mutual Friends" is a subset of "Friends", and "Member of" is a subset of "Watching".) # Entries within the sections are always lower case, so they won't confuse us. # Put each entry on a separate line. # Remove spaces and commas. /usr/local/bin/lynx -dump -nolist -pseudo_inlines 'http://www.livejournal.com/userinfo.bml?user='"$acct"'&mode=full' | sed -e 's/^ *//' -e 's/\[DEL://' -e 's/:DEL]//' | tee temp.lj.profile | awk '\ /^$/ { friends = 0 } \ /:/ { friends = 0 } \ /\[/ { friends = 0 } \ /^Friends \(/ { friends = 1 ; next } \ /^Also Friend of \(/ { friends = 1 ; next } \ /^Watching \(/ { friends = 1 ; next } \ { if (friends) {print} }' | fmt -1 | tr -d ' ,' > /var/tmp/$cmd_name.$$ # Set list of friends. # csh will choke if there are too many friends. # But if there are that many, the collage would probably be too big to post. set friends = `cat /var/tmp/$cmd_name.$$` # Show the number of friends and make LJ-User tags for them all. # (No, make internal links within this page now.) echo "$#friends Friends:" foreach friend ($friends) # echo "" echo ''$friend' ' end # echo '
' echo '
' # Find each friend's acct's userpics. # echo an ANCHOR tag to match the links created above. # echo a link to the LJ User Profile (full). # Optional line echos a LJ-User tag before each friend's userpics. # Grab all the userpics URLs for each friend. Re-format the HTML output: # Combine everything into one line. # Break the line in front of each table element -- icon image, keywords: # Put a "^" in front of each tag, and the translate each "^" to a newline. # Drop the line with "Current Userpics" between tags. # Remove the table-element closing tag and the rest of the line. # Remove the table-element opening tag. # Keep the lines that contain "userpic" (it's part of the URL) or "Keywords:". # Modify the default icon's keyword. # Remove the tagged word "Keywords": # Look for a LJ user-profile tag; copy it as a new field (^) at the end of the keywords. # Replace the break in the keywords with a "^" for AWK to use. # find 'ed URL and LJ-user from aome's fancy keywords; leave just LJ-user; (profile URL already duplicated at end) # [AWK] # output any icon already seen that didn't have keywords. # save the icon URL and attributes; also the icon may already be a link, capture that. # split the keywords into name and description (and possibly added profile URL) # look for a URL on the keywords line # create a small table with the icon and the first part of the keywords (possibly including "default"). # if there was a URL in the keywords, make the image a link to the URL. # make the 2nd part of the keywords the ALT and TITLE tags of the image, if data is provided. # specify align=left to keep multiple tables on one line. # after 8 icon-tables (16 lines of input), break the line by starting a new table. # output last icon if it didn't have keywords. # [AWK done] # the ALT/TITLE tag's delimiters are double quotes. If any friends have put double quotes in their key words, # this HTML will post but it won't display. (LJ will give you a good idea where the error is.) foreach friend ($friends) echo -n '' # anchor tag for each friend # echo -n '' # UNCOMMENT this line if you want a LJ tag echo -n "${friend}:" echo -n ' icons' echo -n ' profile' echo -n ' journal' echo -n ' friends' echo '
' echo -n '' # start a new row-table for each friend /usr/local/bin/lynx -source 'http://www.livejournal.com/allpics.bml?user='"$friend" | tr -d '\012' | sed -e 's/.*==' -e 's/]*>//' | egrep '/l-userpic|>Default<|>Keywords:<' | sed -e 's=Default
Keywords: =(default) =' -e 's=Keywords: ==' -e 's=
.*\(http://.*.livejournal.com/profile\).*=&^\1=' -e 's=
=^=' -e 's===' -e 's===' | awk '\ /^]*>
==g' | tr '^' '\012' | grep -v '>Current Userpics<' | sed -e 's=
") ; \ if ( u1 ) { printf ("", url) } \ printf ("", src, width, height) ; \ if ( u1 ) { printf ("", url) } \ printf ("
\n") } \ src = $3 ; width = $4 ; height = $5 ; alt = $6 ; border = $7 ; \ u1 = match ( $0, "[Hh][Tt][Tt][Pp]:[^ '"'"'^]*" ) ; \ if ( u1 ) { url = substr ( $0, RSTART, RLENGTH ) } \ unprinted = 1 ; next } \ /^
") ; \ if ( u1 ) { printf ("", url) } \ printf ("", src, width, height) ; \ if ( u1 ) { printf ("", url) } \ printf ("
\n") } \ src = $2 ; width = $3 ; height = $4 ; alt = $5 ; border = $6 ; unprinted = 1 ; next } \ /^
") ; \ if ( u1 ) { printf ("", url) } \ printf ("", src, width, height) ; \ if ( u1 ) { printf ("", url) } \ printf ("
\n") } \ src = $2 ; width = $3 ; height = $4 ; alt = $5 ; border = $6 ; unprinted = 1 ; next } \ { split ($0, line, "^") ; \ u2 = match ( $0, "[Hh][Tt][Tt][Pp]:[^ ^]*" ) ; \ if ( u2 ) { url = substr ( $0, RSTART, RLENGTH ) } \ printf ("
") ; \ if ( u1 || u2 ) { printf ("", url) } \ printf ("\"%s\"") ; \ if ( u1 || u2 ) { printf ("", url) } \ printf ("
%s
\n", line[1]) ; \ unprinted = 0 } \ { if (NR && ((NR % 16) == 0)) { printf ("\n") }} \ END { if (unprinted) { \ printf ("\n") } \ printf ("
") ; \ if ( u1 ) { printf ("", url) } \ printf ("", src, width, height) ; \ if ( u1 ) { printf ("", url) } \ printf ("

\n") }' end /bin/rm /var/tmp/$cmd_name.$$ exit