-
-
Save splitbrain/7930280 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/php | |
<?php | |
class AndroidApp { | |
#0: Trees for Cars by Leo Grand | |
#1: 0,99 $ | |
#2: December 11, 2013 | |
#3: Complete | |
#4: Android Apps | |
#5: Transportation | |
var $name; | |
var $price; | |
var $currency; | |
var $date; | |
var $status; | |
var $type; | |
var $category; | |
function fix_currency() { | |
$curr = $this->price; | |
if (strpos($curr, "\$") !== FALSE) { | |
$this->currency = "USD"; | |
$this->price = trim(substr($curr, 0, -1)); | |
} | |
if (strpos($curr, "€") !== FALSE) { | |
$this->currency = "EUR"; | |
$this->price = trim(substr($curr, 0, -3)); | |
} | |
if (strpos($curr, "£") !== FALSE) { | |
$this->currency = "UKP"; | |
$this->price = trim(substr($curr, 0, -3)); | |
} | |
if (strpos($curr, "CHF") !== FALSE) { | |
$this->currency = "CHF"; | |
$this->price = trim(substr($curr, 0, -3)); | |
} | |
if ($curr === "Free") { | |
$this->currency = "EUR"; | |
$this->price = "0.00"; | |
} | |
$this->price = str_replace(",", ".", $this->price); | |
$this->price += 0.00; | |
return; | |
} | |
function __construct($c) { | |
$a = array(); | |
for ($i=0; $i<6; $i++) { | |
if ($c->eof()) | |
return; | |
$a[] = trim($c->fgets()); | |
} | |
$this->name = $a[0]; | |
$this->price = $a[1]; | |
$this->date = $a[2]; | |
$this->status = $a[3]; | |
$this->type = $a[4]; | |
$this->category = $a[5]; | |
$this->fix_currency(); | |
return $this; | |
} | |
} | |
try { | |
$file = new SplFileObject("apps.txt"); | |
} catch (RuntimeException $e) { | |
die($e->getMessage(). "\n"); | |
}; | |
$file->setFlags(SplFileObject::DROP_NEW_LINE); | |
$apps = array(); | |
while (!$file->eof()) { | |
$a = new AndroidApp($file); | |
if (!$file->eof()) | |
$apps[] = $a; | |
} | |
foreach ($apps as $k => $v) { | |
$currency[$v->currency]['sum'] += $v->price; | |
$currency[$v->currency]['count'] ++; | |
$currency[$v->currency]['title'] .= $v->price >0?"{$v->name} for {$v->price}\n":""; | |
} | |
print_r($currency); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment