View Full Version : Little script for checking ADDF for new posts


SweetCode
01-25-13, 04:38 PM
Since sometimes I lose a lot of times checking on ADDF for posts that I am interested in seeing new posts , but not to the point of subscribing, I made a little script to notify me about new posts at ADDF.

Since it doesn't download images it's probably better for the server than me hitting "newposts" every time and also prevents me from getting distracted with the forum.

I have set the script to check the new posts page every 4 minutes and to exit after 2 hours.

addforums.sh :

#!/bin/bash
################################################## ################################################## ###########
# This code is licensed under the ADDF license #
# Which means that the ADDForums.com staff can disallow the use of the code below at any moment #
# And if they disallow and you run this script, you need to pay USD $5.000 in donations for the ADDforums.com #
# You are not allowed to change the code in a way that it'll create any damage for the ADDForums.com #
# More conditions may apply for checking such conditions and if the code still allowed to be used #
# go to: http://www.addforums.com/forums/showthread.php?p=1430010 :P #
################################################## ################################################## ############

useragent="Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)"
cookie_file="addf_cookie"
function logar(){
echo "Username:"
read usuario
echo "Password:"
read senha
curl -c $cookie_file http://www.addforums.com/forums/login.php?do=login -F vb_login_username=$usuario -F cookieuser=1 -F vb_login_password=$senha -A "$useragent" -F securitytoken=guest -F do=login -L --silent > /dev/null
}

function check_logado(){
userid=`grep bbuserid $cookie_file`
logado=${#userid}
}


if [ ! -s $cookie_file ]
then
echo "Logging"
logar
fi

if [ -s $cookie_file ]
then
check_logado
while [ $logado -eq 0 ]
do
echo "Something went wrong , please login again:"
logar
check_logado
done
fi

echo "Logged , starting downloading posts, it'll run for 2 hours downloading every 4 minutes."
for counter in `seq 30`
do
touch new_posts
mv new_posts posts
curl --silent -L -b $cookie_file -e http://addforums.com/forums/index.php http://addforums.com/forums/search.php?do=getnew -A "$useragent" | grep thread_title | cut -f2 -d\> | cut -f1 -d\< > new_posts
diff posts new_posts | grep \> | sed s/^.//g > notify
[ -s notify ] && notify-send "New posts at addforums" "`cat notify`"
sleep 240
done
echo "End of time, exiting for saving ADDF Server resources"


It depends on:
curl and notify-send.

Notes:
This script will not store your username and password in a file, but will store a cookie from the server allowing it to connect without typing user and password every time.

I haven't created any checking mechanism so if the cookie expires or something like that , just delete the cookie file.

Also the notification daemon isn1't the most stable thing on the world , if it stops working just "pkill notification-daemon" and it'll restart automatically.

Please , remember that our good friends admins pay for the server and bandwidth, I created this script to make my life easier and to stop wasting server resources refreshing the getnew page on my browser like a freak , so don't abuse the server and don't let the script running overnight...

:)

namazu
01-25-13, 05:02 PM
Or, you could subscribe to the RSS feed.

I think this one gives new posts http://www.addforums.com/forums/external.php?lastpost=true&type=rss
And this one gives new threads http://www.addforums.com/forums/external.php?newpost=true&type=rss

But I'm not entirely sure about the time-lag or whether it works well. Haven't tested it yet.

EDIT: Oh, hey! The RSS2 feed seems to be much quicker to update! http://www.addforums.com/forums/external.php?lastpost=true&type=rss2

SweetCode
01-25-13, 05:07 PM
Why on earth would I subscribe the feed when I can use that script? :P

Now seriously, I really hate rss...

yep ,took a look at the RSS considering using it as the source for the notification but lag is too big for the objective of the tool.

namazu
01-25-13, 05:08 PM
I dunno. Whatever floats your boat and doesn't crash the site... :D

SweetCode
01-25-13, 05:11 PM
Crashing the site? no way, I don't have 5.000 USD to spend like that :lol:

namazu
01-25-13, 05:30 PM
Did you see my edit re: RSS2 feed being faster? I'm posting again just to check it out...will report back in 5...4...3...2...

Hmm...something's weird. I'm not sure whether the settings are correct.

SweetCode
01-25-13, 05:45 PM
I was checking it since it would be really lighter on the server but *apparently* it has a TTL of 60 minutes and only returns a few items (it doesn't show every post that were posted on the 60 minutes).

part of the header of the RSS:
< lastBuildDate >Fri, 25 Jan 2013 21:27:24 GMT< /lastBuildDate >
< generator >vBulletin< /generator >
< ttl >60< /ttl >

I will check it if it grabs all the posts in the last hour , if it does, it will be much easier to change the code to check every hour the RSS and make the tool check at desired threads every 4 minutes, that way it'll not spend resources with the search (it's a search on a indexed field ordered by the last ones and all... but still a search unless it's cached but I don't have time to look at vBulletin source code now... ) and I will be able to let it running full time (a modified RSS reader with a thread temporary monitoring feature...).

dasikins
02-26-13, 11:37 PM
Nice!

anonymouslyadd
02-27-13, 12:26 AM
Or, you could subscribe to the RSS feed.

I think this one gives new posts http://www.addforums.com/forums/external.php?lastpost=true&type=rss
And this one gives new threads http://www.addforums.com/forums/external.php?newpost=true&type=rss

But I'm not entirely sure about the time-lag or whether it works well. Haven't tested it yet.

EDIT: Oh, hey! The RSS2 feed seems to be much quicker to update! http://www.addforums.com/forums/external.php?lastpost=true&type=rss2
How do you use the xml tree to convert to RSS?

someothertime
03-26-13, 06:21 AM
From the moment i saw #!/bin/bash ......I was in looooove!!!

SweetCode
03-28-13, 10:30 PM
My script so young and already dealing with love, they grow so fast :lol: