Got Habits (wetnun) wrote in lj_nifty,
Got Habits

  • Mood:
  • Music:

PHP script to get interests and random images

So after looking at ga_woo's thing it occurred to me that there had to be a decent way to get interests from users accounts and images for those interests.

So I created a bare script for people who are interested in building something like what ga_woo was doing. I could probably host something like this if someone builds something interesting.

Source Code

Basically the script does this:

Check if users interests are not cached
If not then
  1. Get users FOAF data
  2. Parse out array of interests
  3. cache data
Foreach interest
check if interest image array is cached
if not then
  1. get google images page (I send full headers)
  2. parse out array of possible images
  3. cache data
print out random image for that interest

If you hadn't noticed I like caching. The script currently will cache for 5 hours. It will keep checking if the cache is empty though. I'm sure it could be improved but it was a quick hack before going to bed.  If I left any debugging code in or forgot to remove some hard coding just let me know.  But if you know enough to point it out then it shouldn't be an issue for you.  :)

From what I could tell the FOAF works for everyone as I tried a couple non-paid friends accounts and it seemed to work.  And google will think the script is Firefox connecting to their servers.  I even give them a referrer on their site.  Should probably make that the prior interest or something for better hiding on their side.

Not bad for 4K.
  • Post a new comment


    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded