Deploy Weather APP on RaspberryPI

Since I enabled the RaspberryPI and disabled the PogoPlug, I have to move the Weather App on RaspberryPI. The main difference lies on the python version, on PogoPlug the default python version is python2.7, while on RaspberryPI it’s python3.3, thus I have to use the virtualenvironment of Python.

###Setup the virtualenv Following is the steps for setting up the virtual environment for python2.7 on ArchLinux:

	$ mkdir ~/pyves
	$ cat >~/.virtualenvrc <<EOF
	export WORKON_HOME="$HOME/pyves"
	export PROJECT_HOME="$HOME/pyves"
	source /usr/bin/virtualenvwrapper.sh
	EOF
	$ source  ~/.virtualenvrc
	$ cat >>~/.bashrc <<EOF
	source $HOME/.virtualenvrc
	EOF
	$ mkvirtualenv --python=/usr/bin/python2.7 v27
	$ workon v27
	$ pip install pywapi django sqlite3

###Deployment Python Script Copy the script to some directory, mine is under /root/code/weather. If we want cron to call the virtual environment, we have to create a script and in the script to call the python script.

	#!/bin/bash
	# Export everything.
	source /root/.bashrc
	# Change to the virtual environment
	workon v27
	# Call python
	python /root/code/weather/genhtml.py

Now we add this script to crontab, at every whole point, each hour it will run once.

	crontab -e
	0 */1 * * * /root/code/weather/NJ.sh
	15 */1 * * * /root/code/weather/BJ.sh
	30 */1 * * * /root/code/weather/CS.sh

Now at every 0/15/30, our cron job will be run, and retrieve the data generate the flot image for displaying.

Miragating from ASP to Wordpress(2)

Recent days I am doing a data migration from asp website to WordPress, Following is how-to. ###Database First we have to download the whole website content from the server, in my situation, the website contains a database called “xxxx.mdb”, I downloaded this database and renamed its name to “origin.mdb" We can use Microsoft Access for opening this database file, and from the left side panel we can see all of the tables. We know the about/news1/news2/news3/news4 table which contains the actual webpages content. We can see the picture of news1 which displayed as following: /images/tablesInAccess.jpg ###CSV Preparation In a Ubuntu machine, we install mdbtools via following command:

	$ sudo apt-get install mdbtools

Export the specified tables from the mdb file:

	$ mdb-export origin.mdb news > news.csv

The CSV file is seperated via semicolon, just linke following:

	$ cat news.csv
	id,title,entitle,url,body,enbody,zz,hit,data,ssfl,img,ly,enly,color,encolor,tuijian,px_id,pass,kin
	58,"关于海外游学",,,"<DIV><B><FONT size=2 face=Arial>关于游学</FONT></B></DIV>
	<DIV><FONT size=2><FONT face=Arial><STRONG></STRONG><B></B></FONT></FONT>&n
	............

Now the news.csv contains all of the content which contains in the news table. ###WordPress Plugins Installation Install the WP Ultimate CSV Importer for importing the csv into the WordPress: This Plug-ins is fairly frendly, we simply upload the csv onto the plug-in, the plugin will analyse the csv’s content,and begin to mapping the database fields. /images/csvimport.jpg

Notice: You can import the csv into posts or pages, here I choose “Pages”, and it got the Parent Pages, so first you have to create the parent page, just as following: /images/parentpage.jpg

The content of parent page named “[child_pages]” is also another plug-in, this plug-in is called “Child Pages Shortcode”, after installed it, you can get the “screenshots” of the child pages. The actual effects is listed as following picture: /images/childpageshot.jpg

Another plug-in is called “Children Index Shortcode”. This plug-in will generate all of the child pages’ hyper-links. You can call this plug-in via insert “children-index” into the content of the parent page. ###Change The Theme You can easily install themes in wordpress, via Appearence->Theme. Currently I use “BlackBird Wordpress Theme”, the default suport of chinese is pretty good. Things to be do:

  1. Check all of the images.
  2. Beautify the pages.
  3. Customize the pages.

Migrating from ASP to WordPress(1)

Recently I will moving an old-style website from ASP to WorldPress, that’s a funny work. This series will record the steps for migrating. ###Preparation First I got all of the files which locates in the ASP.NET Server, the database is very simple, it’s a mdb file, which could be viewed by Microsoft Access.

The static files and images could also be downloaded from the server, thus the materials is enough for building a whole-new WorldPress based website.

###Using Python To Generate Content All of the webpage information are located in the mdb file, thus we have to do some dealing with this database file. Python could easily retrieve the data out from the database. Install pyodbc:

	$ pip install pyodbc

Notice when you are using Microsoft Access for visiting the database, the system will automatically generate a ldb file for you.

In Linux, the pyodbc will encouter un-predicted problems, so I use ActivePython in Windows for analyzing the mdb file.

	$ pypm search pyodbc
	$ pypm install pyodbc

Now begin to analyse the database

TBD

Trouble-Shotting on Wordpress

Since the Wordpress is located at home, there are several problems for dealing with. ###Changeing Apache Listening Port Nanjing Unicom has banned the port 80, thus I have to change the default listening port of apache from 80 to other ports. Following is How-To: First import an variable in /etc/apache2/envvars:

	export VHOST_PORT_HTTP=7777

Then Change the /etc/apache2/ports.conf:

	# NameVirtualHost *:80
	# Listen 80
	NameVirtualHost *:${VHOST_PORT_HTTP}
	Listen ${VHOST_PORT_HTTP}

Finally change the site-enabled:

	root@arm:/etc/apache2# cat sites-enabled/000-default
	<VirtualHost *:${VHOST_PORT_HTTP}>

Now restart the apache2 service, you should see the apache listens the 7777 port.

	/etc/init.d/apache2 restart

###Configurating the WordPress Install this light-weight browser for changing configurations.

	pacman -S midori

After remote login with “ssh -Y”, simply input:

	midori 

Then you can get a local window. But wait, midori relies on window, but we’d better do everything in command-line for savign the bandwidth, thus we install the elinks, and use it for configurating the wordpress.

	$ apt-get install elinks

You have to change the configuration->General, from http://xxx.xxx.xxx.xxx to http://xxx.xxx.xxx.xxx:7777, then we can change the port and let it show in browser.

Now you can access the wordpress in everywhere.

Customize Wordpress on BeagleBone Black

For Using proxy for Wordpress, we can directly edit the wp-config file:

	$ cat wp-config.php
	/** Set following for working behind the proxy **/
	//define('WP_PROXY_HOST', '10.0.0.221');
	//define('WP_PROXY_PORT', '9001');
	#define('WP_PROXY_BYPASS_HOSTS','*.local-intranet');
	##
	define('WP_EMMORY_LIMIT', '64M');

A trouble shooting, you have to edit the /etc/resolv.conf to change the default dns server, then your wordpress could reach the network and install new plugins or themes.