6.04.2015 г.

Python order dictionary by Value, hailstone sequence

import operator
def fff(number):
    se = [number]
    while number > 1:
       number = 3*number+1 if number%2 else number/2
       se.append(number)
    return  sum(se)

result={}

for i in range(1,20):
    result[i]=fff(i)
 
print max(result.items(), key=operator.itemgetter(1))

Check zodiac sign ,china and wester with python script

# -*- coding: utf-8 -*-
import time,datetime

chainese = ['monkey','rooster','dog','pig','rat','ox','tiger','rabbit','dragon','snake','horse','sheep']

zodia = {
'aries': ['3 21', '4 20'],
'taurus' : ['4 21' , '5 20'],
'gemini' : ['5 21' , '6 20'],
'cancer' : ['6 21' , '7 22'],
'leo' : ['7 23' , '8 22'],
'virgo' : ['8 23' , '9 22'],
'libra' : ['9 23' , '10 22'],
'scorpio' : ['10 23' , '11 21'],
'sagittarius' : ['11 22' , '12 21'],
'capricorn' : ['12 22' , '1 20'],
'aquarius' : ['1 21' , '2 19'],
'pisces' : ['2 19' , '3 20']
}



def check_zodia(month,day):
    """Check zodia use dictioanry zodia"""
    for i in zip(zodia.keys(),zodia.values()):
        if tuple(map(int, [x for x in [i[1][0]]][0].split())) < (month, day) < tuple(map(int,[x for x in [i[1][1]]][0].split())):
            print "Your Zodia is %s" % i[0].title()


def check_china_zodia(year):
    """Check China Zodia sign"""
    check_china_zodia = int(year%12)
    print "In Chaina calendar you'r zodia is : %s" % chainese[check_china_zodia].title()
 

if __name__ == "__main__":
    value = raw_input("Enter day/month/year of Birth :")
    result = map(int, value.split("/"))
    day=result[0]
    month=result[1]
    year=result[2]
    check_zodia(month,day)
    print "\n"
    check_china_zodia(year)

Python script for listen radion station online

# -*- coding: utf-8 -*-
"""
Created on Thu Sep 18 10:24:56 2014

@author: borko-8.1
"""

import platform
import os
print "---------------Radio Station's----------------"
trance={u'Трансе FM': 'http://listen.trance.fm/1/320', u'Elit trance music': 'http://www.slusham.com/radio/fmplus.m3u', u'Elit houce music': 'http://eilo.org:8000/house.m3u'}

bgradio={u'Energy':'http://80.72.68.217/nrj.ogg.m3u', u'Рок радио':'http://80.72.68.217/radio1rock_low.ogg', u'Радио Melody':'http://live.btvradio.bg/melody.mp3.m3u',u'Радио Nova':'http://149.13.0.81/nova.aac.m3u'}


def menu():
    print u"1 за меню"
    print u"2 за избор на жанр"
    print u"3 за изход"
    cmenu=0
    while cmenu !=3:
        print
        cmenu=input("Enter choice :")
        if cmenu == 1:
            menu()
            print
        elif cmenu == 2:
            chanel()
            print
        print
    
def chanel():
    print u"1 за трансе"
    print u"2 за БГ радио"
    print u"3 за изход"
    choice=0
    while choice!=3:
        choice = input("Choice radio vid :")
        if choice == 1:
            for i in range(len(trance)):
                print i, "-",trance.keys()[i]
            print
            tranceradio = input("Play radio")
            if platform.system() == "Windows":
                print "Windows system "
                path = "C:\\Program Files (x86)\\VideoLAN\\VLC"
                os.chdir( path )
                player = "vlc.exe "
                chanel = trance.values()[tranceradio]
                start = player+chanel
                os.system(start)
            if platform.system() == "linux":
                print "Linux system"
                player = "cvlc -vvv "
                chanel = trance.values()[tranceradio]
                start = player+chanel
                os.system(start)
        if choice == 2:
            for i in range(len(bgradio)):
                print i, "-",bgradio.keys()[i]
            print
            tranceradio = input("Push radio")
            if platform.system() == "Windows":
                print "Windows system "
                path = "C:\\Program Files (x86)\\VideoLAN\\VLC"
                os.chdir( path )
                player = "vlc.exe "
                chanel = bgradio.values()[tranceradio]
                start = player+chanel
                os.system(start)
            if platform.system() == "linux":
                print "Linux system"
                player = "cvlc -vvv "
                chanel = bgradio.values()[tranceradio]
                start = player+chanel
                os.system(start)


#if __name__ == "__main__":
#    menu()
menu()
raw_input()

5.04.2015 г.

ssh without password

Mashine A - Host
Mashine B - Client

On host B do this:

ssh-keygen -t rsa -b 2048 -C "Enibody Name"

After generate key.pub, copy into pashine B with command

ssh-copy-id -i id_rsa.pub user@mashineB
or
scp ~/path to id_rsa.pub username@ip:/home/usenname/.ssh/id_rsa.home.pub

on machine B do this:
cat id_rsa.home.pub >> authorized_keys


Hint2
On the mashine A in .ssh creata file caonfig with text:

Host virtual
    HostName 192.168.1.4
    Port 22
    User username

Change format number from 0888888888 to 0888-88-88-88 in text using python

#-*- coding:utf-8 -*-
import re, fileinput
File = "bbb.txt"
for line in fileinput.FileInput(File, inplace=1):
    pattern = re.compile(r'\d{10}')
    if re.search(pattern,line):
        line = re.sub(r'(\d{4})(\d{2})(\d{2})(\d{2})',r'\1-\2-\3-\4',line).strip()
        print line.strip()
    else:
         print line.strip()