<?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>seeking immortality &#187; python</title>
	<atom:link href="http://blag.sebacean.net/tag/python/feed/" rel="self" type="application/rss+xml" />
	<link>http://blag.sebacean.net</link>
	<description>where are we going, and why am i in this handbasket</description>
	<lastBuildDate>Tue, 22 Dec 2009 23:26:40 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>o2 Germany billparser (zählt Minuten und SMS)</title>
		<link>http://blag.sebacean.net/2009/03/o2-germany-billparser-zahlt-minuten-und-sms/</link>
		<comments>http://blag.sebacean.net/2009/03/o2-germany-billparser-zahlt-minuten-und-sms/#comments</comments>
		<pubDate>Mon, 30 Mar 2009 17:19:53 +0000</pubDate>
		<dc:creator>me</dc:creator>
				<category><![CDATA[german]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[mobile]]></category>
		<category><![CDATA[money]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://blag.sebacean.net/?p=95</guid>
		<description><![CDATA[Nach den angekündigten Preiserhöhungen bei o2 (Golem) habe ich meinen (im Sommer auslaufenden) Vertrag mit einem entsprechend erbostem Schreiben gekündigt. Um nun einen guten neuen Vertrag zu finden wollte ich genauer wissen wieviel Minuten/SMS ich denn so brauche&#8230; Da ich schon seit Langem immer fleißig die .csv files zu den Rechnungen herunterladen hab ich schnell]]></description>
			<content:encoded><![CDATA[<p>Nach den angekündigten Preiserhöhungen bei o2 (<a href="http://www.golem.de/0903/65649.html">Golem</a>) habe ich meinen (im Sommer auslaufenden) Vertrag mit einem entsprechend erbostem Schreiben gekündigt. Um nun einen guten neuen Vertrag zu finden wollte ich genauer wissen wieviel Minuten/SMS ich denn so brauche&#8230;</p>
<p>Da ich schon seit Langem immer fleißig die .csv files zu den Rechnungen herunterladen hab ich schnell folgendes Python Script geschrieben das mir die Zählarbeit erleichtert (und Schreikrämpfe in Excel verhindert).</p>
<p>Als kleinen Bonus zählt es auch (etwas inexakt fürchte ich) die Homezone Minuten, daraus kann man ablesen was das Verlieren von Genion für Auswirkungen hat.</p>
<pre class="brush: python">
# parses .csv files from o2 germany billing
# counts talked minutes (&#039;sprache&#039; in &#039;ART&#039;) and sms sent (&#039;sms&#039; in &#039;TARIFGRUPPE&#039;)
# ignores international minutes/sms
import csv
import glob
import string

# &lt;config&gt;
mypath = &#039;*.csv&#039; # e.g. &#039;./mybills/*.csv&#039;
mydelimiter = &#039;|&#039; # &#039;|&#039; aka &quot;pipe&quot; is default with o2
# &lt;/config&gt;

if __name__ == &quot;__main__&quot;:
files = glob.glob(mypath)
assert len(files) &gt; 0, &quot;Error! No Files found (check path)&quot;

totalminutes = 0
totalsms = 0
totalhomezone = 0
for file in files:
csvfile = open(file)
reader = csv.DictReader(csvfile,delimiter=mydelimiter)
smscount = 0
timecount = dict(hours=0,minutes=0,seconds=0)
homezonecount = 0
for row in reader:
if &#039;sprache&#039; in string.lower(row[&#039;ART&#039;]):
(h,m,s) = string.split(row[&#039;DAUER&#039;], &#039;:&#039;)
timecount[&#039;hours&#039;] += int(h)
timecount[&#039;minutes&#039;] += int(m)
timecount[&#039;seconds&#039;] += int(s)
if &#039;homezone&#039; in string.lower(row[&#039;TARIFGRUPPE&#039;]):
homezonecount += int(m) + (int(h)*60) + (int(s)/60)
if &#039;sms&#039; in string.lower(row[&#039;TARIFGRUPPE&#039;]):
smscount = smscount + 1
minutes = timecount[&#039;minutes&#039;] + (timecount[&#039;hours&#039;]*60) + (timecount[&#039;seconds&#039;]/60)
totalminutes += minutes
totalsms += smscount
totalhomezone += homezonecount
print(file+&#039; &#039;+str(minutes)+&#039; Minutes &#039;+str(smscount)+&#039; SMS (&#039;+str(homezonecount)+&#039; Minutes in Homezone)&#039;)
assert minutes &gt;= homezonecount, &quot;Error! More minutes in homezone than total?&quot;
# the cool .format prints only work in python 2.6 ...
#print(&#039;Total  :{0:4} Minutes and {1:4} SMS in {2} Months ({3:4} Minutes in Homezone)&#039;.format(totalminutes,totalsms,len(files),totalhomezone))
#print(&#039;Average:{0:4} Minutes and {1:4} SMS per Month&#039;.format(totalminutes/len(files),totalsms/len(files)))
# ... and since that isn&#039;t in debian stable yet... i added &quot;old&quot; prints
print(&#039;Total   &#039;+str(totalminutes)+&#039; Minutes &#039;+str(totalsms)+&#039; SMS in &#039;+str(len(files))+&#039; Months (&#039;+str(totalhomezone)+&#039; Minutes in Homezone)&#039;)
print(&#039;Average &#039;+str(totalminutes/len(files))+&#039; Minutes &#039;+str(totalsms/len(files))+&#039; SMS per Month&#039;)
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blag.sebacean.net/2009/03/o2-germany-billparser-zahlt-minuten-und-sms/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
