Quantcast
Channel: DiKnows. » Uncategorized
Viewing all articles
Browse latest Browse all 10

Wikipedia daily featured article

$
0
0

Today, while thinking of me reading always about technicality, career improving and novels only. I liked to have a source of knowledge in every possible field. First thing to pop into my mind was Wikipedia. I like wikipedia, the project never failed me.

I knew that there is always a fresh daily featured article, and I have always wished to be able to read it daily, but I fail to remember to open wikipedia to read the article. Sometimes, I get lazy as well.

I thought, why not to create a simple script to open it daily for me; using cron jobs.

Then, I thought, If I can get the URL of the featured article directly, why don’t I send it to Readability service, to refine the contents.

Thinking, And Thinking.. Then coding .. I produced this simple script, and did my best to make it compatible with both Linux and Mac OSX.

If you like to use it, distribute it, you are most welcome.. You can also add comments telling me how to refine it or fix some issues you faced.


#!/bin/bash
#
# A script to get today's featured article or a random article from wikipedia
# pass it to readability and open the browser to read it 

## The browser to use to open the link
base_browser='google-chrome'

# Displays messages
function display(){
	echo '------------ DiKnows ------------';
	echo "$1";
	echo '----Http://www.diknows.com/----';
}

# Set Script variables based on Operating System detected
function setOSVars(){
	local unamestr=`uname`;
	local platform='unknown'
	if [[ "$unamestr" == 'Linux' ]] ; then
		browser=$base_browser;
		wp='/usr/bin' 
	elif [[ "$unamestr" == 'FreeBSD' ]]; then
		browser=$base_browser;
		wp='/usr/bin'
	elif [[ "$unamestr" == 'Darwin' ]]; then
		browser='open';
		wp='/opt/local/bin'
	else
		exit 1
	fi
}

# Gets wikipedia featured article
function getFeaturedLink(){
	# Generate today's date to work with wikipedia
	d1=`date +"%B_"`;
	d2=`date +"%e"`;
	d3=`date +",_%Y"`;
	article_date="$d1`echo $d2`$d3";
	# Create wikipedia link for the featured article brief
	article_url="http://en.wikipedia.org/wiki/Wikipedia:Today%27s_featured_article/$article_date"
	$wp/wget -q -O /tmp/wiki.html $article_url
	tidy -m /tmp/wiki.html
	clear
	tmp=`cat /tmp/wiki.html | grep '

You can download the script directly here.

For dummies, to run this script you must have Linux or MacOSX.

Open a terminal then cd to the directory containing the script.
Then you should execute the following command


bash wiki-random.sh

To add it to crontab, so that it gets executed daily, at 11pm, edit the crontab using


crontab -e

Then add the following line


45 11 * * * /bin/bash ~/Downloads/wiki-random.sh

Where ‘~/Downloads’ is the download folder in your home directory ( where you should have stored the script ) .

Wish you best of luck

If you have any questions, suggestions or know some fixes, please, comment on the post.


Viewing all articles
Browse latest Browse all 10

Trending Articles