Skip to content

Instantly share code, notes, and snippets.

@isotopp
Created December 12, 2013 09:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save isotopp/7925522 to your computer and use it in GitHub Desktop.
Save isotopp/7925522 to your computer and use it in GitHub Desktop.
I cut and pasted my https://play.google.com/store/account?purchaseFilter=apps into a text file, and got a file of the format #0: Trees for Cars by Leo Grand #1: 0,99 $ #2: December 11, 2013 #3: Complete #4: Android Apps #5: Transportation What I wanted were stats. Here we go...
#! /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":"";
}
var_dump($currency);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment