OK I got my title in a text file with an evil use of sed:
Code:
cat /tmp/title.txt|tr -d "<b>/" > /tmp/title.txt |
hey you can try this one:
echo "<b> Strangers on Mars </b> <br" | grep -o "[[:alpha:]][ a-zA-Z]\+[[:alpha:]]" Edit: or this one. this is the most perfect i can suggest echo "<b> Strangers on Mars </b> <br" | sed -e s/".*<b> \{,1\}"//i -e s/" \{,1\}<\/b>.*"//i |
Quote:
In the mean time I am really proud to display my (clunky and primitive) working script - I have hacked the original around and learnt heaps and managed to title the image when it is run against this page: Code:
#!/bin/bash Will |
you're welcome and thank you too :)
if you want to learn more about bash i suggest: The Bash Beginner's Guide http://www.tldp.org/LDP/Bash-Beginne...tml/index.html or the Advanced Bash-Scripting Guide http://www.tldp.org/LDP/abs/html/ that should help you a lot |
BTW Consolebox your sed and grep worked beautifully (I settled on the sed) - thankyou for the optimisation. I have also make the temp tile a variable and used your debug section.
Just got to work out more about convert to centre the text and get it all nice and tidy. I have written date onto the title too - seemed good for a pic'o'day Code:
# set the date of the picoday |
OK guys, for the sake of completeness and to show off how proud I am of my finished product and thank you both for your help here is the script.
It is still a total mess from the POV of anyone with experience in programming and I can see that but I am happy that the final result works well and reliably for me for my application. Code:
geko dailywallpaper # cat /usr/bin/2getImg.sh Thanks for all your help - especially despawn - I am definitely on the way to knowing how to research my bash needs myself - this is what Linux Questions is all about. PS UNSPAWN: I hope you don't mind my changing of the comments - I still attribute to you for the original script but I am so stoked on the outcome and the time I have spent getting it just right I wanted to claim the latest version for myself - I could use a short lecture on the ettiquette of this if you dont mind - because if I am out of line from an opensource POV I would like to know! :) Thanks again. I am indebted to you. Also, I use convert to rewrite the file as a jpg and this seems not only to improve the quality of the display when using xloadimage but may also mean we can use other image formats not natively supported ?? Will |
that's so nice to hear from you.
hey i wonder why unspawn's no longer making a reply. i hope he's not mad at me for modifying his code. anyway congratulations dude. nice work there. :) |
OK in an effort to get the desktop in Gnome/Nautilus back I dug around in the gconftool-2 and the graphic configuration editor.
So if anyone stumbles on this some time in the future and wants to run this as a native Gnome background I have added these lines instead of using xloadimage: Code:
gconftool-2 --type string --set /desktop/gnome/background/color_shading_type "vertical-gradient" I have run into a major show stopper at this point for three reasons: 1) gnome config editing seems to be more magic, smoke, mirrors and here's hoping (what with gnome settigns daemon restarting and erroring all the time on restarting sessions :roll: ) so I can't confirm that the keys are perfect - for example: the configuration editor make the following comment about setting the picture options: Quote:
Quote:
2) I found that the cron system can't open the display - so this script is not going to cut it when using xloadimage from a crontab call.... 3) This appears to be fixed by using the gnome xml calls and punching the values in that way but for some reason I can't get it to work yet... Code:
stardotstar@geko ~ $ cat /etc/crontab Also, by writing things this way we are no longer in need of a random string - or it can be completely revised and better checks are needed to prevent wierd filenames being generated for the wallpaper directory (for use by the screensaver) so I am inclined to just get it running and then when I have more skills do a complete rewrite so that it works this way better. I prefer to use the system this way - writing to the gnome desktop - because I can get my desktop icons and possibly call it from cron... thoughts and contributions naturally appreciated but if this thread turns into a personal blog then that is just as cool :) Will |
OK here is the current Gnome Version - still messy but does a good job when incorporated with the cron call I have also copied:
Code:
stardotstar@geko ~ $ cat /usr/bin/2getImg.sh Code:
39 22 * * * stardotstar sh -x /usr/bin/2getImg.sh http://antwrp.gsfc.nasa.gov/apod/astropix.html > /tmp/getimg.log |
Yesterday and today's pics on the astronomy site demonstrated that the image on the main page is not going to cut it and I set about grabbing the larger image. I also sorted out the problem with ' in the titles and subsequent script lines and file names.
At consolebox's suggestion I made many things variables - though imperfect for sure. I couldn't get my if then else loop to work with a flag set for big=0/1 so that one could specify if you want the big image or the one from the main page... I have some work and research to do :) anyway it works pretty well and as a cron job too so here is the current and relatively finished gnome version: Code:
cat /usr/X11R6/bin/2getImg.sh Will |
Need to raise the dead on this one:
I am finding that the script fails to grab the title from the page reliably. I can't fathom why but mostly I find that the file fails to get a title (and subsequently save with the correct file name) but I always get the daa te and other text. Something must be going on in the sed of the title section. I don't know what it is - often it works second time around. Can someone please have a quick look at this statement and suggest why: Code:
Code:
wget -O - http://antwrp.gsfc.nasa.gov/apod/astropix.html Code:
stardotstar@spitfire /tmp $ cat /usr/local/bin/2getImg.sh Hmmm. Will |
hi
that's a good effort in bash. However there are modules out there that makes parsing html pages easy, eg in Perl, there are modules like LWP, or in Python, you can use urllib2 and BeautifulSoup module. eg a snippet >>> import urllib2 >>> from BeautifulSoup import BeautifulSoup >>> info = urllib2.urlopen("http://antwrp.gsfc.nasa.gov/apod") >>> htmlsource = info.read() >>> soup = BeautifulSoup(htmlsource) >>> soup.head.title <title>Astronomy Picture of the Day </title> >>> soup.findAll('img') [<img src="image/0609/m46m47_hetlage.jpg" alt="See Explanation. Clicking on the picture will download the highest resolution version available." />] For examples on Perl LWP you can see here http://www.perl.com/pub/a/2002/08/20/perlandlwp.html just a suggestion for your future web projects..;) |
Need to raise the dead on this one
Nice to see you expand stuff, though it does need a bit of tending to, like what you're doing here: Code:
# grep and write the title to a text file and then sed out the unwanted stuff - contributed by konsolebox and update by stardotstar to handle ' ;) Code:
# 0. grab string to file Code:
# 0. grab string, string ops and write to file Code:
# 0. Grab string to array: |
Perfect UnSpawn ! Thanks heaps. Titles are coming in consistently and file names are cleaning up great!
Will |
All times are GMT -5. The time now is 02:00 AM. |