How to open a URL each n-seconds as a new tab in a browser (Python)

Using the following code you can open a URL in a default browser as a new tab. here we use three modules: time, sched (for scheduling), and webbrowser (a very useful module for working with the browser)

The code that you can copy and use is:

#————————————————————————
import webbrowser as wb

import time as tt

import sched as sch

def openSO(sc):

    print “openinig SO in a new tab”

    my_url=”http://google.com/”

    wb.open_new_tab(my_url)

    sc.enter(60,1,openSO,(sc,))          # it opens the webpage each 60 seconds and then repeats the process

s = sch.scheduler(tt.time,tt.sleep)

s.enter(60,1,openSO, (s,))

s.run()
#————————————————————————

Posted in Linux, programming, Python, Software, Thoughts | Tagged , , , , , , , , , , , , , , , , , , , , , , , , , | Leave a comment

How to find this blog

How to find this blog

Posted in Thoughts | Tagged , , , , | Leave a comment

Hint: Run a subprocess from Python script

The subprocess module is a very useful module in python:

1- How to call a subprocess with arguments?
2- How to see the outputs?

# example code
>>> include subprocess
>>> subprocess.call(["ls","-l"])
0
>>>subprocess.check_output(["ls","-l"])
‘total 28328\ndrwxrwxr-x  2 nkn nkn     4096 Feb  4 01:38 backup\ndrwxrwxr-x 11 nkn nkn     4096 Mar 12 13:02 Chain\n-rw-rw-r–  1 nkn nkn       72 Mar  7 11:28 C:\\nppdf32Log\\debuglog.txt\ndrwxr-xr-x  2 nkn nkn    …

Posted in Linux, programming, Python, Ubuntu | Tagged , , , , , , , , , , , , , , , | Leave a comment

Deciphering text messages using Python

Here you will see a simple example that is ciphered by rotating the characters:                         a –> c, b –>d, …, x–>y, y–>a, z–>b

The coded text message is this:

g fmnc wms bgblr rpylqjyrc gr zw fylb. rfyrq ufyr amknsrcpq ypc dmp. bmgle gr gl zw fylb gq glcddgagclr ylb rfyr’q ufw rfgq rcvr gq qm jmle. sqgle qrpgle.kyicrpylq() gq pcamkkclbcb. lmu ynnjw ml rfc spj

Method – 1

the following code is used simply to decode the message:

# ———————— code —————————–

str=”g fmnc wms bgblr rpylqjyrc gr zw fylb. rfyrq ufyr amknsrcpq ypc dmp. bmgle gr gl zw fylb gq glcddgagclr ylb rfyr’q ufw rfgq rcvr gq qm jmle. sqgle qrpgle.kyicrpylq() gq pcamkkclbcb. lmu ynnjw ml rfc spj”
# a = 97, z = 122
for s in str:
if ord(s) > 120:          # for ‘y’ and ‘z’
print chr(ord(s) – 26 + 2),
elif ord(s) < 97:          # for the characters smaller than ‘a’
print s,
else:                            # for the alphabet characters
print chr(ord(s)+2),

# ———————— code —————————–

The result is shown here:

>>>
i h o p e y o u d i d n t t r a n s l a t e i t b y h a n d . t h a t s w h a t c o m p u t e r s a r e f o r . d o i n g i t i n b y h a n d i s i n e f f i c i e n t a n d t h a t ‘ s w h y t h i s t e x t i s s o l o n g . u s i n g s t r i n g . m a k e t r a n s ( ) i s r e c o m m e n d e d . n o w a p p l y o n t h e u r l

Method – 2

here we use the famous string.amekrtrans() which is made for such situations.

# ———————— code —————————–

import string
intab = string.ascii_lowercase
outtab=”
for s in intab:
if (s != ‘z’ and s !=’y’):
outtab = outtab + chr(ord(s)+2)
else:
outtab = outtab + chr(ord(s) -26 + 2)

trantab = string.maketrans(intab,outtab)
print str.translate(trantab)

# ———————— code —————————–

The result is :

>>> i hope you didnt translate it by hand. thats what computers are for. doing it in by hand is inefficient and that’s why this text is so long. using string.maketrans() is recommended. now apply on the url

 

code

 

 

 

 

 

 

 

 

 

 

 

result

Posted in Linux, programming, Python, Software, Ubuntu | Tagged , , , , , , , , , , , , , , , , | Leave a comment

install tinycore linux version 5.0.2 on VirtualBox (video tutorial)

Posted in Linux, Software, Ubuntu | Tagged , , , , , , , , , | Leave a comment

Connecting from Windows to Ubuntu via SSH, using Putty (video tutorial)

Posted in Linux, Software, Ubuntu | Tagged , , , , , , , , , , , | Leave a comment