Coder of Salvation™   — programming / opensource / console / minimal

Imapmunch php cli-cmd

Problem

Example: If you and other employees send you bills, you have to go thru labourous sessions of putting everything in excel to generate overviews.

Solution

Requirements

Example

Here you can see a small bashscript which summarizes all the bills that were send to me. Each time I take a picture of a bill with my smartphone, I just put 'bill #budgetfoo xxxxft' in the subject, so the following bashscript can interpret it using imapmunch:

#!/bin/bash 

summarize(){
  json=$(cat - )
  q="'"
  phpcode='
    $json = '$q''$json''$q';
    $bills = json_decode( $json );
    $debt = 0;
    foreach( $bills->emails as $bill ){
      printf("%14s %10s %20s\n", $bill->forint, $bill->id, $bill->subject );
      $debt += (int)$bill->forint;
    }
    $budget_euro   = 1000;
    $currency_ft   = 282;
    $budget_forint = $budget_euro*$currency_ft;
    $budget_remain_forint = $budget_forint + $debt;
    $budget_remain_euro = $budget_remain_forint / 282;
    print("\n\ndebt  = {$debt} ft (=".($debt/$currency_ft)." Euro)\n");
    print("\n\nremain= {$budget_remain_forint} ft (={$budget_remain_euro} Euro)\n");
  '
  php -r "$phpcode"
}

./imapmunch -SUBJECT='bill ' --prices --exclude="cashmachine" --downloadpath="/var/www/dropbox/bills/" --output=json | summarize

Output

[x] checking email #2609
[email #2609] writing '/var/www/dropbox/bills/2609_photo.JPG'
[x] checking email #2606
[x] checking email #2601
[x] checking email #2600
[x] checking email #2597
[x] checking email #2596
[x] checking email #2576
[x] checking email #2566
[x] checking email #2548
[x] checking email #2547
[x] checking email #2546
[x] checking email #2513
[x] checking email #2509
[x] checking email #2499
[x] checking email #2486
[x] checking email #2485
[x] checking email #2476
[x] checking email #1127
       -219800       2609 bill #foobudget 219800ft #someitem 2x
          -290       2606 bill #foobudget 290ft #teaspoon #ketchup
         -2380       2601 bill #foobudget powerbox 2380ft (2476_photo.JPG)
         -5000       2600 bill #teaspoon 5000ft #tipped (2499_photo.JPG) (fwd)
         -5600       2597 bill #foobudget #teaspoon 5600ft #tipped (fwd)
         -3899       2576 bill #foobudget 3899ft #skull 
         -6000       2566 bill #foobudget -6000ft #teaspoon
         -1090       2548 bill #foobudget #teaspoon -1090ft
         -4370       2547 bill #foobudget #teaspoon -4370ft
         -1840       2546 bill #foobudget -1840ft #mitchell -1000ft #henry -1000ft
       -138998       2509 bill -138998ft laptop
debt  = -389267 ft (=-1380.3794326241 Euro)
remain= -107160 ft (= -380 Euro)

Oops, out of budget :)

Installation



comments powered by Disqus


All rights reserved by Leon van Kammen under this license