12 Feb 2010

Love songs

#!/usr/bin/env python
# python script to download love songs from mp3.zing.vn
# hungnv
# license: Public Domain
from urllib2 import urlopen
from urllib import urlretrieve
from os import mkdir
from os.path import join, isdir
import sys
mp3_dir = "/home/hungnv/Music/"
html_source = "http://mp3.zing.vn/mp3/nghe-album/album-hot/love-song.html"
if not isdir(mp3_dir):
    try:
        mkdir(mp3_dir)
    except:
        print "cannot create directory %s" %mp3_dir
        sys.exit(1) 
def getlink():
    try:
        response = urlopen(html_source)
    except:
        print "connection error"
    response = urlopen(html_source)
    content = response.readlines()
    response.close()
    for line in content:
        a = line.find('http://dl.mp3.kapsule.info')
        b = line.find('?')
        if a <> -1 and b <> -1:
            link = line[a:b]
            c = line.find('filename') + 9
            d = line.find('alt') - 2
            filename = line[c:d]
            print "Song named %s will be downloaded at url %s" % (filename,link)
            print "Downloading.....\n"
            abs_path = join(mp3_dir,filename)
            urlretrieve(link,abs_path)
        else:
            continue
if __name__ == '__main__': 
    getlink()
exit()

27 Jan 2010

Indispensable job

I have an account named hungnv on my server - vndev.net which's running Fedora 8. If I want to remote copy, modify, delete... some files on this server , which way is faster:
1. sftp ( known as an extension of secure shell protocol - SSH ) 
hungnv@g3n2 ~ $ sftp vndev.net
Connecting to vndev.net...
sftp>
Browse local file: lls, move to local directory lcd
upload put
download get

2. sshfs (not an ssh extension, we must install fuse-sshfs to use it)
hungnv@g3n2 ~ $ eix sshfs
[I] sys-fs/sshfs-fuse
     Available versions:  1.9 ~2.1 2.2
     Installed versions:  2.2(08:46:14 AM 01/27/2010)
     Homepage:            http://fuse.sourceforge.net/sshfs.html
     Description:         Fuse-filesystem utilizing the sftp service.
hungnv@g3n2 ~ $ sudo emerge -av sys-fs/sshfs-fuse
hungnv@g3n2 ~ $ sshfs vndev.net:/ /vndev
to mount. We browse, cp, edit, delete....like local file and directory.
I didn't use sshfs until yesterday, with me, ssh and sftp are enough. But I should know sshfs and I did not know, so I fail.
We must learn what we never use =.=

22 Jan 2010

Phân hóa thu nhập từ nhiều góc nhìn

Trong một phát biểu của Trần Trọng Thức ở Tuần Việt Nam
Trong khi có những người giàu lên không bằng năng lực cũng chẳng nhờ vào thời cơ, mà nhờ vào các mối quan hệ. Hầu hết các nước kém phát triển, khi quyền lực liên kết với tư bản trong làm ăn thì phân hóa giàu nghèo càng khó giải quyết. Về mặt lý thuyết thì quyền lực chính trị là khả năng quyết định ai sẽ nhận được "cái gì" để làm ra được "cái gì" và cho ai được hưởng.
Thực tế đơn giản là thực tế :-D.

21 Jan 2010

Học python

Sửa lại chút cái shell script hồi xưa Dreammedia , viết lại bằng python.
Bạn nào dùng thì nhớ nếu tên ban nhạc hoặc album có khoảng trắng, thì thêm vào thành "band name" hoặc "album name" :).

#! /usr/bin/env python
# Script to download Music from Dreammedia.ru
# Try to find your favorite Band and Album, then use this script
# hungnv coded 
import os
import urllib2
import sys
def usage():
        print "Usage:",sys.argv[0], "\"bandname\" \"albumname\""    
        
def st_replace(string):
        new = string.replace(' ','%20')
        return new
            
def download(url,pl,band,album):
        band1 = st_replace(band)
        album1 = st_replace(album)
        temp = (url + pl[:8] + '/' + band1 + '/' + album1 + '/' + pl)
        try:
                response = urllib2.urlopen(temp)
        except:
                print 'Connection error'
        response = urllib2.urlopen(temp)
        content = response.readlines()
        for line in content:
                a = line.find('music/')
                b = line.find('.mp3')
                if a <> -1 and b <> -1:
                        path = line[a:b+4]
                        semi = (url + '%s') %path
                        final = st_replace(semi)
                        os.system('wget '+final)
                else:
                        continue
                        
if __name__ == '__main__':
        band = sys.argv[1]
        album = sys.argv[2]
        url = "http://dreammedia.ru/"
        pl = 'playlist.xml'
        if len(sys.argv) <> 3:
                usage()
                exit()
        else:
                download(url,pl,band,album)
exit()


7 Dec 2009

7-12-09

Tâm trạng đang không tốt, thật sự không tốt, chen lẫn chút nóng giận.
Đôi lúc những gì chúng ta đặt mục tiêu lâu dài không phải sẽ lâu dài, ví như tình bạn chỉ vỏn vẹn...hơn 10 năm cũng chả là cái gì :-)). Thói đời khốn nạn, khốn nạn từng giây từng phút, không thể nào ngờ được.
Cám ơn những cái nhỏ nhặt tưởng chừng nhưng vô nghĩa, nhưng nó mang lại một cái gì đó vô cùng lớn lao như tìm ra được chân lí sống sau một hồi cãi vã, lol. Chỉ là một con người. Đôi khi sống và vui đùa với những cái ảo còn hơn đối diện với những cái thực mà khó lường được chuyện gì sẽ xảy ra. Đôi khi tin vào cái ảo và rồi cái ảo đó thay đổi, mất mát không làm con ngươi ta chết đi được.

10 năm để rồi ra thế này đây, tiên trách kỉ, hậu trách nhân. Cuộc sống đang tồi đi từng ngày trông thấy, nhãm nhí, vô vị, thối nát, ảm đạm.

Vẫn kìm nén được tâm trang không chửi thề ở nơi không nên chửi thể, sao mình giả dối quá. Sống giả thế này bao lâu rồi?
Đồ đồi bại.

29 Nov 2009

[New toy] Download HD wallpaper

Last night I went around the Internet to find some good wallpapers for my 1650*1050 laptop screen, then I found a good place with many wps divided into many types, and ready to be downloaded. One problem everyone will get is they just provide link to download 1 wallpaper at a time, so this script came out :).
I'm actually not a programmer, I write script just to make thing work, then it works, that's all. If someone can make it better, please let me know.
At the end, enjoy!
update 1: python script
#/usr/bin/env python
# hungnv coded
# Usage: hdwp.py then choose type
import os
types = ['abstract', 'computer', 'nature', 'travel', 'cars', 'celerbrities', 'animal']
def _getlink(bi, num, prefix):
        address = 'http://www.hdwallpapers.net/gallery/wallpapers/'
        final = (address + '%s' + '/%s%s%s.zip') %(bi, bi, prefix, num)
        return final
def downloader(_xx_):
        link = _getlink(x, i, _xx_)
        print 'Link is: %s' %link
        osvn = 'wget '+_getlink(x, i, _xx_)+' '
        os.system(osvn)
if __name__=='__main__':
        for i in range(len(types)):
                print i+1,'.',types[i]
        x = raw_input('Choose which type of wp you want to download: ')            
        if x in types:
                for i in range(1,108):
                        if i < 10:
                                _pref = '_000'
                                downloader(_pref)
                        elif i > 9 and i < 100:
                                _pref = '_00'
                                downloader(_pref)
                        else:
                                _pref = '_0'
                                downloader(_pref)
        else:
                print 'plz choose type again'
exit()
 Usage: copy and save it whatever name you want, chmod +x then run, enter your choice, wait until it finished. Update 0: I modified to make it sorter.

#/bin/bash

#Script to Download HD wallpaper from http://www.hdwallpapers.net

#hungnv@opensource.com.vn

url="http://www.hdwallpapers.net/gallery/wallpapers/"

pref="_00"

pref1="_000"

pref2="_0"

x[1]="abstract"

x[2]="cars"

x[3]="celeb"

x[4]="computer"

x[5]="animal"

x[6]="nature"

x[7]="travel"

echo -e "\t\t\n           1. Abstract

   2. Cars

   3. Celerbities

   4. Computer

   5. Animal

   6. Nature

   7. Travel

   " 

read -p 'Enter type of wallpaper you want to download: ' type

#for j in $(seq 1 7)

for ((j=0; j&lt;8; j++))
 do
 if [ $type -eq $j ]
 then
  echo Your photo is being downloaded...
  for ((i=1; i&lt;109; i++))
   do
    if [ $i -lt 10 ] 
    then
     wget -O ${x[`echo $j`]}_$i.zip $url${x[`echo $j`]}/${x[`echo $j`]}$pref1$i.zip
      if test ! -s  "${x[`echo $j`]}_$i.zip" 
       then rm -f "${x[`echo $j`]}_$i.zip"
      fi
    elif [ $i -lt 100 ] 
    then
     wget -O ${x[`echo $j`]}_$i.zip $url${x[`echo $j`]}/${x[`echo $j`]}$pref$i.zip
      if test ! -s  "${x[`echo $j`]}_$i.zip" 
       then rm -f "${x[`echo $j`]}_$i.zip"
      fi
    else
     wget -O ${x[`echo $j`]}_$i.zip $url${x[`echo $j`]}/${x[`echo $j`]}$pref2$i.zip
      if test ! -s  "${x[`echo $j`]}_$i.zip" 
       then rm -f "${x[`echo $j`]}_$i.zip"
      fi
    fi
   done
 fi
done
exit 0

Disqus