Posts Tagged ‘Python’

9
Dec

httping

   Posted by: myururdurmaz    in httping, python, Yazılım

is a small for ping http servers. Here an example

$ httping google.com

Pinging :http://google.com

9324 bytes from http://google.com: seq=1 rep=[200/OK] time=11201 ms
9356 bytes from http://google.com: seq=2 rep=[200/OK] time=834 ms
9342 bytes from http://google.com: seq=3 rep=[200/OK] time=822 ms
9342 bytes from http://google.com: seq=4 rep=[200/OK] time=827 ms

Avg :3421 ms - 9341 bytes
Speed :2KB/second
Health :%100

Download httping

Bookmark and Share
Tags: , , ,

Tags: , , ,

8
Apr

python ile basit bir kod wrapper örneği

   Posted by: İsmail ÇAKIR    in python

import sys

pre = ‘out.println("‘ # satirbasi sql.append(" gibi
pst = ‘")‘            # satirsonu ") gibi
addslash = 1          # tirnaklara backslash

if len(sys.argv) == 1:
    print "kullanim: \n \t\t  wrapper.py giris.txt \n  \t\t  > cikis.txt gerekiyorsa"
    sys.exit(1)

f = open(sys.argv[1] ,’r‘)

for r in f:
    if (addslash == 1):
        r = r.replace(‘"‘,’\\"‘)
    r = r.rstrip()
    line =  "%s%s%s" % (pre , r, pst)
    print line

Bookmark and Share
Tags: ,

Tags: ,

24
Feb

linux capslock notify

   Posted by: Muhammed YÜRÜRDURMAZ    in Linux, python

Eer benim gibi durumunu dizüstünüzde ışık olmadığından dolayı göremiyorsanız aşağıdaki script işinizi görebilir.

bu scripti capsnotify.py ismiyle bir yere kaydedin.

daha sonra kullandığınız masaüstü ortamının otomatik başlangıç bölümüne ayarlayın.


#!/usr/bin/
import pygtk
pygtk.require(’2.0′)
import pynotify
import sys
import gtk
import os
import time

__author__="xmaster"
__date__ ="$Feb 24, 2010 11:14:16 AM$"

def get_status():
    status = None
    p = os.popen("/usr/bin/xset q")
    while 1:
        line = p.readline()
        if not line: break
        if line.find("Caps") > -1:
            status = line[21:25].strip()
            break
    p.close()
    return status

def show_status(status):
    if status == "on":
        uri = "file:///usr/share/icons/gnome/scalable/devices/keyboard.svg"
        n = pynotify.Notification("Caps Lock On", "", uri)
    else:
        uri = "file:///usr/share/icons/gnome/scalable/devices/keyboard.svg"
        n = pynotify.Notification("Caps Lock Off", "", uri)

    n.set_timeout(500)
    if not n.show():
        print "Failed to send notification"
        sys.exit(1)

if __name__ == ‘__main__’:
    if not pynotify.init("Caps toggle"):
        print "Unable to initialize Python "
        sys.exit(1)
    old_status = None
    while 1:
        status = get_status()
        if old_status is None:
            old_status = status
        if status != old_status:
            show_status(status)
            old_status = status
        time.sleep(0.5)

Bookmark and Share
Tags: , , , ,

Tags: , , , ,

19
Feb

Python ile basit bir html form generator (üreteç)

   Posted by: İsmail ÇAKIR    in python


import sys
import 

tablename = ""
mhost = ""
muser = ""
mpasswd = ""
mdb= ""

def head():
    head = """
    <><head>
    <style>
    .minput {
        border: 1px solid #fdfcf7;
        font-family: "Times New Roman", Times, serif;
        font-style: bold;
        font-size: 14px;
        color: #454743;
    }

    .mlabel {
        font-family: "Times New Roman", Times, serif;
        font-style: bold;
        font-size: 13px;
        color: #e7363e;
    }
    </style></head><body>< action="" method="post">
    """
    return head

def sub():
    sub = """
        </form></body></html>
    
    """
    return sub

def insert():
    pass

def update():
    pass

def input(name, label = None):
    if not label:
        label = name
    return ‘<label style="mlabel">%s:</label><input style="minput" name="%s" type=text />’ % (label, name)

def clean(mrow):
    pass

def deneme():
    try:
        conn = MySQLdb.connect (host = mhost, user = muser, passwd = mpasswd, db = mdb)
        cursor = conn.cursor ()
        msql = ‘select column_name from information_schema.columns where table_name="%s"’ % tablename
        cursor.execute (msql)
    except MySQLdb.Error, e:
        print "Error %: %s" % (e.args[0], e.args[1])
        sys.exit (1)

    row = cursor.fetchall ()
    print head()
    for  r in range(len(row)):
        print input("".join(row[r]))
    print sub()
    cursor.close ()
    conn.close ()

if __name__ == "__main__" :
    deneme()

Bookmark and Share
Tags: , , , , , , ,

Tags: , , , , , , ,

19
Feb

zip ve jar dosyalar içinde arama

   Posted by: İsmail ÇAKIR    in python


import zipfile
import os

aranan = "deneme.class"

def yuru(param, dizin, dosyalar):
    global aranan
    for dosya in dosyalar:
        if dosya.endswith(".") or dosya.endswith("."):
            zp = zipfile.ZipFile(os.path.join(dizin, dosya), "r")
            for name in zp.namelist():
                if name.endswith(aranan):
                    print os.path.join(dizin, dosya), ":", name
        if dosya.endswith(aranan):
            print os.path.join(dizin, dosya)

os.path.walk(".", yuru, None)

Bookmark and Share
Tags: , , , ,

Tags: , , , ,

27
Jan

apache access.log için python regex

   Posted by: Muhammed YÜRÜRDURMAZ    in Yazılım

r”"”(?P<karsi_taraf>[^ ]*) – (?P<kullanici>[^ ]*) \[(?P<tarih>[^\]]*)] “(?P<url>[^"]*)” (?P<cevap>[0-9]*) (?P<boyut>[0-9]*) “(?P<ref>[^"]*)” “(?P<browser>[^"]*)”"”

Bookmark and Share
Tags: , , ,

Tags: , , ,

25
Nov

Codepad

   Posted by: myururdurmaz    in Uncategorized

Küçük uygulamalar veya scriptler yazıp test etmek istiyorsanız bu site tam size göre.

http://codepad.org/irV8v8fe

http://codepad.org/

Bookmark and Share
Tags: , , , , , , , , , , ,

Tags: , , , , , , , , , , ,

Standart mı değil mi bilmem, karşılaştığım bir subtitle için yazdığım kodu.

Kullanım:
python .py dosyadi.xml

import math
import sys
import re
import codecs
from xml.dom import minidom
xmldoc = minidom.parse(sys.argv[1])

x,z  = 0,0
yazi = ""

df = codecs.open(sys.argv[1] + ".srt","wt","utf-8")

def saat(msaniye):
    hour = math.floor(msaniye/3600000)
    minute = math.floor((msaniye%3600000)/60000)
    second = math.floor((msaniye%60000)/1000)
    milisecond = math.floor((msaniye%1000))
    return "%02:%02:%02,%03" % (hour,minute,second,milisecond)

def saatbul(sira):
    r = 0
    for satir in xmldoc.getElementsByTagName(‘SYNC‘):
        q = satir.getAttribute(‘start‘)
        if (r == sira) :
            return satir.getAttribute(‘start‘)
        r += 1
    return int(q) + 2000

for tag in xmldoc.getElementsByTagName(‘SYNC‘):
    print >>df,  x
    print >>df, saat(int(tag.getAttribute(‘start‘))) ,  "–>"  , saat(int(saatbul(x + 1)))
    x += 1
    z = tag.getAttribute(‘start‘)
    m = re.(‘\<P.+\>(?P<metin>.+)\<\/P\>‘,tag.toxml())
    yazi = m.group(‘metin‘)
    yazi = yazi.replace(‘#‘,’\n‘)
    print >>df, yazi
    print >>df, " "

Link: flvxml2srt

Bookmark and Share
Tags: , , , , , ,

Tags: , , , , , ,

Switch to our mobile site