Product Sell

Script to sell a product.

Gets products list from /sellcoffee/products folder. input what to sell. or input 4 digit code of product.

Input amount of product to sell

Processes the sale, increasing number of product filename by input amount to sell.

Creates dict of sale, includes time, date, product (inputed data), amount (inputed sales amount), served by, hostname of machine that processed transaction, e receipts.


In [156]:
import os
import arrow
import json
from TwitterFollowBot import TwitterBot

In [157]:
rdtwb = TwitterBot('/home/wcmckee/github/wcmckee-notebook/config.txt')

In [ ]:


In [158]:
prodir = ('/home/wcmckee/sellcoffee/products/')

In [159]:
lsprod = os.listdir(prodir)

In [160]:
print (lsprod)


['followers.txt', 'coffee', 'crayons', 'port-royalport-royalindex.json', 'MarQuis Black CondomsMarQuis Black Condomsindex.json', 'port-royal', 'MarQuis Black Condoms', 'already-followed.txt', 'following.txt', 'coffeecoffeeindex.json']

In [162]:
sellwhat = input('Sell what: ')


Sell what: port-royal

In [163]:
fpathz = (prodir + sellwhat + '/' + sellwhat + '-amount')

In [164]:
#Open the file up and increase the sale number by one.

selinp = open(fpathz, 'r')

cursal = selinp.read()

selinp.close()

In [165]:
print (cursal)


0

In [166]:
conint = int(cursal)

In [167]:
#1 is amount to sell. Maybe raw_input enter int to sell more
#than one

amounsel = input('Amount to sell: ')
amount = int(amounsel)
newintz = conint + amount


Amount to sell: 6

In [170]:
fildir = (prodir + sellwhat + '/' + sellwhat + '-amount')

In [171]:
sewha = open(fildir, 'w')

sewha.write(str(newintz))

sewha.close()

In [172]:
opfolaz = open(fildir, 'r')

print (opfolaz.read())


6

In [173]:
opfolaz.close()

In [174]:
#Need to report back by updating dict() of 24 hour value
#that sale is +. 

#Dict that is recect of current sale. Name of product, amount.
#Cost * amount.
#Paid by cash, eftpos, credit card etc...
#Change to be given.

In [175]:
locdict = dict()

In [176]:
autc = arrow.utcnow()

In [177]:
hrsaledict = dict()

In [178]:
authr = autc.strftime('%H')

In [179]:
aumin = autc.strftime('%M')

In [180]:
ausec =autc.strftime('%S')

In [181]:
str(autc.date())


Out[181]:
'2015-08-15'

In [182]:
auall = authr + aumin + ausec

In [183]:
fzaq = (str(autc.date()) + '-' + auall)

In [184]:
opcose = open(prodir + sellwhat + '/' + sellwhat + '-price', 'r')

In [185]:
oprdz = opcose.read()

opcose.close()

In [186]:
#price per item
print (oprdz)


456

In [187]:
totopr = int(oprdz) * newintz

In [188]:
totopr


Out[188]:
2736

In [189]:
hrsaledict.update({auall : amount})

In [190]:
locdict.update({'product' : sellwhat, 'amount' : amount, 'time': auall, 'date': str(autc.date()), 'cost': totopr})

In [191]:
lcojson = json.dumps(locdict)

In [192]:
lcojson


Out[192]:
'{"date": "2015-08-15", "cost": 2736, "product": "port-royal", "amount": 6, "time": "115811"}'

In [ ]:


In [193]:
os.urandom(7)


Out[193]:
b'\x1a\r\xfd\xb4f\xe5G'

In [197]:
os.mkdir('/home/wcmckee/sellcoffee/archive/')

In [198]:
salcoj = open('/home/wcmckee/sellcoffee/archive/' + fzaq + '.json', 'w')

salcoj.write(lcojson)

salcoj.close()

In [199]:
#7 character unique id for each transaction
#More than 1 product type sale transaction.

In [200]:
#Add another product? Y/n Question after the amount of product.
#

In [ ]:


In [202]:
rdtwb.send_tweet('Sold ' + sellwhat + ' amount is ' + amounsel + '. Price is' + str(totopr))


Out[202]:
{'contributors': None,
 'coordinates': None,
 'created_at': 'Sat Aug 15 11:59:34 +0000 2015',
 'entities': {'hashtags': [], 'symbols': [], 'urls': [], 'user_mentions': []},
 'favorite_count': 0,
 'favorited': False,
 'geo': None,
 'id': 632522012515151872,
 'id_str': '632522012515151872',
 'in_reply_to_screen_name': None,
 'in_reply_to_status_id': None,
 'in_reply_to_status_id_str': None,
 'in_reply_to_user_id': None,
 'in_reply_to_user_id_str': None,
 'is_quote_status': False,
 'lang': 'en',
 'place': None,
 'retweet_count': 0,
 'retweeted': False,
 'source': '<a href="http://brobeur.com" rel="nofollow">brobeurtweet</a>',
 'text': 'Sold port-royal amount is 6.Cost 2736',
 'truncated': False,
 'user': {'contributors_enabled': False,
  'created_at': 'Sat Mar 30 01:44:05 +0000 2013',
  'default_profile': False,
  'default_profile_image': False,
  'description': 'Video Game Development. #gamedev #linux #getsdrawn',
  'entities': {'description': {'urls': []},
   'url': {'urls': [{'display_url': 'brobeur.com',
      'expanded_url': 'http://brobeur.com',
      'indices': [0, 22],
      'url': 'http://t.co/KRO9XPRA01'}]}},
  'favourites_count': 12,
  'follow_request_sent': False,
  'followers_count': 615,
  'following': False,
  'friends_count': 682,
  'geo_enabled': False,
  'has_extended_profile': False,
  'id': 1315550370,
  'id_str': '1315550370',
  'is_translation_enabled': False,
  'is_translator': False,
  'lang': 'en',
  'listed_count': 34,
  'location': 'Hamilton, New Zealand',
  'name': 'BroBeur.com',
  'notifications': False,
  'profile_background_color': 'C0DEED',
  'profile_background_image_url': 'http://abs.twimg.com/images/themes/theme1/bg.png',
  'profile_background_image_url_https': 'https://abs.twimg.com/images/themes/theme1/bg.png',
  'profile_background_tile': False,
  'profile_banner_url': 'https://pbs.twimg.com/profile_banners/1315550370/1431862528',
  'profile_image_url': 'http://pbs.twimg.com/profile_images/487211737284739072/HBzP949-_normal.png',
  'profile_image_url_https': 'https://pbs.twimg.com/profile_images/487211737284739072/HBzP949-_normal.png',
  'profile_link_color': '300808',
  'profile_sidebar_border_color': 'C0DEED',
  'profile_sidebar_fill_color': 'DDEEF6',
  'profile_text_color': '333333',
  'profile_use_background_image': True,
  'protected': False,
  'screen_name': 'brobeur',
  'statuses_count': 931,
  'time_zone': 'Auckland',
  'url': 'http://t.co/KRO9XPRA01',
  'utc_offset': 43200,
  'verified': False}}

In [ ]: