<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>ftoptas blog &#187; python</title>
	<atom:link href="http://ftoptas.com/category/python/feed/" rel="self" type="application/rss+xml" />
	<link>http://ftoptas.com</link>
	<description>[beta]</description>
	<lastBuildDate>Mon, 30 Jan 2012 20:19:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>3. Dereceden Denklemin Köklerini Bulma</title>
		<link>http://ftoptas.com/3-dereceden-denklemin-koklerini-bulma/</link>
		<comments>http://ftoptas.com/3-dereceden-denklemin-koklerini-bulma/#comments</comments>
		<pubDate>Sun, 25 Dec 2011 22:06:45 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[python]]></category>
		<category><![CDATA[3.dereceden deklem]]></category>
		<category><![CDATA[denklem kökleri]]></category>

		<guid isPermaLink="false">http://ftoptas.com/?p=463</guid>
		<description><![CDATA[3. dereceden bir denklemin bir]]></description>
			<content:encoded><![CDATA[<p>3. dereceden bir denklemin bir tane reel iki tane de imajiner kökü bulunur. Python ile bu reel kökü bulmak için şu fonksiyonu yazabiliriz:</p>
<pre>def denklem_koku(a,b,c,d):
	return -b / (3.0 * a) - (2.0 ** (1.0 / 3.0) * (-b ** 2.0 + 3.0 * a * c)) / (3.0 * a * (-2.0 * b ** 3.0 + 9.0 * a * b * c - 27.0 * a ** 2.0 * d + math.sqrt(4.0 * (-b ** 2.0 + 3.0 * a * c) ** 3.0 + (-2.0 * b ** 3.0 + 9.0 * a * b * c - 27.0 * a ** 2.0 * d) ** 2.0)) ** (1.0 / 3.0)) + (-2.0 * b ** 3.0 + 9.0 * a * b * c - 27.0 * a ** 2.0 * d + math.sqrt(4.0 * (-b ** 2.0 + 3.0 * a * c) ** 3.0 + (-2.0 * b ** 3.0 + 9.0 * a * b * c - 27.0 * a ** 2.0 * d) ** 2.0)) ** (1.0 / 3.0) / (3.0 * 2.0 ** (1.0 / 3.0) * a)</pre>
<p><span id="more-463"></span></p>
<p>İmajiner kökler için i karmaşık sayısını da eklersek şöyle olur (ASCII formatında):</p>
<p>x1 = -b/(3*a) + ((1 <span style="color: #000000;">+</span> i*math.sqrt[3])*(-b^2 + 3*a*c))/(3*2^(2/3)*a*(-2*b^3 + 9*a*b*c &#8211; 27*a^2*d + math.sqrt[4*(-b^2 + 3*a*c)^3 + (-2*b^3 + 9*a*b*c - 27*a^2*d)^2])^(1/3)) &#8211; (1 - i*math.sqrt[3])*(-2*b^3 + 9*a*b*c &#8211; 27*a^2*d + math.sqrt[4*(-b^2 + 3*a*c)^3 + (-2*b^3 + 9*a*b*c - 27*a^2*d)^2])^(1/3)/(6*2^(1/3)*a)</p>
<p>x2 = -b/(3*a) + ((1 - i*math.sqrt[3])*(-b^2 + 3*a*c))/(3*2^(2/3)*a*(-2*b^3 + 9*a*b*c &#8211; 27*a^2*d + math.sqrt[4*(-b^2 + 3*a*c)^3 + (-2*b^3 + 9*a*b*c - 27*a^2*d)^2])^(1/3)) &#8211; (1 + i*math.sqrt[3])*(-2*b^3 + 9*a*b*c &#8211; 27*a^2*d + math.sqrt[4*(-b^2 + 3*a*c)^3 + (-2*b^3 + 9*a*b*c - 27*a^2*d)^2])^(1/3)/(6*2^(1/3)*a)</p>
<p>Kaynak: <a href="http://www.josechu.com/ecuaciones_polinomicas/cubica_solucion.htm" target="_blank">http://www.josechu.com</a></p>
]]></content:encoded>
			<wfw:commentRss>http://ftoptas.com/3-dereceden-denklemin-koklerini-bulma/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>İÜ-RSS: Elektrik-Elektronik Müh. Duyuruları RSS Adresi</title>
		<link>http://ftoptas.com/iu-rss-elektrik-elektronik-muh-duyurulari-rss-adresi/</link>
		<comments>http://ftoptas.com/iu-rss-elektrik-elektronik-muh-duyurulari-rss-adresi/#comments</comments>
		<pubDate>Sat, 22 Jan 2011 13:31:59 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[google app engine]]></category>
		<category><![CDATA[google-app-engine]]></category>
		<category><![CDATA[iu-rss]]></category>

		<guid isPermaLink="false">http://ftoptas.com/?p=412</guid>
		<description><![CDATA[Bölümümün sayfasındaki duyuruları okumak için]]></description>
			<content:encoded><![CDATA[<p><a href="http://ee.istanbul.edu.tr/anasayfa.html" target="_blank"><img class="size-full wp-image-413 alignright" title="iu-rss" src="http://ftoptas.com/wp-content/uploads/2011/01/iu-rss.jpg" alt="" width="200" height="200" />Bölümümün </a>sayfasındaki duyuruları okumak için neden bir RSS ouşturdum? Bu sorunun cevabı, aşağıdan yukarı doğru kayan duyuruların en yakın tarihli olanı, sayfa açıldıktan birkaç milisaniye sonra kaybolması ve okumak için kayan yazıların birinci turu bitirip ikinci tura başlamasını beklemek. Her seferinde daha hızlı okumak için arşive girmem gerekiyordu. Ben de hemen kolları sıvayıp sadece<strong> 2.3 KB</strong> boyutunda olan bir python betiği yazıp <a href="http://code.google.com/intl/tr/appengine/" target="_blank">GAE </a>üzerinde çalıştırmaya başladım. Kod basit bir web scraper olarak çalışıyor ve çektiği verileri işleyip RSS formatına çeviriyor. Şimdi keyifle Google Reader&#8217;da gelen duyuruları inceliyorum. Siz de <a href="http://iu-rss.appspot.com/" target="_blank">iu-rss.appspot.com</a> adresinden ulaşabilirsiniz.</p>
<p><strong>Güncelleme</strong></p>
<p>Artık sınav sonuçları da RSS olarak izlenebiliyor ilgilere duyurulur.</p>
]]></content:encoded>
			<wfw:commentRss>http://ftoptas.com/iu-rss-elektrik-elektronik-muh-duyurulari-rss-adresi/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Django Öğrenebileceğiniz 24 Kaynak</title>
		<link>http://ftoptas.com/django-ogrenebileceginiz-24-kaynak/</link>
		<comments>http://ftoptas.com/django-ogrenebileceginiz-24-kaynak/#comments</comments>
		<pubDate>Sun, 03 Oct 2010 19:43:54 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[django]]></category>
		<category><![CDATA[ders]]></category>
		<category><![CDATA[kaynak]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[video]]></category>

		<guid isPermaLink="false">http://ftoptas.com/?p=386</guid>
		<description><![CDATA[Popularitesi hızla yükselen bir programlama]]></description>
			<content:encoded><![CDATA[<p><a href="http://ftoptas.com/wp-content/uploads/2010/10/django.png"><img class="alignright size-medium wp-image-388" title="django" src="http://ftoptas.com/wp-content/uploads/2010/10/django-300x128.png" alt="" width="300" height="128" /></a></p>
<p>Popularitesi hızla yükselen bir programlama dili olan <a href="http://www.python.org/" target="_blank">Python</a> ile yazılmış mükemmel bir web çatısı olan <a href="http://www.djangoproject.com/" target="_blank">Django</a>&#8216;yu öğrenmek işte size 24 kaynak.</p>
<p><span id="more-386"></span></p>
<p><strong>Django dökümantasyonu</strong></p>
<p><a title="django" href="http://docs.djangoproject.com/en/1.2/" target="_blank">http://docs.djangoproject.com/en/1.2/</a></p>
<p><strong>Django kitapı</strong></p>
<p><a title="django" href="http://www.djangobook.com/" target="_blank">http://www.djangobook.com/</a></p>
<p><strong>Türkçe Video Dersler</strong></p>
<p>4 bölümlük djangoturkiye.com video dersleri</p>
<p><a title="django" href="http://showmedo.com/videotutorials/series?name=Y907SyYnq" target="_blank">http://showmedo.com/videotutorials/series?name=Y907SyYnq</a></p>
<p>3 bölümlük django giriş ve views ile alakalı dersler</p>
<p><a href="http://showmedo.com/videotutorials/series?name=qWmtuStb0" target="_blank">http://showmedo.com/videotutorials/series?name=qWmtuStb0</a></p>
<p><strong>İngilizce Video Dersler</strong></p>
<p>13 bölümlük Django from the ground up</p>
<p><a title="django" href="http://showmedo.com/videotutorials/series?name=PPN7NA155" target="_blank">http://showmedo.com/videotutorials/series?name=PPN7NA155</a></p>
<p>10 adet django ipuçu</p>
<p><a title="django" href="http://net.tutsplus.com/tutorials/tools-and-tips/10-insanely-useful-django-tips/" target="_blank">http://net.tutsplus.com/tutorials/tools-and-tips/10-insanely-useful-django-tips/</a></p>
<p>3 bölümlük django ile wiki hazırlama dersi</p>
<p><a title="django" href="http://showmedo.com/videotutorials/series?name=v7kABKL6R" target="_blank">http://showmedo.com/videotutorials/series?name=v7kABKL6R</a></p>
<p>5 bölümlük ders</p>
<p><a title="django" href="http://showmedo.com/videotutorials/series?name=pythonNapleonePyConTechSeries" target="_blank">http://showmedo.com/videotutorials/series?name=pythonNapleonePyConTechSeries</a></p>
<p>7 bölümlük ders</p>
<p><a title="django" href="http://ericholscher.com/blog/categories/screencasts/" target="_blank">http://ericholscher.com/blog/categories/screencasts/</a></p>
<p>Webfaction sunucusuna django kurulumu</p>
<p><a title="django" href="http://www.webfaction.com/demos/django" target="_blank">http://www.webfaction.com/demos/django</a></p>
<p>Django ile image hosting</p>
<p><a title="django" href="http://www.youtube.com/watch?v=g8v4STgAAdA" target="_blank">http://www.youtube.com/watch?v=g8v4STgAAdA</a></p>
<p>7 dakikada django</p>
<p><a title="django" href="http://www.throwingbeans.org/django_screencasts.html" target="_blank">http://www.throwingbeans.org/django_screencasts.html</a></p>
<p><strong>Diğer django dersleri</strong></p>
<p>Google App Engine üzerine django kurulumu</p>
<p><a title="django" href="https://code.google.com/intl/tr-TR/appengine/articles/django.html" target="_blank">https://code.google.com/intl/tr-TR/appengine/articles/django.html</a></p>
<p>6 adet django dersi</p>
<p><a title="django" href="http://www.webmonkey.com/2010/02/get_started_with_django/" target="_blank">http://www.webmonkey.com/2010/02/get_started_with_django/</a></p>
<p>Nettuts django dersleri</p>
<p><a title="django" href="http://net.tutsplus.com/articles/news/diving-into-django/" target="_blank">http://net.tutsplus.com/articles/news/diving-into-django/</a></p>
<p><a title="django" href="http://net.tutsplus.com/tutorials/other/10-django-troublespots-for-beginners/" target="_blank">http://net.tutsplus.com/tutorials/other/10-django-troublespots-for-beginners/</a></p>
<p><a title="django" href="http://net.tutsplus.com/tutorials/other/intro-to-django-building-a-to-do-list/" target="_blank">http://net.tutsplus.com/tutorials/other/intro-to-django-building-a-to-do-list/</a></p>
<p>4 adet django giriş dersi</p>
<p><a title="django" href="http://armuting.blogspot.com/search/label/django" target="_blank">http://armuting.blogspot.com/search/label/django</a></p>
<p>2 adet slide</p>
<p><a title="django" href="http://blog.insicdesigns.com/2010/03/learning-django-web-development-framework/" target="_blank">http://blog.insicdesigns.com/2010/03/learning-django-web-development-framework/</a></p>
<p>Django kurulumu ve giriş</p>
<p><a title="django" href="http://www.birazkisisel.com/category/web-programlama/django-web-programlama/" target="_blank">http://www.birazkisisel.com/category/web-programlama/django-web-programlama/</a></p>
<p>Django cheatsheet v1</p>
<p><a title="django" href="http://www.mercurytide.co.uk/news/article/django-cheat-sheet/" target="_blank">http://www.mercurytide.co.uk/news/article/django-cheat-sheet/</a></p>
<p>Django ile alakalı birkaç yazı</p>
<p><a title="django" href="http://serkan.gen.tr/kategori/django" target="_blank">http://serkan.gen.tr/kategori/django</a></p>
<p><strong>Django ile yapılmış kaynak kodları açık siteler</strong></p>
<p>235+ adet sitenin kaynak kodları</p>
<p><a title="django" href="http://www.djangosites.org/with-source/" target="_blank">http://www.djangosites.org/with-source/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://ftoptas.com/django-ogrenebileceginiz-24-kaynak/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Python ile FTP işlemleri</title>
		<link>http://ftoptas.com/python-ile-ftp-islemleri/</link>
		<comments>http://ftoptas.com/python-ile-ftp-islemleri/#comments</comments>
		<pubDate>Wed, 04 Aug 2010 19:30:20 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[python]]></category>
		<category><![CDATA[ftp]]></category>
		<category><![CDATA[ftplib]]></category>
		<category><![CDATA[pys60]]></category>
		<category><![CDATA[upload]]></category>

		<guid isPermaLink="false">http://ftoptas.com/?p=345</guid>
		<description><![CDATA[Dün cep telefonumdan(eski toprak N6600)]]></description>
			<content:encoded><![CDATA[<p>Dün cep telefonumdan(eski toprak N6600) ftp ile dosya göndermeye çalışırken kullandığım python scriptini sizinle paylaşmak istiyorum. Burada yazacağımız kodları ister bilgisayarınızdan ister Python destekleyen telefonunuzdan çalıştırabilirsiniz. Yapacağımız örneklerin kaynak dosyasını <a href="http://ftoptas.com/wp-content/plugins/download-monitor/download.php?id=1">buradan </a>indirebilirsiniz.</p>
<p>Önce ftplib kütüphanesine sahip olup olmadığımızı anlamak için aşağıdaki kodu yazalım.</p>
<p><span id="more-345"></span></p>
<pre name="code" class="python">
import ftplib
</pre>
<p>eğer hata vermediyse sorun yok devam edebiliriz.</p>
<pre name="code" class="python">
from ftplib import FTP
host= 'ftp.ftoptas.com'
kullanici_adi = 'kullanici'
parola = 'bir-iki-uc'
ftp = FTP(host)
ftp.set_pasv('true')
ftp.login(kullanici_adi,parola)
</pre>
<p>Belirttiğimiz parametreler sonucunda FTP sunucusuna bağlandık. Şimdi bulunduğumuz dizindeki dosya ve dizinleri listeleyelim</p>
<pre name="code" class="python">
ftp.retrlines('LIST')
</pre>
<p>Şimdi de bulunduğumuz dizini değiştirelim</p>
<pre name="code" class="python">
ftp.cwd('app')
</pre>
<p>Bulunduğumuz dizinden herhangi bir dosya indirelim</p>
<pre name="code" class="python">
dosya = 'test.txt'
ftp.retrbinary('RETR '+dosya,open(dosya,'wb').write)
</pre>
<p>veya bir dosya upload edelim</p>
<pre name="code" class="python">
dosya_adi = 'tes2t.txt'
dosya = open(dosya_adi,'r')
ftp.storbinary('STOR '+dosya_adi,dosya,1024)
dosya.close()
</pre>
<p>Son olarak açtığımız FTP bağlantısını kapatalım</p>
<pre name="code" class="python">
ftp.quit()
</pre>
]]></content:encoded>
			<wfw:commentRss>http://ftoptas.com/python-ile-ftp-islemleri/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Google App Engine ile Alexa Rank Değerini Okuma &#8211; urlfetch fonksiyonu</title>
		<link>http://ftoptas.com/google-app-engine-ile-alexa-rank-degerini-okuma-urlfetch-fonksiyonu/</link>
		<comments>http://ftoptas.com/google-app-engine-ile-alexa-rank-degerini-okuma-urlfetch-fonksiyonu/#comments</comments>
		<pubDate>Thu, 24 Sep 2009 13:18:35 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[google app engine]]></category>
		<category><![CDATA[alexa rank]]></category>
		<category><![CDATA[urlfetch]]></category>

		<guid isPermaLink="false">http://ftoptas.com/?p=321</guid>
		<description><![CDATA[Bugünlerde sitemin alexa rank değeri]]></description>
			<content:encoded><![CDATA[<p>Bugünlerde sitemin alexa rank değeri aniden 2 katından fazla artınca biraz kafayı taktım. Derken Google App Engine ile değeri okumaya çalıştım ve sizinle paylaşıyorum.</p>
<p>Bu yazıyı okumaya devam etmeden önce <a href="http://ftoptas.com/google-app-engine-ile-uygulama-gelistirme/" target="_blank">şuradaki</a> yazımı okumanızı öneriyorum.</p>
<p>Önce alexa isminde bir çalışma dizini oluşturuyoruz. Bu dizinin içine app.yaml isminde bir dosya oluşturuyoruz. Dosyanın içeriğini şöyle yapıyoruz:</p>
<pre name="code" class="python">application: alexa-rank-ogren
version: 1
runtime: python
api_version: 1

handlers:
- url: /.*
script: main.py</pre>
<p><span id="more-321"></span></p>
<p>İlk satırdaki alexa-rank-ogren degeri <a href="http://appengine.google.com" target="_blank">appengine.google.com</a> adresine girip Create an Application dedikten sonra girdiğimiz Application Identifier değeri olmalıdır.</p>
<p>Şimdi de burada belirttiğmiz <span style="color: #0000ff;">main.py</span> dosyasını da <span style="color: #0000ff;">app.yaml</span> dosyasının yanına oluşturuyoruz.<span style="color: #0000ff;"> main.py</span> dosyası da şöyle olsun:</p>
<pre name="code" class="python">from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.api import urlfetch
import re,urllib

class MainPage(webapp.RequestHandler):
    def get(self,url):
        self.response.headers['Content-Type'] = 'text/plain'
        url = 'http://www.alexa.com/siteinfo/'+ url
        try:
            content = urlfetch.fetch(url).content
            up = re.search('&lt;img src="/images/icons/globe-sm.jpg" alt="Global" style="margin-bottom:-2px;"/&gt; [0-9,]{1,10}&lt;/a&gt;',content)
            up = re.search('[0-9,]{1,10}&lt;/a&gt;',up.group()).group()
            sonuc = up[0:-4]
        except:
            sonuc = 'hata'
        self.response.out.write(sonuc)

application = webapp.WSGIApplication([(r'/(.*)',MainPage)],debug=True)

def main():
    run_wsgi_app(application)

if __name__ == "__main__":
    main()</pre>
<p>Burada önce <span style="color: #008000;">MainPage</span> isminde bir sınıf oluşturduk ardından sınıfın içinde oluşturduğumuz get fonksiyonu ile sayfaya gelen istek sonucunda sayfanın gösterdiği değeri belirleyeceğiz. Bu fonksiyonun bir parametresi olan url şu şekilde okunuyor:</p>
<p>http://alexa-rank-ogren.appspot.com/<span style="color: #008000;">ftoptas.com</span></p>
<p>Bu adresteki<span style="color: #008000;"> ftoptas.com</span> kısmı urlyi oluşturmaktadır. Çünkü sadece bir parametremiz var o da ilk<span style="color: #008000;"> &#8216;/&#8217; </span>karakterinden sonra gelen kısımdır.</p>
<p>alexa rank değerini okuyacağımız siteyi öğrendik şimdi de alexaya bağlanıyoruz. Sitenin alexa rank değeri de</p>
<p>http://www.alexa.com/siteinfo/ftoptas.com adresindedir.</p>
<p><span style="color: #008000;">urlfetch() </span>fonksiyonuyla bu siteyi çekiyoruz. Yaklaşık olarak 26KB&#8217;lik bir dosya. Şimdi bir düzenli ifade yazarak bu 26KB&#8217;lik dosyanın içinden sadece alexa rank değerini alacağız.</p>
<p>Eğer FireBug ile bu sayfayı incelersek alexa rank değerinin olduğu yerdeki kodlar şöyledir:</p>
<pre>&lt;img src="/images/icons/globe-sm.jpg" alt="Global" style="margin-bottom:-2px;"/&gt; 4,274,049&lt;/a&gt;</pre>
<p>Bu ifadeyi 12. satırda buluyoruz ve 13.satırda ikinci defa düzenli ifade (regex) kullanarak buradaki sayıyı çekiyoruz.</p>
<p>try kullanmamızın nedeni ise olmayan bir url girdiğimizde bize &#8216;hata&#8217; değerini döndürmesi içindir.</p>
<p>Oluşturduğumuz WSGIApplication parametrelerinde ise urllerin nasıl olacağını belirttik. Yani hangi fonksiyonun hangi url ile bağlantılı olacağını yazdık.</p>
<p>Burada <span style="color: #008000;">&#8216;/&#8217;</span> yerine <span style="color: #008000;"> r&#8217;/(.*)&#8217;</span> kullanmamızın nedeni ise http://alexa-rank-ogren.appspot.com/ adresinden sonra bir parametre geleceğini belirtmek.</p>
<p>Eğer http://alexa-rank-ogren.appspot.com/alexa/ftoptas.com urlsini kullandığımızda <span style="color: #008000;">MainPage </span>fonksiyonunu çağırmak isteseydik şu ifadeyi kullanırdık:</p>
<p><span style="color: #008000;">r&#8217;/alexa/(.*)&#8217;</span></p>
<p>veya MainPage fonksiyonunda iki parametre kullanmak isteseydik şöyle yapardık:</p>
<p><span style="color: #008000;">r&#8217;/(.*)/(.*)&#8217;</span></p>
<p>Yani regex kullanarak çok esnek urller oluşturabiliriz.</p>
<p>Gördüğünüz gibi 26KB&#8217;lik bir veriyi kendi sunucunuzda çekip işlemek hem trafiği hem de işlemci yükünü arttırır. Google app engine kullanarak bu yükü google sunucuların yükledik.  Sistemin çalışan halini şu adreslerden test edebilirsiniz.</p>
<p><a href="http://f-toptas.appspot.com/alexa/google.com" target="_blank">http://f-toptas.appspot.com/alexa/google.com</a></p>
<p><a href="http://f-toptas.appspot.com/alexa/ftoptas.com">http://f-toptas.appspot.com/alexa/ftoptas.com</a></p>
]]></content:encoded>
			<wfw:commentRss>http://ftoptas.com/google-app-engine-ile-alexa-rank-degerini-okuma-urlfetch-fonksiyonu/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Python ile MySQL Bağlantısı ve Temel İşlemler</title>
		<link>http://ftoptas.com/python-ile-mysql-baglantisi-ve-temel-islemler/</link>
		<comments>http://ftoptas.com/python-ile-mysql-baglantisi-ve-temel-islemler/#comments</comments>
		<pubDate>Fri, 11 Sep 2009 13:02:55 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[python]]></category>
		<category><![CDATA[bağlanma]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[mysqldb]]></category>
		<category><![CDATA[python dersleri]]></category>
		<category><![CDATA[veritabanı]]></category>

		<guid isPermaLink="false">http://ftoptas.com/?p=305</guid>
		<description><![CDATA[Python ile MySQLe bağlanmak için]]></description>
			<content:encoded><![CDATA[<p><img src="http://ftoptas.com/wp-content/uploads/2009/09/python-mysql.jpg" alt="python-mysql" title="python-mysql" width="300" height="124" class="aligncenter size-full wp-image-306" /><br />
Python ile MySQLe bağlanmak için önce MySQLdb kütüphanesini <a href="http://sourceforge.net/projects/mysql-python/" target="_blank">şuradan</a> indirip kuralım. Kütüphanenin doğru çalışıp çalışmadığını kontrol etmek için pythonu açıp kütüphaneyi import etmeye çalışalım.</p>
<pre name="code" class="python">
import MySQLdb
</pre>
<p>Eğer problem yoksa devam edebiliriz. Önce veritabanına bağlanmak için sunucu, kullanıcı adı, parola ve veritabanı ismini girelim.</p>
<pre name="code" class="python">
import MySQLdb
db = MySQLdb.connect(host="localhost",user="root",passwd="par01a",db="python")
cursor = db.cursor()
</pre>
<p>şimdi istediğimiz sorguları yazabiliriz.<br />
<span id="more-305"></span></p>
<pre name="code" class="python">
cursor.execute("select * from users")
result = cursor.fetchall()
</pre>
<p>Eğer tablodan birkaç eleman çekmek istiyorsak fetchall() yerine fetchmany() kullanabiliriz.</p>
<pre name="code" class="python">
result = cursor.fetchmany(3)
</pre>
<p>Tablodaki satır sayısını öğrenmek için</p>
<pre name="code" class="python">
cursor.rowcount
</pre>
<p>Veritabanına bilgi girmek için</p>
<pre name="code" class="python">
s = """insert into users (username, password) values ("yeni-kullanici","yeni-sifre")"""
cursor.execute(s)
</pre>
<p>en son eklenen girdinin id numarasını öğrenmek için</p>
<pre name="code" class="python">
cursor.lastrowid
</pre>
<p>Eğer veritabanına tek seferde birden fazla veri eklemek istiyorsak şu yöntemi kullanabiliriz:</p>
<pre name="code" class="python">
s = "insert into users (username, password) values (%s,%s)"
cursor.executemany(s,[("ali","alininparolali"),("veli","velininparolası"),("ayşe","ayşeninparolası")])
</pre>
<p>Son olarak da işimiz bittikten sonra bağlantıyı kapatıyoruz.</p>
<pre name="code" class="python">
cursor.close()
db.close()
</pre>
<p>Kolay gelsin&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://ftoptas.com/python-ile-mysql-baglantisi-ve-temel-islemler/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PyS60 ile SMS Yedekleme</title>
		<link>http://ftoptas.com/pys60-ile-sms-yedekleme/</link>
		<comments>http://ftoptas.com/pys60-ile-sms-yedekleme/#comments</comments>
		<pubDate>Fri, 11 Sep 2009 04:18:41 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[pys60]]></category>
		<category><![CDATA[inbox]]></category>
		<category><![CDATA[pys60 dersleri]]></category>
		<category><![CDATA[sms yedekleme]]></category>

		<guid isPermaLink="false">http://ftoptas.com/?p=297</guid>
		<description><![CDATA[Eğer smslerinizi silmek istemiyorsanız ve]]></description>
			<content:encoded><![CDATA[<p><img src="http://ftoptas.com/wp-content/uploads/2009/09/pysms.jpg" alt="pysms" title="pysms" width="400" height="200" class="aligncenter size-full wp-image-298" /><br />
Eğer smslerinizi silmek istemiyorsanız ve gelen kutusu yüzlerce sms ile dolduysa ve telefonunuzun sms yedekleme özelliği yoksa Python sizin yardımınıza hemen yetişir (Tabi işletim sisteminiz Symbian olması lazım!).</p>
<p>Hemen inbox kütüphanesini kullanarak 1 KB&#8217;den daha az bir betik yazarak tüm smslerinizi text dosyası olarak yedekleyip gönül rahatlığıyla silebilirsiniz. Hemen kodlara geçelim:</p>
<pre name="code" class="python">
from time import  ctime
from inbox import Inbox
from os import listdir,mkdir

kutum = Inbox()
id = kutum.sms_messages()
yol = "e:\\mesajlar\\"
if not 'mesajlar' in listdir('e:\\'):
    mkdir(yol)
sayi = 10 #yedeklenmesini istediğiniz sms adedi
for i in range(0,sayi):
    msj = kutum.address(id[i])+'\n'+ctime(kutum.time(id[0]))+'\n'+kutum.content(id[i])
    h,ay,gun,saat,yil = ctime(kutum.time(id[i])).split(" ")
    sa,dk,sn=saat.split(':')
    d = gun+ay+yil+'-'+sa+'.'+dk+'.'+sn+'-'+kutum.address(id[i])+".txt"
    dosya = open(yol+d,'w')
    dosya.write(msj.encode('utf-8'))
    dosya.close()
print str(sayi)+" adet mesaj '"+yol+"' dizinine kaydedildi."
</pre>
<p><span id="more-297"></span><br />
Kodları kısaca açıklayalım.</p>
<p>Önce <span style="color: #0000ff;">inbox </span>modülünü import ediyoruz. Ardından gelen kutusuna bağlanıyoruz. Her smsnin kendine özgü başka smsde ıolmayan bir id numarası vardır. <span style="color: #0000ff;">&#8220;id&#8221; </span>isimli değişkene bu id numaralarını atıyoruz (<span style="color: #0000ff;">kutum.sms_messages()</span>) Sms okumayı bu id numaralarına göre yapacağız. Hafıza kartında mesajlar isminde bir dizin yoksa oluşturuyoruz. Sonra kaç adet sms yedeklemek istiyorsak <span style="color: #0000ff;">&#8220;</span><span style="color: #0000ff;">sayi&#8221; </span>değişkenine o sayıyı yazıyoruz. <span style="color: #0000ff;">&#8220;msj&#8221;</span> isimli değişkene mesajın gönderenini, gönderme zamanını ve mesaj içeriğini atıyoruz. Mesajın gönderme tarihinin formatını ayarlıyoruz ve <span style="color: #0000ff;">gönderme zamanı+gönderen+&#8217;.txt&#8217; </span>isimli bir dosya oluşturup mesajlar dizinine yazdırıyoruz. Yazarken <span style="color: #0000ff;">utf-8 </span>şeklinde kodlanmış olarak yazarsak karakter problemi yaşamayız. Kolay gelsin&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://ftoptas.com/pys60-ile-sms-yedekleme/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PyS60 ile Telefon Rehberi Yedekleme</title>
		<link>http://ftoptas.com/pys60-ile-telefon-rehberi-yedekleme/</link>
		<comments>http://ftoptas.com/pys60-ile-telefon-rehberi-yedekleme/#comments</comments>
		<pubDate>Tue, 08 Sep 2009 14:27:25 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[pys60]]></category>
		<category><![CDATA[contacts]]></category>
		<category><![CDATA[pys60 dersleri]]></category>
		<category><![CDATA[rehber yedekleme]]></category>

		<guid isPermaLink="false">http://ftoptas.com/?p=290</guid>
		<description><![CDATA[Bugün karşılaştığım bir olaydan sonra]]></description>
			<content:encoded><![CDATA[<p>Bugün karşılaştığım bir olaydan sonra Python&#8217;u daha çok sevmeye başladım. Nokia 6600 rehberini yedeklemeye çalıştık birkaç rehber programı kullandık vCard formatında çıkardı ama isimlerin yaklaşık olarak yarısı görünmedi yani tam olarak alamadık. Derken iş başa düştü ve PyS60 ile birkaç satırda hallettik ve bunu sizinle burada paylaşıyorum.</p>
<pre name="code" class="python">import contacts
rehber=contacts.open()
liste=''
s=len(rehber)
for id in rehber:
    try:
        isim=rehber[id][0].value
    except:
        isim='isim yok'
    try:
        no=rehber[id][1].value
    except:
        no='numara yok'
    liste = liste+isim+'-'+no+'\n'
dosya_adi = 'e:\\rehber-yedek.txt'
dosya = open(dosya_adi,'w')
dosya.write(liste.encode('utf-8'))
dosya.close()
print s,' kisi "'+dosya_adi+'" adresine yedeklendi.'</pre>
<p><span id="more-290"></span><br />
utf-8 karakter kodlamasıyla okuyup yazdığımız için herhangi bir karakter problemi de oluşmuyor.</p>
<p>Burada önce contacts modülünü import ediyoruz.</p>
<p><span style="color: #000080;">contacts.open()</span> fonksiyonuyla rehberi açıyoruz.</p>
<p><span style="color: #000080;">len(rehber)</span> rehberdeki kişi sayısını veriyor.</p>
<p>for döngüsüyle rehberdeki her elemanı sırasıyla çekiyoruz.</p>
<p><span style="color: #000080;">rehber[id][0].value</span> değeri bize rehberdeki ismi verir</p>
<p><span style="color: #000080;">rehber[id][1].value</span> değeri bize ilk numarayı veriri</p>
<p><span style="color: #000080;">rehber[id][2].value</span> değeri bize ikinci numarayı verir. Değiştirdiğimiz sayı her bir alanı ifade etmektedir.</p>
<p><span style="color: #000080;">try</span> kullanmamızın nedeni ise bazen isim olup numara olmuyor veya tam tersi oluyor böyle bir durumda hata verip döngüyü bitirmemesidir.</p>
<p>Okuduğumuz isim ve numaraları aralarına bir <span style="color: #008000;">‘-‘</span> karakteri koyarak ve <span style="color: #008000;">‘\n’</span> ile bir alt satıra geçmesini sağlayarak liste stringine ekliyoruz.</p>
<p>for döngüsü bittikten sonra bir dosya açıp <span style="color: #008000;">‘utf-8’</span> karakter kodlamasıyla kaydediyoruz.</p>
<p>Hepsi bu kadar…</p>
]]></content:encoded>
			<wfw:commentRss>http://ftoptas.com/pys60-ile-telefon-rehberi-yedekleme/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Python ile Resim Üzerine Yazı Yazma</title>
		<link>http://ftoptas.com/python-ile-resim-uzerine-yazi-yazma/</link>
		<comments>http://ftoptas.com/python-ile-resim-uzerine-yazi-yazma/#comments</comments>
		<pubDate>Fri, 21 Aug 2009 10:01:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[python]]></category>
		<category><![CDATA[imagedraw]]></category>
		<category><![CDATA[imagedraw.text]]></category>
		<category><![CDATA[pil]]></category>
		<category><![CDATA[resim üzerine yazı]]></category>
		<category><![CDATA[text]]></category>

		<guid isPermaLink="false">http://ftoptas.com/?p=279</guid>
		<description><![CDATA[Python ile grafik işleme yapabilmek]]></description>
			<content:encoded><![CDATA[<p>Python ile grafik işleme yapabilmek için <a href="http://www.pythonware.com/products/pil/" target="_blank">PIL (Python Imaging Library) </a>kütüphanesini kullanıyoruz. Kütüphanenin işletim sistemi ve Python sürümümüze uygun olan versiyonunu indirip kuralım. Kütüphanenin doğru bir şekilde kurulup kurulmadığını test etmek için Python komut satırına şunu yazalım:</p>
<pre name="code" class="python">
import PIL
</pre>
<p>Herhangi bir hata vermediyse kütüphane yüklenmiştir. Şimdi işlem yapmaya başlayabiliriz.</p>
<pre name="code" class="python">
from PIL import Image
resim = Image.open("test.jpg")
print resim.size
</pre>
<p>(241,172)<br />
<span id="more-279"></span><br />
<img class="alignnone" title="test" src="http://ftoptas.com/wp-content/uploads/2009/08/pil/test.jpg" alt="" width="241" height="172" /></p>
<p>Burada önce PIL içerisinden Image nesnesini çağırdık ve open fonksiyonuyla test.jpg resmini açtık. Resmin boyutlarını öğrenmek için size özelliğine bakarız. Image nesnesiyle kullanacağımız diğer metotlar için şunu yazabiliriz:</p>
<pre name="code" class="python">
dir(resim)
</pre>
<p>Resim üzerine bir yazı yazmak için de ImageDraw nesnesini kullanacağız. Bu yazının fontunu belirlemek için ImageFont nesnesini kullanacağız.</p>
<pre name="code" class="python">
from PIL import Image,ImageFont,ImageDraw
resim = Image.open("test.jpg")
f = ImageFont.truetype("arial.ttf", 35)
ciz = ImageDraw.Draw(resim)
ciz.text((10,10), "ftoptas.com", font=f, fill="#0C3446")
resim.save("test2.jpg")
</pre>
<p><img class="alignnone" title="test" src="http://ftoptas.com/wp-content/uploads/2009/08/pil/test2.jpg" alt="" width="241" height="172" /></p>
<p>Önce yazacağımız yazının fontunu arial ve font büyüklüğünü de 20 olarak belirledik. Ardından 4. satırda açtığımız resmi kullanarak bir Draw nesnesi oluşturduk. Bu nesnenin text metodunu kullanarak (10,10) koordinatına &#8220;#0C3446&#8243; renginde ve ayarladığımız fontta yazı yazmış olduk. text metodunun parametreleri şu şekildedir:</p>
<p>text((x,y), &#8220;yazılacak metin&#8221;, font, renk)</p>
<p>Son olarak  yeni resmi test2.jpg olarak kaydediyoruz.</p>
<p>Yazıya biraz gölge efekti vermek için yazıyı iki defa farklı renkte ve x-y koordinatlarının 2 piksel arttırılmış olarak kaydedelim.</p>
<pre name="code" class="python">
from PIL import Image,ImageFont,ImageDraw
resim = Image.open("test.jpg")
f = ImageFont.truetype("arial.ttf", 35)
ciz = ImageDraw.Draw(resim)
ciz.text((8,8), "ftoptas.com", font=f, fill="#3EA3D1")
ciz.text((10,10), "ftoptas.com", font=f, fill="#0C3446")
resim.save("test3.jpg")
</pre>
<p><img class="alignnone" title="test" src="http://ftoptas.com/wp-content/uploads/2009/08/pil/test3.jpg" alt="" width="241" height="172" /></p>
<p>Yazının arkasına açık renkli bir diktörtgen çizip yazının okunabilirliğini arttırabiliriz.</p>
<pre name="code" class="python">
from PIL import Image,ImageFont,ImageDraw
resim = Image.open("test.jpg")
f = ImageFont.truetype("arial.ttf", 35)
ciz = ImageDraw.Draw(resim)
ciz.rectangle(((8,8),(190,48)),fill="#ffffff")
ciz.text((8,8), "ftoptas.com", font=f, fill="#3EA3D1")
ciz.text((10,10), "ftoptas.com", font=f, fill="#0C3446")
resim.save("test4.jpg")
</pre>
<p><img class="alignnone" title="test" src="http://ftoptas.com/wp-content/uploads/2009/08/pil/test4.jpg" alt="" width="241" height="172" /></p>
<p>Draw nesnesinin rectangle metodunu kullanarak belirtiğimiz koordinatlara bir diktörtgen oluşturduk. Yazıya bir açı vermek için şu yöntemi kullanabiliriz:</p>
<pre name="code" class="python">
from PIL import Image,ImageFont,ImageDraw
resim = Image.open("test.jpg")
f = ImageFont.truetype("arial.ttf", 20)
yazi = Image.new('RGB',(120,50))
ciz = ImageDraw.Draw(yazi)
ciz.text((8,8), "ftoptas.com", font=f, fill="#ffffff")
yazi = yazi.rotate(15)
resim.paste(yazi,(20,20))
resim.save("test5.jpg")
</pre>
<p><img class="alignnone" title="test" src="http://ftoptas.com/wp-content/uploads/2009/08/pil/test5.jpg" alt="" width="241" height="172" /></p>
<p>RGB formatında 120&#215;50 piksel boyutunda yeni bir Image oluşturup yazıyı onun içine yazdık. Ardından içinde yazı olan resme 15 derece açı verip eski resmin üzerinde yapıştırdık.</p>
]]></content:encoded>
			<wfw:commentRss>http://ftoptas.com/python-ile-resim-uzerine-yazi-yazma/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Pardus&#8217;a Google App Engine Kurulumu</title>
		<link>http://ftoptas.com/pardusa-google-app-engine-kurulumu/</link>
		<comments>http://ftoptas.com/pardusa-google-app-engine-kurulumu/#comments</comments>
		<pubDate>Sun, 21 Jun 2009 11:59:32 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[google app engine]]></category>
		<category><![CDATA[linux]]></category>

		<guid isPermaLink="false">http://ftoptas.com/?p=242</guid>
		<description><![CDATA[Önceki yazılarımda Google App Engine&#8217;den]]></description>
			<content:encoded><![CDATA[<p>Önceki yazılarımda Google App Engine&#8217;den biraz bahsetmiştim. Kodlarımızı GAE sunucularına yüklemek için veya yerelde çalıştırmak için bir uygulama kullanıyoruz. Windwos için bu uygulama bir .exe dosyası ve çalıştırıp kuruyoruz. Burada sorun yok. Fakat bu uygulamanın Linux versiyonu ise bir .zip dosyası. Bunu nasıl kullanacağımızı görelim:</p>
<p>1. Adım: Uygulamayı indirelim:</p>
<p><a href="http://code.google.com/intl/tr-TR/appengine/downloads.html" target="_blank">şuradan</a> google_appengine_1.2.3.zip dosyasını indiriyoruz.</p>
<p>2. Adım: indirdiğimiz zip dosyasını açıp <span style="color: #000080;">/home/faruk/gae</span> (burada &#8216;faruk&#8217; yerine sizin kullanıcı adınız gelecek) dizinine kopyalıyoruz. Bu kısmı isterseniz sağ tıklayıp buraya çıkar diyerek veya komutlarla şöyle yapabilirsiniz:</p>
<p><span id="more-242"></span></p>
<pre class="python">unzip google_apengine_1.2.3.zip
cp -R googgle_appengine /home/faruk/gae</pre>
<p>Sıkıştırılmış dosyayı açıp /home/faruk/gae dizinine kopyaladık. Uygulamamız bu dizine kurulmuş oldu.</p>
<p>3.Adım: Şimdi de çalışacağımız dizinin içine buradan bir symlink oluşturalım. Çalışacağımız dizin /home/faruk/Desktop/projelerim/ olsun. Şu kodları yazarak symlink oluşturuyoruz:</p>
<pre class="python">sudo ln -s /home/faruk/gae /home/faruk/Desktop/projelerim/gae</pre>
<p>4.Adım: Şimdi tekrar projelerim dizinine dönerek burada herhangi bir GAE uygulaması yapabilirz. Hemen küçük bir uygulama yapalım. Önce deneme isminde bir dizin açalım:</p>
<pre>mkdir deneme</pre>
<p>Bu dizinin içine app.yaml ve main.py dosyalarımızı oluşturalım:</p>
<p>app.yaml:</p>
<pre>application: deneme
version: 1
runtime: python
api_version: 1

handlers:
- url: /.*
  script: main.py</pre>
<p>main.py:</p>
<pre class="python">from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app

class MainPage(webapp.RequestHandler):
    def get(self):
        self.response.headers['Content-Type'] = 'text/plain'
        self.response.out.write('Merhaba Pardus')

application = webapp.WSGIApplication([('/',MainPage)],debug=True)

def main():
    run_wsgi_app(application)

if __name__ == "__main__":
    main()</pre>
<p>Şimdi tekrar projelerim dizinine gelerek şu komutları yazalım:</p>
<pre>sudo python gae/dev_appserver.py deneme</pre>
<p>Firefoxu açıp localhost:8080/ adresine girdiğimizde Merhaba Pardus yazısını görüyoruz. Hayırlı olsun&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://ftoptas.com/pardusa-google-app-engine-kurulumu/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

