productreceipt

Product Receipt

Adds together items and content from sellcofee/archive

In [39]:
import os
import json
import dominate
from dominate.tags import * 
from time import gmtime, strftime
import time
In [30]:
arctdir = ('/home/wcmckee/sellcoffee/archive/')
In [31]:
arctdir
Out[31]:
'/home/wcmckee/sellcoffee/archive/'
In [32]:
lisar = os.listdir(arctdir)
In [33]:
finlis = []
In [34]:
for li in lisar:
    print li
    opli = open(arctdir + li, 'r')
    oprd = opli.read()
    finlis.append(oprd)
2015-03-03-032826.json
2015-03-03-032821.json
In [35]:
#Merge together sales by time.
In [36]:
#deblis = 
  File "<ipython-input-36-a5468364108c>", line 1
    deblis =
             ^
SyntaxError: invalid syntax
In [37]:
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']
portrait
{u'date': u'2015-03-03', u'product': u'portrait', u'amount': 2, u'time': u'032826'}
032826
2015-03-03
2
debian
{u'date': u'2015-03-03', u'product': u'debian', u'amount': 5, u'time': u'032821'}
032821
2015-03-03
5
In [41]:
finlis
Out[41]:
['{"date": "2015-03-03", "product": "portrait", "amount": 2, "time": "032826"}',
 '{"date": "2015-03-03", "product": "debian", "amount": 5, "time": "032821"}']
In [40]:
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 products</h1>
      <h3>BroBeur CyberCafe Products</h3>
      <p>Updated Tue, 03 Mar 2015 03:37:48 +0000</p>
    </div>
  </head>
  <body>
    <div id="body">
      <ol>
        <h1>portrait</h1>
        <p>032826</p>
        <p>2015-03-03</p>
        <p>2</p>
        <h1>debian</h1>
        <p>032821</p>
        <p>2015-03-03</p>
        <p>5</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()

Comments

Comments powered by Disqus