Product Receipt

Adds together items and content from sellcofee/archive


In [1]:
import os
import json
import dominate
from dominate.tags import * 
from time import gmtime, strftime
import time

In [2]:
arctdir = ('/home/wcmckee/sellcoffee/archive/')

In [3]:
arctdir


Out[3]:
'/home/wcmckee/sellcoffee/archive/'

In [4]:
lisar = os.listdir(arctdir)

In [5]:
finlis = []

In [7]:
for li in lisar:
    print (li)
    opli = open(arctdir + li, 'r')
    oprd = opli.read()
    finlis.append(oprd)


2015-03-03-032951.json
2015-03-03-033840.json
2015-03-03-033001.json
2015-03-03-033017.json
2015-03-03-033847.json
2015-03-03-033007.json

In [8]:
#Merge together sales by time.

In [9]:
#deblis =

In [10]:
for fi in finlis:
    #print fi
    newjs = json.loads(fi)
    print (newjs['product'])
    print (newjs)
    #print newjs['cost']
    print (newjs['time'])
    print (newjs['date'])
    print (newjs['amount'])


debian
{'time': '032951', 'amount': 3, 'date': '2015-03-03', 'product': 'debian'}
032951
2015-03-03
3
debian
{'time': '033840', 'amount': 3, 'date': '2015-03-03', 'product': 'debian'}
033840
2015-03-03
3
portrait
{'time': '033001', 'amount': 2, 'date': '2015-03-03', 'product': 'portrait'}
033001
2015-03-03
2
portrait
{'time': '033017', 'amount': 5, 'date': '2015-03-03', 'product': 'portrait'}
033017
2015-03-03
5
portrait
{'time': '033847', 'amount': 2, 'date': '2015-03-03', 'product': 'portrait'}
033847
2015-03-03
2
debian
{'time': '033007', 'amount': 1, 'date': '2015-03-03', 'product': 'debian'}
033007
2015-03-03
1

In [14]:
jsdic = dict()

In [ ]:


In [ ]:
for fi in finlis:
            #print fi
            newjs = json.loads(fi)
            h1(newjs['product'])
            #print newjs
            #print newjs['cost']
            p(newjs['time'])
            p(newjs['date'])
            p(newjs['amount'])

In [11]:
finlis


Out[11]:
['{"date": "2015-03-03", "product": "debian", "amount": 3, "time": "032951"}',
 '{"date": "2015-03-03", "product": "debian", "amount": 3, "time": "033840"}',
 '{"date": "2015-03-03", "product": "portrait", "amount": 2, "time": "033001"}',
 '{"date": "2015-03-03", "product": "portrait", "amount": 5, "time": "033017"}',
 '{"date": "2015-03-03", "product": "portrait", "amount": 2, "time": "033847"}',
 '{"date": "2015-03-03", "product": "debian", "amount": 1, "time": "033007"}']

In [13]:
doc = dominate.document(title='BroBeur CyberCafe Transactions')

with doc.head:
    link(rel='stylesheet', href='style.css')
    script(type ='text/javascript', src='script.js')
    #str(str2)
    
    with div():
        attr(cls='header')
        h1('BroBeur CyberCafe Transactions')
        h3('BroBeur CyberCafe Transactions')
        #p(img('imgs/getsdrawn-bw.png', src='imgs/getsdrawn-bw.png'))
        #p(img('imgs/15/01/02/ReptileLover82-reference.png', src= 'imgs/15/01/02/ReptileLover82-reference.png'))
        p('Updated ', strftime("%a, %d %b %Y %H:%M:%S +0000", gmtime()))
        #p(panz)
        #p(bodycom)
    
    

with doc:
    with div(id='body').add(ol()):
        for fi in finlis:
            #print fi
            newjs = json.loads(fi)
            h1(newjs['product'])
            #print newjs
            #print newjs['cost']
            p(newjs['time'])
            p(newjs['date'])
            p(newjs['amount'])
            #print newjs['cost']
            #oprdz = open((prodir + rdz + '/' + rdz + '-id'), 'r')
            #p('id: ' + oprdz.read())
            #oprdz.close()
            
            #prrdz = open((prodir + rdz + '/' + rdz + '-price'), 'r')
            #p('price: ' + prrdz.read())
            #prrdz.close()


                
            #print rdz.url
            #if '.jpg' in rdz.url:
            #    img(rdz.urlz)
            #else:
            #    a(rdz.urlz)
            #h1(str(rdz.author))
            
            #li(img(i.lower(), src='%s' % i))

    with div():
        attr(cls='body')
        p('sellcoffee is open source')
        a('https://github.com/wcmckee/lcacoffee')
        #a('https://reddit.com/r/redditgetsdrawn')

print (doc)


<!DOCTYPE html>
<html>
  <head>
    <title>BroBeur CyberCafe Transactions</title>
    <link href="style.css" rel="stylesheet"><script src="script.js" type="text/javascript"></script>
    <div class="header">
      <h1>BroBeur CyberCafe Transactions</h1>
      <h3>BroBeur CyberCafe Transactions</h3>
      <p>Updated Sun, 02 Aug 2015 05:55:08 +0000</p>
    </div>
  </head>
  <body>
    <div id="body">
      <ol>
        <h1>debian</h1>
        <p>032951</p>
        <p>2015-03-03</p>
        <p>3</p>
        <h1>debian</h1>
        <p>033840</p>
        <p>2015-03-03</p>
        <p>3</p>
        <h1>portrait</h1>
        <p>033001</p>
        <p>2015-03-03</p>
        <p>2</p>
        <h1>portrait</h1>
        <p>033017</p>
        <p>2015-03-03</p>
        <p>5</p>
        <h1>portrait</h1>
        <p>033847</p>
        <p>2015-03-03</p>
        <p>2</p>
        <h1>debian</h1>
        <p>033007</p>
        <p>2015-03-03</p>
        <p>1</p>
      </ol>
    </div>
    <div class="body">
      <p>sellcoffee is open source</p>
      <a>https://github.com/wcmckee/lcacoffee</a>
    </div>
  </body>
</html>

In [ ]:
docre = doc.render()
#s = docre.decode('ascii', 'ignore')
yourstring = docre.encode('ascii', 'ignore').decode('ascii')
indfil = ('/home/wcmckee/sellreceipt/index.html')
mkind = open(indfil, 'w')
mkind.write(yourstring)
mkind.close()