<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Just a tech stuff» Just a tech stuff – Karol Zielinski’s tech life – python, java blog, web development blog</title>
	
	<link>http://tech.karolzielinski.com</link>
	<description>... because from time to time I'm a web developer, too</description>
	<lastBuildDate>Tue, 23 Feb 2010 12:32:57 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/JustATechStuff" /><feedburner:info uri="justatechstuff" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>Publish post on Facebook Page wall as a Page (not a user) (python + Facebook REST API)</title>
		<link>http://feedproxy.google.com/~r/JustATechStuff/~3/FI-b_U15sIM/publish-post-of-facebook-page-wall-as-a-page-not-a-user-python-facebook-rest-api</link>
		<comments>http://tech.karolzielinski.com/publish-post-of-facebook-page-wall-as-a-page-not-a-user-python-facebook-rest-api#comments</comments>
		<pubDate>Tue, 23 Feb 2010 12:32:39 +0000</pubDate>
		<dc:creator>Karol Zielinski</dc:creator>
				<category><![CDATA[python]]></category>
		<category><![CDATA[tools]]></category>
		<category><![CDATA[facebook]]></category>
		<category><![CDATA[facebook api]]></category>
		<category><![CDATA[fan page]]></category>
		<category><![CDATA[rest]]></category>

		<guid isPermaLink="false">http://tech.karolzielinski.com/?p=449</guid>
		<description><![CDATA[After long days (or even weeks) of fighting with this issue&#8230; today I can be proud of myself. At last&#8230; I did it and it works! I can publish new posts on Facebook Page wall as a Page, not as a user (admin of that page). 


I found lots of discussions about that, however none [...]]]></description>
			<content:encoded><![CDATA[<p>After long days (or even weeks) of fighting with this issue&#8230; today I can be proud of myself. At last&#8230; I did it and it works! I can publish new posts on Facebook Page wall as a Page, not as a user (admin of that page). </p>
<p><span id="more-449"></span></p>
<p><a href="http://tech.karolzielinski.com/wp-content/uploads/2010/02/facebook.jpg"><img src="http://tech.karolzielinski.com/wp-content/uploads/2010/02/facebook-300x213.jpg" alt="Facebook" title="Facebook" width="300" height="213" class="alignnone size-medium wp-image-450" /></a></p>
<p>I found lots of discussions about that, however none of them were enough for me. Some of the discussions:</p>
<ul>
<li><a href="http://bugs.developers.facebook.com/show_bug.cgi?id=8184">http://bugs.developers.facebook.com/show_bug.cgi?id=8184</a></li>
<li><a href="http://bugs.developers.facebook.com/show_bug.cgi?id=8691">http://bugs.developers.facebook.com/show_bug.cgi?id=8691</a></li>
</ul>
<p>And now&#8230; my solution:</p>
<p>Log in to Facebook, create new app, create fan page.</p>
<p>Now you are ready.</p>
<h2>Add app to your fan page. </h2>
<p>Go to <a href="http://www.facebook.com/apps/application.php?id=ID_OF_YOUR_APP">http://www.facebook.com/apps/application.php?id=ID_OF_YOUR_APP</a>. </p>
<p>Find link <em>&#8216;Add to my Page&#8217;</em> on the left, click on it. Find your page on the list and click on <em>&#8216;Add to page&#8217;</em> next to this page.</p>
<h2>Set application type</h2>
<p>Go to <a href="http://www.facebook.com/developers/editapp.php?app_id=ID_OF_YOUR_APP">http://www.facebook.com/developers/editapp.php?app_id=ID_OF_YOUR_APP</a>. </p>
<p>Choose <em>&#8216;Web&#8217;</em> next to <em>&#8216;Application type&#8217;</em> and click on <em>&#8216;Save Changes&#8217;</em> button.</p>
<h2>Add permissions to your app</h2>
<p>Prepare special link:</p>
<p><a href="http://www.facebook.com/connect/prompt_permissions.php?api_key=YOUR_API_KEY&#038;v=1.0&#038;next=http://www.facebook.com/connect/login_success.html?xxRESULTTOKENxx&#038;display=page&#038;ext_perm=publish_stream,offline_access&#038;enable_profile_selector=1&#038;profile_selector_ids=ID_OF_YOUR_PAGE">http://www.facebook.com/connect/prompt_permissions.php?api_key=YOUR_API_KEY&#038;v=1.0&#038;next=http://www.facebook.com/connect/login_success.html?xxRESULTTOKENxx&#038;display=page&#038;ext_perm=publish_stream,offline_access&#038;enable_profile_selector=1&#038;profile_selector_ids=ID_OF_YOUR_PAGE</a></p>
<p>replace <em>YOUR_API_KEY</em> for an API KEY of your application and <em>ID_OF_YOUR_PAGE</em> for an id of your page</p>
<p>Run this URL in your web browser. Click on <em>&#8216;Allow&#8217;</em>. </p>
<p>You should see a message: <em>&#8216;Success&#8217;</em>.</p>
<h2>Check everything</h2>
<p>Go to <a href="http://developers.facebook.com/tools.php?app_id=335851346097">http://developers.facebook.com/tools.php?app_id=335851346097</a> and check your permissions.</p>
<p>Choose your application, change <em>&#8216;Response Format&#8217;</em> to <em>JSON</em>, choose method <em>&#8216;users.hasAppPermission&#8217;</em>, fill <em>publish_stream</em> in <em>ext_perm</em> and id of your page in <em>uid</em>.</p>
<p>You should see result: <strong>1</strong>.</p>
<p>That means that everything is ok.</p>
<h2>Write a code</h2>
<p>Right now I will show how to create script in python (with <a href="http://code.google.com/p/pyfacebook/">PyFacebook</a>), but the code is really similar to that from other programming languages.</p>
<pre name="code" class="python">
def add_to_fb();
	import facebook
	fb = facebook.Facebook('YOUR_API_KEY', 'YOUR_SECRET_KEY')
	fb.auth.createToken()
	fb.login(popup=False)

	#print 'offline access...'
	#b.request_extended_permission('offline_access')
	#print 'publish stream...'
	#fb.request_extended_permission('publish_stream')

	print 'get session...'
	fb.auth.getSession()

	print 'add...'

	try:
		id_of_message = fb.stream.publish(message='my test message', uid=ID_OF_YOUR_PAGE)
	except Exception, e:
		error_code = None
		try:
			error_code = e.code
		except AttributeError:
			pass

		if error_code:
			print  "Facebook returned an error - sorry! %s %s" % (str(e.code), repr(e))
		else:
			print  "Facebook returned an error - sorry (no error code)! %s" % (repr(e))
	else:
		print id_of_message
</pre>
<p>And that&#8217;s all. Try to use it.</p>
<p>Sometimes it&#8217;s necessary to use <em>request_extended_permission()</em> (if we want to add privileges to our user), so you can uncomment these two lines.</p>
<p>Lots of hours&#8230; but at last &#8211; <strong>success</strong>.</p>
<script src="http://feeds.feedburner.com/~s/?i=http://tech.karolzielinski.com/publish-post-of-facebook-page-wall-as-a-page-not-a-user-python-facebook-rest-api" type="text/javascript" charset="utf-8"></script><img src="http://feeds.feedburner.com/~r/JustATechStuff/~4/FI-b_U15sIM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://tech.karolzielinski.com/publish-post-of-facebook-page-wall-as-a-page-not-a-user-python-facebook-rest-api/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://tech.karolzielinski.com/publish-post-of-facebook-page-wall-as-a-page-not-a-user-python-facebook-rest-api</feedburner:origLink></item>
		<item>
		<title>SQLAlchemy: Dependency rule tried to blank-out primary key column…</title>
		<link>http://feedproxy.google.com/~r/JustATechStuff/~3/PMrhgyJVDf8/sqlalchemy-dependency-rule-tried-to-blank-out-primary-key-column</link>
		<comments>http://tech.karolzielinski.com/sqlalchemy-dependency-rule-tried-to-blank-out-primary-key-column#comments</comments>
		<pubDate>Sun, 21 Feb 2010 09:58:43 +0000</pubDate>
		<dc:creator>Karol Zielinski</dc:creator>
				<category><![CDATA[databases]]></category>
		<category><![CDATA[frameworks]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[tools]]></category>
		<category><![CDATA[cascade]]></category>
		<category><![CDATA[pylons]]></category>
		<category><![CDATA[sqlalchemy]]></category>

		<guid isPermaLink="false">http://tech.karolzielinski.com/?p=422</guid>
		<description><![CDATA[While I was working on some project (pylons + sqlalchemy), I had an error: (...) Dependency rule tried to blank-out primary key column...]]></description>
			<content:encoded><![CDATA[<p>While I was working on some project (pylons + sqlalchemy), I had an error: <em>&#8220;ERROR [project.controllers.blog] Dependency rule tried to blank-out primary key column ‘BLOG_TAG_2_ENTRY.id_blog_entry’ on instance&#8221;</em>. How to fix it?</p>
<p><span id="more-422"></span></p>
<p><a href="http://tech.karolzielinski.com/wp-content/uploads/2010/02/sqlalchemy2.gif"><img class="alignnone size-full wp-image-425" title="sqlalchemy" src="http://tech.karolzielinski.com/wp-content/uploads/2010/02/sqlalchemy2.gif" alt="sqlalchemy" width="188" height="52" /></a></p>
<p>Everything is because I forgot about one parameter&#8230; so what I need to do right now, is to add parameter &#8216;cascade&#8217; to my model.</p>
<p>Model with new parameter could looks like:</p>
<pre name="code" class="python">
(...)
tags = relation('BlogTag2Entry', backref='blogentry', order_by='BlogTag2Entry.id_blog_tag', cascade="all")
(...)
</pre>
<p>and that&#8217;s all. Easy, right?</p>
<p>More about this parameter could be found in <a href="http://www.sqlalchemy.org/docs/04/session.html#unitofwork_cascades">SQLAlchemy documentation</a>.</p>
<script src="http://feeds.feedburner.com/~s/?i=http://tech.karolzielinski.com/sqlalchemy-dependency-rule-tried-to-blank-out-primary-key-column" type="text/javascript" charset="utf-8"></script><img src="http://feeds.feedburner.com/~r/JustATechStuff/~4/PMrhgyJVDf8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://tech.karolzielinski.com/sqlalchemy-dependency-rule-tried-to-blank-out-primary-key-column/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://tech.karolzielinski.com/sqlalchemy-dependency-rule-tried-to-blank-out-primary-key-column</feedburner:origLink></item>
		<item>
		<title>Download files from Amazon’s S3</title>
		<link>http://feedproxy.google.com/~r/JustATechStuff/~3/ctH46Z_L1Og/download-files-from-amazons-s3</link>
		<comments>http://tech.karolzielinski.com/download-files-from-amazons-s3#comments</comments>
		<pubDate>Mon, 01 Feb 2010 11:43:43 +0000</pubDate>
		<dc:creator>Karol Zielinski</dc:creator>
				<category><![CDATA[python]]></category>
		<category><![CDATA[amazon]]></category>
		<category><![CDATA[amazon web services]]></category>
		<category><![CDATA[aws]]></category>
		<category><![CDATA[download]]></category>
		<category><![CDATA[s3]]></category>
		<category><![CDATA[script]]></category>

		<guid isPermaLink="false">http://tech.karolzielinski.com/?p=415</guid>
		<description><![CDATA[I had lots of files in my bucket on S3. That's why downloading these files via firefox plugins wasn't the best possible idea...]]></description>
			<content:encoded><![CDATA[<p>I had lots of files in my bucket on S3. That&#8217;s why downloading these files via firefox plugins wasn&#8217;t the best possible idea. I had to create script, which will do it for me.</p>
<p><span id="more-415"></span></p>
<div style="margin-top:30px;">&nbsp;</div>
<p><a href="http://tech.karolzielinski.com/wp-content/uploads/2010/02/logo_aws.gif"><img src="http://tech.karolzielinski.com/wp-content/uploads/2010/02/logo_aws.gif" alt="amazon web services" title="amazon web services" width="164" height="60" class="alignnone size-full wp-image-416" style="margin-bottom:10px;" /></a></p>
<p>Ok, so let&#8217;s code something&#8230;</p>
<p>We need to have one external library in our environment. It&#8217;s <a href="http://code.google.com/p/boto/">boto</a> (Python interface to Amazon Web Services).</p>
<p>Now, create new file (let&#8217;s call it <em>&#8216;download_files_from_s3.py&#8217;</em>) and add there:</p>
<pre name="code" class="python">
from boto.s3 import Connection
import StringIO
import getopt, sys

class Downloader():

    base_dir = None
    bucket_name = None
    aws_access_key_id = 'YOUR_AWS_ACCESS_KEY_ID'
    aws_secret_access_key = 'YOUR_SECRET_ACCESS_KEY'

    def start_downloading(self):

        try:
            opts, args = getopt.getopt(sys.argv[1:], "b:u:", ["help"])
        except getopt.GetoptError, err:
            print "No way! We don't have an option like this one!"
            print str(err)
            sys.exit(2)

        self.base_dir = None
        for o, b in opts:
            if o == "-b":
                self.base_dir = b
                print "I have base_dir"
                print "It's: " + str(self.base_dir)
            if o == "-u":
                self.bucket_name = b
                print "I have bucket_name"
                print "It's: " + str(self.bucket_name)
            elif o in ("-h", "--help"):
                print "No way! We don't have an option like this one!"
                sys.exit()

        if not self.base_dir:
            print "I need base_dir!"
            sys.exit()

        if not self.bucket_name:
            print "I need bucket_name!"
            sys.exit()

        # connect with Amazon S3
        s3_connection = Connection(aws_access_key_id=self.aws_access_key_id,
                                   aws_secret_access_key=self.aws_secret_access_key)
        bucket = s3_connection.get_bucket(self.bucket_name)

        print 'Start fetching keys...'

        keys = []
        rs = bucket.get_all_keys()

        for each in rs:
            keys.append(each)

        print 'Loop nr. 1'
        print str(len(rs)) + ' keys in current loop'

        inc = 2
        while True:
            last = keys[len(keys)-1]

            rs = bucket.get_all_keys(marker=last.key)

            print 'Loop nr. ' + str(inc)
            print str(len(rs)) + ' keys in current loop'

            if len(rs) < 1:
                break
            for each in rs:
                keys.append(each)

            inc += 1

        print 'I have all keys'
        print 'Start downloading...'
        print 'We have ' + str(len(keys)) + ' files to download.'

        inc = 0
        for each in keys:
            orig_image_key = bucket.get_key(each)
            orig_im_temp = StringIO.StringIO(orig_image_key.get_contents_as_string())

            f = open('%s%s' % (self.base_dir, each.name), 'w')
            f.write(orig_im_temp.getvalue())
            f.close()

            inc += 1

            print 'File ' + str(inc) + ' is on local disk'

        print 'All finished.'

def main():
    downloader = Downloader()
    downloader.start_downloading()

if __name__ == '__main__':
    main()
</pre>
<p>Ok, script is ready.</p>
<p>We need to run it by:</p>
<pre>
python download_files_from_s3.py -b our_base_dir -u our_bucket_name
</pre>
<p>where <em>our_base_dir</em> is a path where we want to put downloaded files and <em>our_bucket_name</em> is a name of our bucket on AWS S3.</p>
<script src="http://feeds.feedburner.com/~s/?i=http://tech.karolzielinski.com/download-files-from-amazons-s3" type="text/javascript" charset="utf-8"></script><img src="http://feeds.feedburner.com/~r/JustATechStuff/~4/ctH46Z_L1Og" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://tech.karolzielinski.com/download-files-from-amazons-s3/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://tech.karolzielinski.com/download-files-from-amazons-s3</feedburner:origLink></item>
		<item>
		<title>Some of the buttons in eclipse don’t work</title>
		<link>http://feedproxy.google.com/~r/JustATechStuff/~3/9Rnw6dCTsIs/some-of-the-buttons-in-eclipse-doesnt-work</link>
		<comments>http://tech.karolzielinski.com/some-of-the-buttons-in-eclipse-doesnt-work#comments</comments>
		<pubDate>Fri, 29 Jan 2010 11:32:50 +0000</pubDate>
		<dc:creator>Karol Zielinski</dc:creator>
				<category><![CDATA[tools]]></category>
		<category><![CDATA[button]]></category>
		<category><![CDATA[eclipse]]></category>
		<category><![CDATA[gdk_native_windows]]></category>

		<guid isPermaLink="false">http://tech.karolzielinski.com/?p=409</guid>
		<description><![CDATA[Some time ago I realized that some of the buttons in my eclipse don’t work. I mean that I can’t press it by clicking, but I can press it using keyboard. To fix it… I had to create new file.


It won&#8217;t be a long advice.
Everything what I need to do is to create new file [...]]]></description>
			<content:encoded><![CDATA[<p>Some time ago I realized that some of the buttons in my eclipse don’t work. I mean that I can’t press it by clicking, but I can press it using keyboard. To fix it… I had to create new file.</p>
<p><span id="more-409"></span></p>
<p><a href="http://tech.karolzielinski.com/wp-content/uploads/2010/01/eclipse.jpg"><img src="http://tech.karolzielinski.com/wp-content/uploads/2010/01/eclipse.jpg" alt="eclipse" title="eclipse" width="360" height="238" class="alignnone size-full wp-image-410" /></a></p>
<p>It won&#8217;t be a long advice.</p>
<p>Everything what I need to do is to create new file (let&#8217;s call it <em>eclipse_run.sh</em>) and add there something like:</p>
<pre name="code" class="python">
export GDK_NATIVE_WINDOWS=true
PATH_TO_YOUR_ECLIPSE_RUN_FILE
</pre>
<p>So on my computer it will be:</p>
<pre name="code" class="python">
export GDK_NATIVE_WINDOWS=true
/home/karol/Pulpit/eclipse/eclipse
</pre>
<p>We should have an ability to run it, so we have to do:</p>
<pre>
sudo chmod +x eclipse_run.sh
</pre>
<p>The end.</p>
<p>Now everything what I need to do is to start eclipse via that file.</p>
<script src="http://feeds.feedburner.com/~s/?i=http://tech.karolzielinski.com/some-of-the-buttons-in-eclipse-doesnt-work" type="text/javascript" charset="utf-8"></script><img src="http://feeds.feedburner.com/~r/JustATechStuff/~4/9Rnw6dCTsIs" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://tech.karolzielinski.com/some-of-the-buttons-in-eclipse-doesnt-work/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://tech.karolzielinski.com/some-of-the-buttons-in-eclipse-doesnt-work</feedburner:origLink></item>
		<item>
		<title>Get number of your subscribers from Feedburner</title>
		<link>http://feedproxy.google.com/~r/JustATechStuff/~3/BfTxJ-r_X_Y/get-number-of-your-subscribers-from-feedburner</link>
		<comments>http://tech.karolzielinski.com/get-number-of-your-subscribers-from-feedburner#comments</comments>
		<pubDate>Wed, 27 Jan 2010 11:54:06 +0000</pubDate>
		<dc:creator>Karol Zielinski</dc:creator>
				<category><![CDATA[python]]></category>
		<category><![CDATA[tools]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[feed]]></category>
		<category><![CDATA[feedburner]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[rss]]></category>
		<category><![CDATA[subscriber]]></category>

		<guid isPermaLink="false">http://tech.karolzielinski.com/?p=398</guid>
		<description><![CDATA[While we already know how to create script for getting number of followers from twitter &#8211; now it&#8217;s the best time for getting number of subscribers from feedburner. Everything will be done in python (django).


What is Feedburner? It&#8217;s a great tool for managing RSS feeds.
Why I may want to have number of subscribers? Because we [...]]]></description>
			<content:encoded><![CDATA[<p>While we already know how to <a href="http://tech.karolzielinski.com/download-a-number-of-your-twitter-followers-in-python">create script for getting number of followers from twitter</a> &#8211; now it&#8217;s the best time for getting number of subscribers from <em>feedburner</em>. Everything will be done in python (django).</p>
<p><span id="more-398"></span></p>
<p><a href="http://tech.karolzielinski.com/wp-content/uploads/2010/01/feedburner.png"><img src="http://tech.karolzielinski.com/wp-content/uploads/2010/01/feedburner.png" alt="feedburner" title="feedburner" width="325" height="94" class="alignnone size-full wp-image-401" /></a></p>
<p>What is <a href="http://feedburner.com">Feedburner</a>? It&#8217;s a great tool for managing RSS feeds.</p>
<p>Why I may want to have number of subscribers? Because we may want to show that number on our website.</p>
<p>We will use Feedburner&#8217;s <a href="http://code.google.com/apis/feedburner/">API</a>. What you should read is: <a href="http://code.google.com/apis/feedburner/awareness_api.html#past_basic_feed_awareness_data">Past Basic Feed Awareness Data</a></p>
<p>I will use <a href="http://www.freenet.org.nz/python/xmlobject/">XMLObject</a> class to parse XMLs, because I simply like it.</p>
<p>Ok, let&#8217;s code&#8230;</p>
<p>Open your *.py file (it could be <em>main/views.py</em>) and add there one new method:</p>
<pre name="code" class="python">
def getFeedburner(request):
    from datetime import datetime as datetime2now
	today = datetime2now.now().date()
	actTime = datetime2now.now().timetz()
	actTime = str(actTime)
	actTime = actTime[:8]
	oneDay = datetime.timedelta(days=1)
	twoDays = datetime.timedelta(days=2)
	yesterday = today - oneDay
	twodaysago = today - twoDays

	from develway.main.xmlobject import XMLFile

	url = 'https://feedburner.google.com/api/awareness/1.0/GetFeedData?uri=URI_OF_MY_WEBSITE&#038;dates=' + str(twodaysago) + ',' + str(yesterday)

	f = urllib.urlopen(url)
	xml = f.read()

	xml = XMLFile(raw=xml)
	entries = xml.root.feed.entry

	circulation_yesterday = None
	circulation_twodaysago = None
	for each_entry in entries:
		if each_entry._get('date') == str(yesterday):
			circulation_yesterday = each_entry._get('circulation')
		elif each_entry._get('date') == str(twodaysago):
			circulation_twodaysago = each_entry._get('circulation')

	if circulation_yesterday:
		value = circulation_yesterday
	elif circulation_twodaysago:
		value = circulation_twodaysago

	return HttpResponse(str(value))
</pre>
<p>That&#8217;s all. Now add new view to your <em>urls.py</em>:</p>
<pre name="code" class="python">
    (...)
    (r'^get-feedburner/$', 'YOUR_PROJECT.main.views.getFeedburner'),
</pre>
<p>and test it by going to the URL: http://your_domain/get-feedburner/</p>
<p><strong>Everything should work fine.</strong></p>
<script src="http://feeds.feedburner.com/~s/?i=http://tech.karolzielinski.com/get-number-of-your-subscribers-from-feedburner" type="text/javascript" charset="utf-8"></script><img src="http://feeds.feedburner.com/~r/JustATechStuff/~4/BfTxJ-r_X_Y" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://tech.karolzielinski.com/get-number-of-your-subscribers-from-feedburner/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://tech.karolzielinski.com/get-number-of-your-subscribers-from-feedburner</feedburner:origLink></item>
		<item>
		<title>Build firewall on server (ubuntu)</title>
		<link>http://feedproxy.google.com/~r/JustATechStuff/~3/-UVUh_ffKjg/build-firewall-on-server-ubuntu</link>
		<comments>http://tech.karolzielinski.com/build-firewall-on-server-ubuntu#comments</comments>
		<pubDate>Mon, 25 Jan 2010 11:39:56 +0000</pubDate>
		<dc:creator>Karol Zielinski</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[tools]]></category>
		<category><![CDATA[firewall]]></category>
		<category><![CDATA[port]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[ufw]]></category>

		<guid isPermaLink="false">http://tech.karolzielinski.com/?p=391</guid>
		<description><![CDATA[I would like to secure my VPS. That&#8217;s why I had to find some more informations about firewalls. The most interesting idea&#8230; &#8220;firewall&#8221; via iptales. However managing iptables is a litlle bit complicated, so I decided to use UFW.


What you have to know: UFW is not the firewall. UFW just configures your iptables
And that&#8217;s what [...]]]></description>
			<content:encoded><![CDATA[<p>I would like to secure my VPS. That&#8217;s why I had to find some more informations about firewalls. The most interesting idea&#8230; &#8220;firewall&#8221; via iptales. However managing iptables is a litlle bit complicated, so I decided to use <a href="https://wiki.ubuntu.com/UncomplicatedFirewall">UFW</a>.</p>
<p><span id="more-391"></span></p>
<p><a href="http://tech.karolzielinski.com/wp-content/uploads/2010/01/UbuntuLogo.jpg"><img src="http://tech.karolzielinski.com/wp-content/uploads/2010/01/UbuntuLogo.jpg" alt="ubuntu" title="ubuntu" width="530" height="138" class="alignnone size-full wp-image-393" /></a></p>
<p>What you have to know: <strong>UFW is not the firewall. UFW just configures your iptables</strong></p>
<p>And that&#8217;s what I was looking for.</p>
<p>First&#8230; check what you have installed on your server and which ports are opened. Do it by <em>&#8216;ps -aux&#8217;</em> and <em>&#8216;nmap&#8217;</em>. Consider which ports you would like to have opened and which ones should be closed.</p>
<p>Next&#8230; install UFW:</p>
<pre>
sudo apt-get install ufw
</pre>
<p>and disable all ports:</p>
<pre>
sudo ufw default deny
</pre>
<p>Next&#8230; configure your firewall. </p>
<p>I would like to have one port opened (80) and one port opened just for my IP (22). So I need to do:</p>
<pre>
sudo ufw allow to any port 80
sudo ufw allow from MY_IP_ADDRESS to any port 22
</pre>
<p>and that&#8217;s all.</p>
<p>Now turn on the firewall:</p>
<pre>
sudo ufw enable
</pre>
<p>and check everything:</p>
<pre>
sudo ufw status
</pre>
<p>More commands and informations related to UFW:<br />
<a href="http://ubuntuforums.org/showthread.php?t=823741">http://ubuntuforums.org/showthread.php?t=823741</a></p>
<script src="http://feeds.feedburner.com/~s/?i=http://tech.karolzielinski.com/build-firewall-on-server-ubuntu" type="text/javascript" charset="utf-8"></script><img src="http://feeds.feedburner.com/~r/JustATechStuff/~4/-UVUh_ffKjg" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://tech.karolzielinski.com/build-firewall-on-server-ubuntu/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://tech.karolzielinski.com/build-firewall-on-server-ubuntu</feedburner:origLink></item>
		<item>
		<title>Get number of your twitter followers in python</title>
		<link>http://feedproxy.google.com/~r/JustATechStuff/~3/oXl8KAvo6Cc/download-a-number-of-your-twitter-followers-in-python</link>
		<comments>http://tech.karolzielinski.com/download-a-number-of-your-twitter-followers-in-python#comments</comments>
		<pubDate>Mon, 18 Jan 2010 12:01:01 +0000</pubDate>
		<dc:creator>Karol Zielinski</dc:creator>
				<category><![CDATA[frameworks]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[followers]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://tech.karolzielinski.com/?p=383</guid>
		<description><![CDATA[We already know how to implement functionality for automatic adding statuses to twitter. Today we will implement a functionality for automatic downloading a number of your twitter followers in python (django).

&#160;

Everything via twitter API.
We will use only one method from this API, so we need to read &#8220;Twitter REST API Method: followers ids&#8221; section in [...]]]></description>
			<content:encoded><![CDATA[<p>We already know how to implement<a href="http://tech.karolzielinski.com/django-twitter-com-automatic-new-statuses"> functionality for automatic adding statuses to twitter</a>. Today we will implement a functionality for automatic downloading a number of your twitter followers in python (django).</p>
<p><span id="more-383"></span></p>
<div style="margin-top:20px;">&nbsp;</div>
<p><a href="http://tech.karolzielinski.com/wp-content/uploads/2010/01/twitter-logo.png"><img src="http://tech.karolzielinski.com/wp-content/uploads/2010/01/twitter-logo.png" alt="" title="twitter logo" width="224" height="55" class="alignnone size-full wp-image-377" /></a></p>
<p>Everything via <a href="http://apiwiki.twitter.com/Twitter-API-Documentation">twitter API</a>.</p>
<p>We will use only one method from this API, so we need to read &#8220;Twitter REST API Method: followers ids&#8221; section in this documentation. You can find this section <a href="http://apiwiki.twitter.com/Twitter-REST-API-Method%3A-followers%C2%A0ids">here</a>.</p>
<p>Let&#8217;s fun.</p>
<p>We will download amount of followers of <a href="http://twitter.com/develway">@develway</a>. That&#8217;s an account of a <a href="http://develway.pl">website</a> for IT specialists and programmers.</p>
<p>Open *.py file (for example <em>main/views.py</em>) and add there a new method:</p>
<pre name="code" class="python">
def downloadTwitterFollowers(request):
	import urllib2, urllib
    from django.utils import simplejson

	request = urllib2.Request('http://twitter.com/followers/ids.json?screen_name=develway&#038;cursor=-1')
	response = urllib2.urlopen(request)

	ids = response.read()
	ids = simplejson.loads(ids)

	followers = len(ids['ids'])

	return HttpResponse('Amount of followers: ' + str(followers))
</pre>
<p>Now add new view to your <em>urls.py</em>&#8230;</p>
<p>Open the urls.py file and add there something like:</p>
<pre name="code" class="python">
(r'^download-twitter-followers/$', 'ourProject.main.views.downloadTwitterFollowers'),
</pre>
<p>Save it and try to run <em>http://yourdomain.com/download-twitter-followers/</em> in your web browser.</p>
<p><strong>Easy, isn&#8217;t it?</strong></p>
<script src="http://feeds.feedburner.com/~s/?i=http://tech.karolzielinski.com/download-a-number-of-your-twitter-followers-in-python" type="text/javascript" charset="utf-8"></script><img src="http://feeds.feedburner.com/~r/JustATechStuff/~4/oXl8KAvo6Cc" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://tech.karolzielinski.com/download-a-number-of-your-twitter-followers-in-python/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://tech.karolzielinski.com/download-a-number-of-your-twitter-followers-in-python</feedburner:origLink></item>
		<item>
		<title>django + twitter.com: automatic new statuses</title>
		<link>http://feedproxy.google.com/~r/JustATechStuff/~3/6uPkFsPzPhc/django-twitter-com-automatic-new-statuses</link>
		<comments>http://tech.karolzielinski.com/django-twitter-com-automatic-new-statuses#comments</comments>
		<pubDate>Thu, 14 Jan 2010 14:30:29 +0000</pubDate>
		<dc:creator>Karol Zielinski</dc:creator>
				<category><![CDATA[python]]></category>
		<category><![CDATA[microblogging]]></category>
		<category><![CDATA[status]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://tech.karolzielinski.com/?p=373</guid>
		<description><![CDATA[Earlier we created functionality for automatic adding of statuses to blip.pl. Today we would like to do the same thing, however for adding statuses to twitter.com. It will be based on twitter API, so without any &#8220;hacks&#8221;.

&#160;

Everybody knows what is twitter, so I won&#8217;t describe it here. I just want to give you a link [...]]]></description>
			<content:encoded><![CDATA[<p>Earlier we created <a href="http://tech.karolzielinski.com/django-blip-pl-automatic-new-statuses">functionality for automatic adding of statuses to blip.pl</a>. Today we would like to do the same thing, however for adding statuses to <a href="http://twitter.com">twitter.com</a>. It will be based on <em>twitter API</em>, so without any &#8220;hacks&#8221;.</p>
<p><span id="more-373"></span></p>
<div style="margin-top:20px;">&nbsp;</div>
<p><img src="http://tech.karolzielinski.com/wp-content/uploads/2010/01/twitter-logo.png" alt="" title="twitter logo" width="224" height="55" class="alignnone size-full wp-image-377" /></p>
<p>Everybody knows what is <em>twitter</em>, so I won&#8217;t describe it here. I just want to give you a link to official documantation of <em>twitter&#8217;s API</em>: <a href="http://apiwiki.twitter.com/Twitter-API-Documentation">http://apiwiki.twitter.com/Twitter-API-Documentation</a>.</p>
<p>We will use only one method from this API, so we need to read <em>&#8220;Twitter REST API Method: statuses/update&#8221;</em> section in this documentation. You can find this section <a href="http://apiwiki.twitter.com/Twitter-REST-API-Method%3A-statuses%C2%A0update">here</a>.</p>
<p>I prefer JSON format, than XML in communication with any API.</p>
<p>So, let&#8217;s fun.</p>
<p>Open *.py file with your model and change <em>&#8220;save()&#8221;</em> method:</p>
<pre name="code" class="python">
def save(self):
    if not self.id:
        import urllib2, urllib

        twitter_status = self.title + ' http://our_domain_name/' + str(self.slug)

        request = urllib2.Request('http://twitter.com/statuses/update.json')
        request.headers['Authorization'] = 'Basic %s' % ( base64.b64encode('TWITTER_USERNAME:TWITTER_PASSWORD'),)
        request.data = urllib.urlencode({'status': twitter_status})
        response = urllib2.urlopen(request)
</pre>
<p>and that&#8217;s all.</p>
<p>After you will <strong>add</strong> new item to this model &#8211; message with title of an item (<em>self.title</em>) and link to this item (<em>self.slug</em>) will be added to your account on <em>twitter.com</em>.</p>
<p><strong>Easy, isnt&#8217;t it?</strong></p>
<p>Btw. Yes. I know that base64 is not as safe, as oAuth. However this way is much faster to implement.</p>
<script src="http://feeds.feedburner.com/~s/?i=http://tech.karolzielinski.com/django-twitter-com-automatic-new-statuses" type="text/javascript" charset="utf-8"></script><img src="http://feeds.feedburner.com/~r/JustATechStuff/~4/6uPkFsPzPhc" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://tech.karolzielinski.com/django-twitter-com-automatic-new-statuses/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		<feedburner:origLink>http://tech.karolzielinski.com/django-twitter-com-automatic-new-statuses</feedburner:origLink></item>
		<item>
		<title>django + blip.pl: automatic new statuses</title>
		<link>http://feedproxy.google.com/~r/JustATechStuff/~3/uxkFTC97p-E/django-blip-pl-automatic-new-statuses</link>
		<comments>http://tech.karolzielinski.com/django-blip-pl-automatic-new-statuses#comments</comments>
		<pubDate>Tue, 12 Jan 2010 14:48:41 +0000</pubDate>
		<dc:creator>Karol Zielinski</dc:creator>
				<category><![CDATA[python]]></category>
		<category><![CDATA[blip]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[microblogging]]></category>
		<category><![CDATA[status]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://tech.karolzielinski.com/?p=361</guid>
		<description><![CDATA[blip.pl is a Polish microblogging service (some kind of Polish twitter). Today I&#8217;d like to present how to integrate python application (django application) with blip.pl API.

First of all&#8230; full documentation of blip.pl API is available here: http://blip.pl/api-0.02.html
It&#8217;s in Polish, however if you want to integrate your app with this service you propably know Polish (if [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://blip.pl">blip.pl</a> is a Polish microblogging service (some kind of Polish <a href="http://twitter.com">twitter</a>). Today I&#8217;d like to present how to integrate python application (django application) with blip.pl API.</p>
<p><span id="more-361"></span></p>
<p>First of all&#8230; full documentation of blip.pl API is available here: <a href="http://blip.pl/api-0.02.html">http://blip.pl/api-0.02.html</a></p>
<p>It&#8217;s in Polish, however if you want to integrate your app with this service you propably know Polish (if not &#8211; notice, that it works as a standard REST + JSON compilation, so it shouldn&#8217;t be a problem to implement this functionality even for someone, who doesn&#8217;t Polish).</p>
<p>Ok, stop talking, start coding&#8230;</p>
<p>Open *.py file with your model and change <em>&#8220;save()&#8221;</em> method:</p>
<pre name="code" class="python">
def save(self):
    if not self.id:
        if self.blip_message:
	        import httplib, base64
	        from django.utils import simplejson

  	        http_url = 'http://api.blip.pl/updates'
                API_HEADERS = {
	            'Content-Type' : 'application/json',
	            'X-Blip-api' : '0.02',
	            'User-Agent' : 'Karol Zielinski blip API',
	            'Authorization' : 'Basic %s' % (base64.b64encode('BLIP.PL_USERNAME:BLIP.PL_PASSWORD'))
	        }

	        update = {}
	        update['body'] = self.blip_message

	        post_params = simplejson.dumps(update)

	        connection = httplib.HTTPConnection('api.blip.pl')
	        connection.request('POST', http_url, headers=API_HEADERS, body=post_params)

	        response = connection.getresponse()
	        headers = response.getheaders()
	        status = response.status
	        resp_data = response.read()
</pre>
<p>and that&#8217;s all.</p>
<p>After you will <strong>add</strong> new item to this model &#8211; message from attribute <em>blip_message</em> will be added to your account on <em>blip.pl</em>.</p>
<p><strong>Easy, isnt&#8217;t it?</strong></p>
<script src="http://feeds.feedburner.com/~s/?i=http://tech.karolzielinski.com/django-blip-pl-automatic-new-statuses" type="text/javascript" charset="utf-8"></script><img src="http://feeds.feedburner.com/~r/JustATechStuff/~4/uxkFTC97p-E" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://tech.karolzielinski.com/django-blip-pl-automatic-new-statuses/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		<feedburner:origLink>http://tech.karolzielinski.com/django-blip-pl-automatic-new-statuses</feedburner:origLink></item>
		<item>
		<title>INSERT or UPDATE in django’s save() method</title>
		<link>http://feedproxy.google.com/~r/JustATechStuff/~3/a9AsoU4-yxA/insert-or-update-in-djangos-save-method</link>
		<comments>http://tech.karolzielinski.com/insert-or-update-in-djangos-save-method#comments</comments>
		<pubDate>Tue, 05 Jan 2010 12:29:02 +0000</pubDate>
		<dc:creator>Karol Zielinski</dc:creator>
				<category><![CDATA[frameworks]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[insert]]></category>
		<category><![CDATA[model]]></category>
		<category><![CDATA[save]]></category>
		<category><![CDATA[update]]></category>

		<guid isPermaLink="false">http://tech.karolzielinski.com/?p=352</guid>
		<description><![CDATA[Django uses save() method in models to save all kind of data into database. This method is used by framework when you want to add or edit data. That&#8217;s great, however sometimes we need to know is it INSERT, or maybe UPDATE. How to check it?


Answer is really simple: by checking primary key.
From django&#8217;s documentation:

Specifically, [...]]]></description>
			<content:encoded><![CDATA[<p>Django uses save() method in models to save all kind of data into database. This method is used by framework when you want to add or edit data. That&#8217;s great, however sometimes we need to know is it INSERT, or maybe UPDATE. How to check it?</p>
<p><span id="more-352"></span></p>
<p><a href="http://tech.karolzielinski.com/wp-content/uploads/2010/01/django-logo.png"><img src="http://tech.karolzielinski.com/wp-content/uploads/2010/01/django-logo.png" alt="django" title="django" width="530" height="195" class="alignnone size-full wp-image-357" /></a></p>
<p>Answer is really simple: <strong>by checking primary key</strong>.</p>
<p>From django&#8217;s documentation:</p>
<blockquote><p>
Specifically, when you call save(), Django follows this algorithm:</p>
<ul>
<li>If the object&#8217;s primary key attribute is set to a value that evaluates to True (i.e., a value other than None or the empty string), Django executes a SELECT query to determine whether a record with the given primary key already exists.</li>
<li>If the record with the given primary key does already exist, Django executes an UPDATE query.</li>
<li>If the object&#8217;s primary key attribute is not set, or if it&#8217;s set but a record doesn&#8217;t exist, Django executes an INSERT.</li>
</ul>
</blockquote>
<p>So&#8230; we just need to check primary key.</p>
<p>My save() method looks like:</p>
<pre name="code" class="python">
def save(self):
    if not self.id:
        # what I want to do if it's INSERT statement
    else:
        # what I want to do if it's UPDATE statement

    super(MyObject, self).save()
</pre>
<p>Notice: <strong><em>&#8220;super(MyObject, self).save()&#8221;</em> has to be called after checking is it INSERT or UPDATE.</strong></p>
<script src="http://feeds.feedburner.com/~s/?i=http://tech.karolzielinski.com/insert-or-update-in-djangos-save-method" type="text/javascript" charset="utf-8"></script><img src="http://feeds.feedburner.com/~r/JustATechStuff/~4/a9AsoU4-yxA" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://tech.karolzielinski.com/insert-or-update-in-djangos-save-method/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		<feedburner:origLink>http://tech.karolzielinski.com/insert-or-update-in-djangos-save-method</feedburner:origLink></item>
	</channel>
</rss>
