python ile basit bir kod wrapper örneği

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 python 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: ,

Related posts

python

Comments (0)

Permalink

linux capslock notify

Eer benim gibi capslock 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/python
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 Notify"
        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: , , , ,

Related posts

Linux
python

Comments (0)

Permalink

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


import sys
import MySQLdb

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

def head():
    head = """
    <html><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><form 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 %d: %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: , , , , , , ,

Related posts

python

Comments (0)

Permalink

zip ve jar dosyalar içinde arama


import zipfile
import os

aranan = "deneme.class"

def yuru(param, dizin, dosyalar):
    global aranan
    for dosya in dosyalar:
        if dosya.endswith(".jar") or dosya.endswith(".zip"):
            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: , , , ,

Related posts

python

Comments (0)

Permalink

apache access.log için python regex

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: , , ,

Related posts

Yazılım

Comments (0)

Permalink

Codepad

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: , , , , , , , , , , ,

Related posts

Uncategorized

Comments (0)

Permalink

flvxml2srt flv xml yapisini srt ye çeviren bir py (güncellendi)

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

Kullanım:
python flvxml2srt.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 "%02d:%02d:%02d,%03d" % (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.search(‘\<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: , , , , , ,

Related posts

Uncategorized

Comments (0)

Permalink

Switch to our mobile site