nikeditfiles

Nik Edit Files

Edit blog files

In [64]:
import nikola

import dominate
from dominate.tags import * 
from time import gmtime, strftime
import time
In [66]:
import os
In [67]:
prodir = ('/home/wcmckee/sellcoffee/products/')
In [68]:
prodlis = os.listdir('/home/wcmckee/sellcoffee/products/')
In [69]:
#Display index.html page that has products list, price, sales
#etc.

prodlis
Out[69]:
['debian']
In [70]:
#(prodir + rdz + '/' + rdz + '-price')
Out[70]:
'/home/wcmckee/sellcoffee/products/internet/internet-price'
In [70]:
 
In [70]:
 
In [ ]:
doc = dominate.document(title='BroBeur CyberCafe products')

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 products')
        h3('BroBeur CyberCafe Products')
        #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 rdz in prodlis:
            #h1(rdz.title)
            #a(rdz.url)
            #p(img(rdz, src='%s' % rdz))
            #print rdz
            #p(img(rdz, src = rdz))
            h3(rdz)
            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
In [ ]:
docre = doc.render()
#s = docre.decode('ascii', 'ignore')
yourstring = docre.encode('ascii', 'ignore').decode('ascii')
indfil = ('/home/wcmckee/sellcoffee/index.html')
mkind = open(indfil, 'w')
mkind.write(yourstring)
mkind.close()
In [ ]:
 

productsell

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 [121]:
import os
import arrow
import json
In [122]:
prodir = ('/home/wcmckee/sellcoffee/products/')
In [123]:
lsprod = os.listdir(prodir)
In [124]:
print lsprod
['debian', 'internet', 'python', 'pepsi', 'coke', 'chips']
In [125]:
sellwhat = raw_input('Sell what: ')
Sell what: python
In [135]:
fpathz = (prodir + sellwhat + '/' + sellwhat + '-amount')
In [136]:
fpathz
Out[136]:
'/home/wcmckee/sellcoffee/products/python/python-amount'
In [137]:
#Open the file up and increase the sale number by one.

selinp = open(fpathz, 'r')

cursal = selinp.read()

selinp.close()
In [139]:
print cursal
0
In [138]:
conint = int(cursal)
In [140]:
#1 is amount to sell. Maybe raw_input enter int to sell more
#than one

amounsel = raw_input('Amount to sell: ')
amount = int(amounsel)
newintz = conint + amount
Amount to sell: 5
In [141]:
newintz
Out[141]:
5
In [142]:
fildir = (prodir + sellwhat + '/' + sellwhat + '-amount') 
In [143]:
fildir
Out[143]:
'/home/wcmckee/sellcoffee/products/python/python-amount'
In [143]:
 
In [144]:
sewha = open(fildir, 'w')

sewha.write(str(newintz))

sewha.close()
In [145]:
opfolaz = open(fildir, 'r')

print opfolaz.read()
5
In [146]:
opfolaz.close()
In [147]:
#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 [148]:
locdict = dict()
In [149]:
autc = arrow.utcnow()
In [150]:
hrsaledict = dict()
In [151]:
authr = autc.strftime('%H')
In [152]:
aumin = autc.strftime('%M')
In [153]:
ausec =autc.strftime('%S')
In [154]:
str(autc.date())
Out[154]:
'2015-03-02'
In [155]:
auall = authr + aumin + ausec
In [169]:
fzaq = (str(autc.date()) + '-' + auall)
In [170]:
fzaq
Out[170]:
'2015-03-02-033801'
In [157]:
hrsaledict.update({auall : amount})
In [158]:
locdict.update({'product' : sellwhat, 'amount' : amount, 'time': auall, 'date': str(autc.date())}) 
In [159]:
lcojson = json.dumps(locdict)
In [160]:
lcojson
Out[160]:
'{"date": "2015-03-02", "product": "python", "amount": 5, "time": "033801"}'
In [161]:
os.urandom(7)
Out[161]:
'J1\x1b\xd8\x04\xd2X'
In [ ]:
fzaq
In [ ]:
salcoj = open('/home/wcmckee/sellcoffee/archive/' + fzaq + '.json', 'w')

salcoj.write(lcojson)

salcoj.close()
In [101]:
print hrsaledict
{'015242': 2}
In [102]:
#7 character unique id for each transaction
#More than 1 product type sale transaction.
In [75]:
#Add another product? Y/n Question after the amount of product.
#
In [ ]:
 

productadd

Product Add

Script to add a new product to list of them. Location is /home/wcmckee/sellcoffee/products.

Better to have a file for products or a folder? Might be easier to have a folder. Each product has rsa key - public and private key.

In [31]:
import os
#from passlib.hash import pbkdf2_sha256
#import crypt, getpass, spwd
#from Crypto.PublicKey import RSA
In [32]:
prodirz = ('/home/wcmckee/sellcoffee/products/')
In [33]:
prolis = os.listdir(prodirz)
In [34]:
print prolis
['debian', 'internet', 'tea', 'coke']
In [35]:
prodoadd = raw_input('Name of product to add: ')
Name of product to add: deb
In [36]:
prodirc = (prodirz + prodoadd)
In [37]:
os.mkdir(prodirc)
In [42]:
opmeta = open(prodirc + '/' +  prodoadd + '-amount', 'w')

opmeta.write('0')

opmeta.close()
In [38]:
#switching to folders for each product. Inside folder has rsa
#and rsa.public.
In [39]:
#opnewp = open(prodirz + prodoadd, 'w')

##opnewp.write('0')
In [43]:
#new_key = RSA.generate(2048, e=65537)
#public_key = new_key.publickey().exportKey("PEM")
#private_key = new_key.exportKey("PEM")
#print private_key 
#sapriv = open(prodirc + '/' + prodoadd, 'w')
#sapriv.write(private_key)
#sapriv.close()

#print public_key 
#papriv =  open(prodirc + '/' +  prodoadd + '.pub', 'w')
#papriv.write(public_key)
#papriv.close()
In [41]:
#dict that has all the product details. When it was first
#created. Price. 
#amount sold. This value will be zero when a product is created
#but add 1 with productsell script. 
#Store amount sold data in dict
#or just a file called productname-amountsold.
In [ ]:
 
In [ ]:
#opnewp.close()
In [11]:
#for prol in prolis:
#    print prol
#    adprod = open(prodirz + prol + '.meta', 'w')
#    adprod.write(
debian
internet
python
coffee
tired
snake
vogals
sleep
In [ ]:
 
In [ ]:
#adprod = open(pro
In [ ]:
 

wcusersdata

wcUsersData

Script to get users logged into the system.

Saves the output of users as the hostname of the system. Convert to a dict and json object, merging with other hostname output.

Runs script every min and if user is found then - time from their account

File with, usernames, time remaining on user.

time file is a json object. {'username' : 'wcmckee', 'time' : 320 }

time is amount of time left on account.

script to check this object and if 0 - lock account. ELSE, allow login.

Script to add time to acoun,, auto add time to certain groups/user a day.

username 45

In [5]:
import os
import socket
import json
In [6]:
usertimedict = dict()
In [7]:
lisho = os.listdir('/home')
In [8]:
for ish in lisho:
    usertimedict.update({ish : 0})
In [9]:
usertimedict
Out[9]:
{'blag': 0,
 'blah': 0,
 'charle': 0,
 'checkthis': 0,
 'clittle': 0,
 'figlet': 0,
 'gerty': 0,
 'jblog': 0,
 'jchick': 0,
 'joecheck': 0,
 'joeman': 0,
 'joemanz': 0,
 'pjohns': 0,
 'poi': 0,
 'point': 0,
 'poiu': 0,
 'pytest': 0,
 'qwe': 0,
 'red': 0,
 'signinlca.py': 0,
 'sjohns': 0,
 'ssung': 0,
 'tnow': 0,
 'wblack': 0,
 'wcm': 0,
 'wcmckee': 0,
 'webmck': 0,
 'wez': 0,
 'wkee': 0,
 'wmen': 0}
In [10]:
addtime = (raw_input('add how much time: '))
add how much time: 15
In [11]:
#letim = len(addtime)
In [12]:
#letim
In [13]:
addtime
Out[13]:
'15'
In [14]:
type(addtime)
Out[14]:
str
In [15]:
intime = int(addtime)
In [16]:
for ish in lisho:
    usertimedict.update({ish : intime})
In [17]:
usertimedict
Out[17]:
{'blag': 15,
 'blah': 15,
 'charle': 15,
 'checkthis': 15,
 'clittle': 15,
 'figlet': 15,
 'gerty': 15,
 'jblog': 15,
 'jchick': 15,
 'joecheck': 15,
 'joeman': 15,
 'joemanz': 15,
 'pjohns': 15,
 'poi': 15,
 'point': 15,
 'poiu': 15,
 'pytest': 15,
 'qwe': 15,
 'red': 15,
 'signinlca.py': 15,
 'sjohns': 15,
 'ssung': 15,
 'tnow': 15,
 'wblack': 15,
 'wcm': 15,
 'wcmckee': 15,
 'webmck': 15,
 'wez': 15,
 'wkee': 15,
 'wmen': 15}
In [19]:
myhn = socket.gethostname()
In [37]:
#Edit just one person

edione = raw_input('Which user to edit time: ')
timedi = raw_input('How much time to add: ')

usertimedict.update({edione : timedi})
Which user to edit time: point
How much time to add: 100
In [20]:
jstim = json.dumps(usertimedict)
In [21]:
jstim
Out[21]:
'{"wcmckee": 15, "joemanz": 15, "point": 15, "qwe": 15, "wkee": 15, "checkthis": 15, "poiu": 15, "blah": 15, "charle": 15, "poi": 15, "tnow": 15, "clittle": 15, "wblack": 15, "ssung": 15, "wmen": 15, "blag": 15, "signinlca.py": 15, "sjohns": 15, "gerty": 15, "webmck": 15, "joeman": 15, "joecheck": 15, "jchick": 15, "pytest": 15, "jblog": 15, "pjohns": 15, "wez": 15, "figlet": 15, "wcm": 15, "red": 15}'
In [24]:
opus = open('/home/wcmckee/sellcoffee/hostnames/' + myhn, 'w')

opus.write(jstim)
opus.close()
In [26]:
rdopuw = open('/home/wcmckee/sellcoffee/hostnames/localhost', 'r')

print rdopuw.read()
{"wcmckee": 15, "joemanz": 15, "point": 15, "qwe": 15, "wkee": 15, "checkthis": 15, "poiu": 15, "blah": 15, "charle": 15, "poi": 15, "tnow": 15, "clittle": 15, "wblack": 15, "ssung": 15, "wmen": 15, "blag": 15, "signinlca.py": 15, "sjohns": 15, "gerty": 15, "webmck": 15, "joeman": 15, "joecheck": 15, "jchick": 15, "pytest": 15, "jblog": 15, "pjohns": 15, "wez": 15, "figlet": 15, "wcm": 15, "red": 15}
In [33]:
edione
Out[33]:
'point'
In [34]:
limedi = int(timedi)
In [35]:
limedi
Out[35]:
15
In [9]:
osscm = ('users > ' + myhn + '.txt')
In [11]:
osscm
Out[11]:
'users > naplesyellow.txt'
In [ ]:
 
In [ ]:
 
In [12]:
os.chdir('/home/wcmckee/sellcoffee/')
In [13]:
os.system(osscm)
Out[13]:
0
In [14]:
ophos = open('/home/wcmckee/sellcoffee/' + myhn + '.txt')
In [15]:
print ophos.read()
Out[15]:
'noby wcmckee wcmckee wcmckee wcmckee wcmckee\n'
In [17]:
ophos.close()
In [ ]:
 
In [ ]:
 

salerev

Sale Rev

Sale Reverse. Sell Stuff.

Python script for point of sale computer time.

more $ == more time.

Opens up sales data of products and saves for daily reports.

Saving the data as a json object. File has name of product as key and amount sold for value.

Easily merge json files.

At the end of each day keep the product in product folder but change sales data to 0.

In [123]:
import arrow
import os
import json
In [124]:
arut = arrow.utcnow()
In [ ]:
arday = arut
In [168]:
 
Out[168]:
'2015-02-28'
In [165]:
cofdot = dict()
In [126]:
#print('a to add time, b to remove time, c to')
a to add time, b to remove time, c to
In [127]:
#subscripe based.
#Get time

#Password expire.
#One month pass.
#10pm to 10am weekend pass.
In [128]:
armonth = arday.replace(month=+1)
In [129]:
armonth.month
Out[129]:
1
In [130]:
bemon = arday.replace(month=+4)
In [131]:
lsitems = os.listdir('/home/wcmckee/sellcoffee/products/')
In [132]:
lsitems

#Sales per day of items. Resets at midnight.
Out[132]:
['debian', 'internet', 'python', 'coffee', 'tired', 'snake', 'vogals', 'sleep']
In [133]:
dirza = ('/home/wcmckee/sellcoffee/products/')
In [140]:
daydict = dict()

#daydict.update({'datetime': str(arday.utcnow())})
In [141]:
for lsit in lsitems:
    print lsit
    #open each item up and read it.
    opitez = open(dirza + lsit, 'r')
    #print opitez.read()
    daydict.update({lsit : opitez.read()})
    opitez.close()
    
    #Make a json object for that days sales. 
    #Name of product. Amount Sold.
    
debian
internet
python
coffee
tired
snake
vogals
sleep
In [142]:
print daydict
{'vogals': '1', 'coffee': '1', 'sleep': '1', 'snake': '1', 'tired': '1', 'python': '1', 'internet': '15', 'debian': '1'}
In [158]:
jsday = json.dumps(daydict)
In [163]:
#The json object.  Should sale it to a folder. Maybe to 
#/yr/mnth/day folder?
#All in one folder, name of json file is datetime.

jsday
Out[163]:
'{"vogals": "1", "coffee": "1", "sleep": "1", "snake": "1", "tired": "1", "python": "1", "internet": "15", "debian": "1"}'
In [ ]:
 
In [169]:
savjsf = open('/home/wcmckee/sellcoffee/archive/' + str(arut.date()) + '.json', 'w')
In [170]:
savjsf.write(jsday)
In [171]:
savjsf.close()
In [172]:
#Reset value of int in products/nameofproducts folder to 0.
In [174]:
for lst in lsitems:
    print lst
    opfolaz = open('/home/wcmckee/sellcoffee/products/' + lst, 'w')
    opfolaz.write('0')
    opfolaz.close()
debian
internet
python
coffee
tired
snake
vogals
sleep
In [143]:
#for r in arrow.Arrow.span_range('hour', arday, bemon):
    #print r
#    for res in r:
#        print res.humanize()
        
In [144]:
#Total sales is value of all items in daydict
In [147]:
print (daydict.values())
['1', '1', '1', '1', '1', '1', '15', '1']
In [149]:
addnum = 0 
In [151]:
for dayv in daydict.values():
    print dayv
    addnum = addnum + int(dayv)
1
1
1
1
1
1
15
1
In [156]:
totdsal = ('Total Sale numbers: ' + str(addnum))
In [157]:
print totdsal
Out[157]:
'Total Sale numbers: 22'
In [ ]:
 

lockacc

LockAcc

Lock Account User Management System

Script to delete, create, lock, and change passwords for users.

Script runs and gives choice for input. a b c d e etc...

Script to lock username. Asks for what user you want to lock, delete, create, lock or change password.

Expire, unlock password.

In [ ]:
import os
import getpass
In [ ]:
#Menu that displays all the options. 
#eg 1 to delete user
#2 to create user
#3 to lock user
#4 to change password
print('a to delete a user, b to create a user, c to lock a user, e to unlock a locked account, f to expire a users password') 
selectchoic = raw_input('Select task by letter: ')

if str('f') in selectchoic:
#lockusr = raw_input('Do you want to lock a user? y/n ')
#if 'y' in lockusr:
    locusa = raw_input("User to password expire: ")
    os.system('sudo passwd -e ' + locusa) 
    #os.system('sudo pgrep -u ' + locusa)
    #os.system('sudo killall -KILL -u ' + locusa)



if str('e') in selectchoic:
#lockusr = raw_input('Do you want to lock a user? y/n ')
#if 'y' in lockusr:
    locusa = raw_input("User to unlock: ")
    os.system('sudo passwd -u ' + locusa) 
    #os.system('sudo pgrep -u ' + locusa)
    #os.system('sudo killall -KILL -u ' + locusa)

#selectchoic = int(selectchoic)
if str('c') in selectchoic:
#lockusr = raw_input('Do you want to lock a user? y/n ')
#if 'y' in lockusr:
    locusa = raw_input("User to lock: ")
    os.system('sudo passwd -l ' + locusa) 
    os.system('sudo pgrep -u ' + locusa)
    os.system('sudo killall -KILL -u ' + locusa)
In [ ]:
#deleusr = raw_input('Do you want to delete a user? y/n ')

#if 'y' in deleusr:
if str('a') in selectchoic:
    print 'y'
    locusa = raw_input("User to Delete: ")
    os.system('sudo passwd -l ' + locusa) 
    os.system('sudo pgrep -u ' + locusa)
    os.system('sudo killall -KILL -u ' + locusa)
    os.system('sudo userdel -r ' + locusa)
    
In [ ]:
#makeusr = raw_input('Do you want to create a user? y/n ')

#if 'y' in makeusr:
if str('b') in selectchoic:
    print 'y'
    cruer = raw_input('Username to Create: ')
    #crpas = getpass.getpass('Password for ' + cruer + ': ')
    usdir = ('sudo useradd ' + cruer)
    os.system(usdir)
    #chdirz = ('sudo passwd ' + cruer + ' ' + crpas)
Do you want to create a user? y/n y
y
Username to Create: libcs
Password for libcs: ········
In [ ]:
#Change a password of a user
#Why not just edit the shadow file and paste encrupted
#password in there?

#This isn't working right now. look at subprocess pipe.
#chanpass = raw_input('Do you want to change a password? y/n ')

#if 'y' in chanpass:
#if str('d') in selectchoic:
#    print 'y'
#    chpasr = raw_input('Username to change password: ')
#    chpasz = getpass.getpass('Enter new password: ')
#    chdirz = ('sudo passwd ' + chpasr + ' ' + chpasz)
    
In [ ]:
#if str('t') in selectchoic:
    

revcoffee

RevCoffee

Reverse Coffee Sales System

This is a script to create coffee sales data. It uses the same base template as lcacoffee.ipnb.

Create a dict with coffee data in

Sell a product = +1 to sales

Cash register base.

Hour, Daily, Monthly, Annual sales data of each item.

10 cents, 20cents, 50cents, 1dollar, 2dollar, 5 dollar, 10 dollar, 20 dollar, 50 dollar, 100 dollar.

Point of sale open source project.

In [0]:
 
In [1]:
import arrow
import os
In [2]:
#I need it to return the day of the week it is.
#etc. Monday, Tuesday, Wednesday, Thursday
In [3]:
arut = arrow.utcnow()
In [4]:
cofdat = dict()
In [5]:
#cofdat
In [6]:
#Add a product.
yop = raw_input('add new product? y/n ')

if 'y' in yop:
    newprod = raw_input('Enter new product: ')

    strprod = str(newprod)
    #dicprod = dict
else:
    print 'not adding new product'
add new product? y/n y
Enter new product: vogals
In [7]:
yepz = raw_input('sell a product? y/n ')
#input product type to sell.
if 'y' in yepz:
    lios = os.listdir('/home/wcmckee/sellcoffee/products/')
    print lios
    useprod = raw_input('Sell What? ')
    useprod
sell a product? y/ny
['debian', 'internet', 'python', 'coffee', 'tired', 'snake']
Sell What? internet
In [8]:
#dict({"test": "again"})
In [9]:
print arut.date()
2015-02-25
In [10]:
print arut.time()
03:33:17.464006
In [11]:
arut.weekday()
Out[11]:
2
In [12]:
cofdat.update({'Day': arut.weekday()})
In [13]:
cofdat.update({'Date': str(arut.date())})
In [14]:
print cofdat
{'Date': '2015-02-25', 'Day': 2}
In [15]:
#for dayhr in range(24):
    #print dayhr
#    cofdat.update({dayhr: ' '})
In [16]:
twenforst = arut.strftime('%H')
In [17]:
twenforst
Out[17]:
'03'
In [18]:
lisprod = ('/home/wcmckee/sellcoffee/products/')
In [52]:
os.listdir(lisprod)
Out[52]:
['debian', 'internet', 'python', 'coffee', 'tired', 'snake', 'vogals']
In [53]:
#Type in shortcuts for selecting items from list.
#id is code for what you can input in order to choose a
#product.
In [20]:
opnumco = open('/home/wcmckee/sellcoffee/products/internet', 'r')

oprz = opnumco.read()
In [21]:
#Need to +1 to this number 
salnumz = int(oprz) + 1
In [22]:
salnumz
Out[22]:
11
In [23]:
savopnum = open('/home/wcmckee/sellcoffee/products/internet', 'w')

savopnum.write(str(salnumz))
In [24]:
savopnum.close()
In [25]:
cofdat.update({twenforst: salnumz})
In [26]:
#cofdat.update({twenforst : numup
In [69]:
cofdat
Out[69]:
{'03': 1, 'Date': '2015-02-25', 'Day': 2}
In [70]:
cofdat.update({twenforst: 1})
In [ ]:
#Get value [hour of the day] of key [amount sold]
In [29]:
#Whats the point in creating keys for hours that don't
#get sales. Just get it to update with hour and add it

#Value is a database on the coffee sale. 
#Currently just numbers.
In [30]:
print cofdat
{'Date': '2015-02-25', '03': 1, 'Day': 2}
In [31]:
sincofd = dict()
In [32]:
import getpass
In [33]:
gusr = getpass.getuser()
In [34]:
gusr
Out[34]:
'wcmckee'
In [35]:
#Outlet is username of sales person
In [36]:
#Product is coffee name. 
#Open and read file that the customer asks
#for type of coffee. 
#Have a order folder that coffees are 
#qued into. 
#Sellcoffee folder
#Usernames - customers
#Staff - Staff list
In [37]:
#opctype = open('/home/wcmckee/sellcoffee/usernames/')
In [38]:
coftag = ('coffee, soymilk')
In [39]:
idnum = 1000
In [40]:
#Amount of coffee sales
cofsal = salnumz
In [41]:
salstot = 4 * salnumz
In [ ]:
#New product id will be os.listdir products len 
#1000 + products len
#This will increase by 1 each time a new product is added.
#Product ids start from 1000 or higher?
In [56]:
amofp = len(os.listdir(lisprod))
In [57]:
neidfp = (amofp + 1000)
In [58]:
neidfp
Out[58]:
1007
In [59]:
#Dict of new product created with this script. 
#Dict is stored with folder of product.
#Details on when product was first created
#It's name, ID, tags, sales counts.

sincofd.update({'Outlet': gusr})

sincofd.update({'Product': strprod})

sincofd.update({'ID': neidfp})
#Tags for this sale. 
sincofd.update({'tags': coftag})
#Sales count of that product
sincofd.update({'count': salnumz})
sincofd.update({'sales': salstot})
In [60]:
sincofd
Out[60]:
{'ID': 1007,
 'Outlet': 'wcmckee',
 'Product': 'vogals',
 'count': 11,
 'sales': 44,
 'tags': 'coffee, soymilk'}
In [61]:
#Need a list of coffee types
#and assign ID to each coffee.
In [62]:
strprod
Out[62]:
'vogals'
In [63]:
savprod = open('/home/wcmckee/sellcoffee/products/' + strprod, 'w')

savprod.write('1')

savprod.close()
In [64]:
#strzict = dict({'test':'again'})
In [65]:
#strzict
In [66]:
dictprod = dict()
In [67]:
#Add internet. Adds computer time to a account.
dictprod.update({newprod: sincofd})
In [68]:
print dictprod
{'vogals': {'count': 11, 'Product': 'vogals', 'Outlet': 'wcmckee', 'tags': 'coffee, soymilk', 'ID': 1007, 'sales': 44}}

testroll

In [75]:
from nose.tools import ok_, eq_
import random
import re
import nose.tools
#import signinlca
import time
import os
In [ ]:
 
In [ ]:
#nose.tools.assert_list_equal
In [42]:
#Nose check dir is there
#Check username is in usernames folder
#Check user is in /home/
In [57]:
#print len('erter23')
7
In [66]:
#Need to nose test raw_input
#charinp = raw_input('Enter number')
Enter numberqwertya
In [67]:
def testlenth():
    if len('blahesrs') > 7:
        assert True
    else:
        assert False

#def testchartyp():
    
# #   assert len('erter23') == 7
In [73]:
import requests
import shutil
In [71]:
def testdirmk():
    if os.path.isdir('/home/wcmckee/github') == True:
        assert True
    else:
        assert False
    #os.mkdir(gtsdrndir)
    
def testimgur():
    if 'http://i.imgur.com' in 'http://i.imgur.com/RfIHXaJ.jpg':
        #print rdz.url
        assert True
    else:
        assert False
        
#def testrequeget():
#    if requests.get('/home/wcmckee/github/signinlca/testroll.py', stream=True):
        
    
        #url = rdz.url
        #response = requests.get(url, stream=True)
        #with open(str(rdz.author) + '-reference.png', 'wb') as out_file:
        #    shutil.copyfileobj(response.raw, out_file)
        #    del response
        
#def test
In [43]:
#def checkstrlen():
#    assert len( 'erter23') < 6
    
In [45]:
#nose.core.logging.codecs
In [46]:
#nose.run(
In [47]:
#def testhomedir():
#    assert os.listdir('/home/wcmckee/') == True

Test that the list is empty.

In [49]:
#def teststr():
#    if ranumlis == []:
#        assert True
#    else:
#        assert False
        
#def testfullis():
#    if ranumlis == list:
#        assert True
#    else:
#        assert False
    
#def testrandnum():
#    if randmun == 5:
#        assert True
#    else:
#        assert False
In [50]:
EMAIL_REGEXP = r'[\S.]+@[\S.]+'

def test_email_regexp():
#   # a regular e-mail address should match
   assert re.match(EMAIL_REGEXP, 'test@nowhere.com')

#   # no domain should fail
#    assert not re.match(EMAIL_REGEXP, 'test@')
In [51]:
#import nose
In [52]:
#nose.tools.assert_greater()

#nose.tools.
In [54]:
#os.listdir('/home/wcmckee/signinlca/')
#os.system('ipython nbconvert /home/wcmckee/github/signinlca/testroll.ipynb --to python')
Out[54]:
0
In [10]:
#def testsum():
#    eq_(4+2,4)
In [13]:
#get_ipython().magic(u'logstart')
#import random
#ranumlis = []
#ranlow = 0
#ranhigh = 9

#for ranez in range(10):
#      randmun = random.randint(ranlow, ranhigh)
#      ranumlis.append(randmun)

#      ranlow = (ranlow + 10)
#      ranhigh = (ranhigh + 10)

#print ranumlis
[1, 15, 26, 37, 41, 58, 64, 74, 80, 95]
In [ ]:
#def testlis():
    
In [6]:
#def test():
#    assert False
In [78]:
#def testpass():
#    pass

#Test counting 0,9 10,19 to 90,99.
In [79]:
#def testcountonhundrd():
#    for coun in range(0,99):
#        yield coun
In [ ]:
def testodd():
    for i in range(0,10):
        yield checkodd, i , i*2
        
def checkodd(n, nn):
    assert n % 3 == 0 or nn % 3 == 0
        
In [77]:
#def testevens():
#    for i in range(0, 99):
#        yield checkeven, i, i*3
        
#def checkeven(n, nn):
#    assert n % 2 == 0 or nn % 2 == 0
In [76]:
#Test 
In [ ]:
#time.sleep(15)
#os.system('nosetests /home/wcmckee/github/signinlca/testroll.py')

bbknikola

BroBeurKids Nikola

This script deals with creating data for BroBeurKids/wcmckee Nikola site.

The directory to look at is brobeurkidsdotcom/posts or folder

wcmckee.com /posts

/github folders are scanned with the input for folders. It's basically a search for notebook, then turn notebook into a blog posts.

Arrow is used to generate the date (YR/MONTH/DAY), and time(HR : MIN: SEC)

This is where ipynb files are kept.

This script generates the .meta files needed.

The meta file is called the same as the ipynb. It also contains the slug and title, and date. The date is collected by looking at the save date of the ipynb.

In [9]:
import os
import getpass
from walkdir import filtered_walk, dir_paths, all_paths, file_paths
import arrow
import nikola
In [33]:
raw = arrow.utcnow()
In [35]:
print raw
2015-02-19T02:30:06.851557+00:00
In [45]:
def returntime():
    return raw.strftime('%H:%M:%S')
In [47]:
returntime()
Out[47]:
'02:30:06'
In [36]:
yraw = raw.strftime("%Y")
mntaw = raw.strftime("%m")
dytaw = raw.strftime("%d")
#gmtz.strftime("%Y")
In [37]:
fulda = yraw + '/' + mntaw + '/' + dytaw
In [48]:
fultim = fulda + ' ' + returntime()
In [49]:
#fultim
Out[49]:
'2015/02/19 02:30:06'
In [9]:
#gtur = getpass.getuser()
In [10]:
#lisbbkn = os.listdir('/home/' + gtur + '/brobeurkidsdotcom/posts')
In [12]:
#lisbbkn
Out[12]:
['.ipynb_checkpoints',
 'when-you-have-then-you-can.ipynb',
 'when-you-have-then-you-can.py',
 'Untitled.txt']
In [14]:
#for lisb in lisbbkn:
#    if '.ipynb' in lisb:
#        print lisb  
.ipynb_checkpoints
when-you-have-then-you-can.ipynb
In [1]:
#Name of notebook you want to turn into a blog
In [65]:
nbog = raw_input('Name of notebook to blog: ')
Name of notebook to blog: pgguserdel
In [66]:
#Search for blog through folders. 
In [67]:
files = file_paths(filtered_walk('/home/wcmckee/github/', depth=100, included_files=[nbog + '.ipynb']))
In [68]:
#print files
<generator object file_paths at 0xb22d03c8>
In [69]:
opblog = ('/home/wcmckee/github/')
In [74]:
podir = ('/home/wcmckee/github/wcmckee.com/posts/')
In [75]:
podir
Out[75]:
'/home/wcmckee/github/wcmckee.com/posts/'
In [70]:
for fie in files:
    #print fie
    print fie
    os.system('cp ' + fie + ' ' + podir)
/home/wcmckee/github/wcmckee.com/posts/pgguserdel.ipynb
/home/wcmckee/github/signinlca/pgguserdel.ipynb
In [71]:
opeza = open(podir + nbog + '.meta', 'w')
opeza.write(nbog + '\n' + nbog + '\n' + fultim)
opeza.close()
In [ ]:
 
In [ ]:
os.chdir('/home/wcmckee/github/wcmckee.com/')
os.system('nikola build')

pgguserdel

In [13]:
import os
import getpass
from passlib.hash import pbkdf2_sha256
import crypt, getpass, spwd
from Crypto.PublicKey import RSA
In [14]:
fuliz = os.listdir('/home')
In [15]:
fuliz
Out[15]:
['tnow',
 'sjohns',
 'signinlca.py',
 'charle',
 'wcm',
 'wmck',
 'wmen',
 'webmck',
 'pjohns',
 'red',
 'wez',
 'checkthis',
 'blah',
 'joeman',
 'wkee',
 'jchick',
 'wcmckee',
 'wblack',
 'joemanz',
 'poiu',
 'poi',
 'qwe',
 'point',
 'cvb',
 'pytest',
 'figlet',
 'blag',
 'gerty',
 'jblog',
 'ssung',
 'clittle',
 'joecheck',
 'yellow']
In [16]:
#Chabge password for user
#pasuz = raw_input('User to change password: ')
In [17]:
#logtest = getpass.getpass('new password: ')

#loghash = pbkdf2_sha256.encrypt(logtest, rounds=200000, salt_size=16)
#vercryp = pbkdf2_sha256.verify(logtest, hashez)
In [18]:
#Enter user to delete.
#Even better, user to lock.

#delusa = raw_input('User to delete: ')
#locusa = raw_input('User to lock: ')
#os.system('sudo passwd -l ' + locusa) 
In [19]:
#Read hashed passwords from /etc/shadow
#opshad = open('/etc/shadow', 'r')
#opshad.read()
#opshad.close()
#Better to do this with a python module. spwd reads
#shadow files done.
#Need to getpass and ask for password, comparing to 
#the password returned from spwd
In [20]:
pan = 'wcmckee'
In [21]:
#enc_pwd = spwd.getspnam(pan)[1]
#if enc_pwd in ["NP", "!", "", None]:
#    print "user '%s' has no password set" % pan
#if enc_pwd in ["LK", "*"]:
#    print "account is locked"
#if enc_pwd == "!!":
#    print "password has expired"
In [22]:
gpas = getpass.getpass('Enter Username Password: ')
Enter Username Password: ········
In [32]:
encpass = spwd.getspnam(pan)[1]
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-32-9aef7c527eb2> in <module>()
----> 1 encpass = spwd.getspnam(pan)[1]

KeyError: 'getspnam(): name not found'
In [33]:
if crypt.crypt(gpas, encpass) == encpass:
    print ('True')
else:
    print "incorrect password"
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-33-4efe7353fce3> in <module>()
----> 1 if crypt.crypt(gpas, encpass) == encpass:
      2     print ('True')
      3 else:
      4     print "incorrect password"

NameError: name 'encpass' is not defined
In [34]:
#print spwd.getspnam(pan)[1]
In [35]:
#shpa = spwd.getspnam('wcmckee')[1]
In [36]:
#spwd.getspall()
In [37]:
#shpa

rsa key generated for each user and stored in their /home/user/.ssh/ folder. Public key is emailed, added to test servers.

In [38]:
new_key = RSA.generate(2048, e=65537)
public_key = new_key.publickey().exportKey("PEM")
private_key = new_key.exportKey("PEM")
print private_key 
sapriv = open('/home/wcmckee/.ssh/' + pan, 'w')
sapriv.write(private_key)
sapriv.close()

print public_key 
papriv = open('/home/wcmckee/.ssh/' + pan + '.pub', 'w')
papriv.write(public_key)
papriv.close()
-----BEGIN RSA PRIVATE KEY-----
MIIEowIBAAKCAQEAvEzwE1+D6TX2wDGUBhSZmwYkVsnVjoYiklhGBBIdg5jMHVkh
93HLlvu04KWAwSQHLIUFy4teTxovw+eo/5+VJAlelJZWcgctMsL+U1uRImD+aieV
uKEN65fCMdRIautEnPDAi9g51XleqpXvK/nGR9BRA5ibR31kcL+OYSqjFY0tlTdV
5JQ0jSZdudjgnNE33lrBwpdCUL112C4dT2r/gDfHM8icsitkhqnGxJ/xsw1sDaW8
ENSg73/lJO9Sc8j8d/mjVVVPHGs0TJneLq6Y/mF7QQq8Os0TAlXG+EnR/bX1saKa
qhxiFmKvF5ww/uSu79xkK2LajPY+DS27kia7yQIDAQABAoIBADl+HEcuAK6yBVcF
TDbXD1df9rRxB71ugxu/zBDuHwjRHHFRh6dvnUPKMp3sqnVONMqJCw3szazFSBQ+
pUD3TqgkHDat+FL0kf5PvytgZ93hU4zB7VrkAcYPHgHs2PecQeTRNVj9ehsN5bOb
99yrdLj0h+fbLn4TcRljw2szg3vOiykVe650zwu0D1J1/JxBq4bG/YndsLCPqdMk
5uZoroKx5myHnCMXRxChJAyHw+HZ1xcMGhpXE0ghqQuW8obxU4IA2T1NBWow8xCO
f1QbQR473Oat0WsBrJoHgks1SpyfO+/eomhUNG42UgeJjIWgB2s2P19nKWuTeMtc
epaAdCECgYEA2OvgGkeo1/e7k6QDS52N3s6S3MKwQksSAsRaeV3vYE7Dcb3zjNWh
d8UbzVcSN1cKVRc27j1EIBAHlRHCan45JJOeqlmnYS5g6IeF+nB74067J4gvwTbe
zciAX3NEIk5WbpdDuLzkFnajUgwiHxEVxS5WIvvUbuYpphi2lV7fLhUCgYEA3jkb
ZnJckNoNsKUbHUV/EjsEQC50kSZJ9RNh55rMfcI4uhbaJTE23eQeygtt102v0R+w
kvHRrcnjTa3mvpYL9grVfmsiSnaYL8IW75uSNgnBW7LIMsJjT7HjKok/2Sm7r4rR
sFOJCfY/jWGBpKGGlx52IJEJaF3w5acSy/4sN+UCgYBxSO4mi1oAP950Qml+KfAX
diZ4qCxI0s+7JjRhwc7rqvajBiKVYFQNKqFUYa6fvBMnURJc5R4Y6IYtMbMoznal
RXrNWDjzpbbyeSRdIDVzBoDzKkpWS4OcUKPKNXZVvDejVdgGOI+ds6Oji7aeJtwJ
uCM/7eiJaiZCGhHwfDVt6QKBgQC59xhS90k3fwMN3F2AdXQNkY3RGA88mMozaXD5
HLYcV7iZIh6UGUdNEWYitsXI8546Z0ag8fUCdnzduLXssCx6Tj6zeHxNzEk3Tjlb
ctk8l5VUY5zdvYbWXos4QXtJBH+oO4eXA5Ee4Q/2BK81UmcLd9ZrEnTI/jRmOxaj
16SxcQKBgA7E1J3fJTSEiEDu2tB5KHKe1LDZzoPda1qe1NASefJArsJYpjCU+GY6
DvvBCXv7ovWWJa7Vi1BEGZ0/INc/SCK1WVWbC9FcdLlbANW3Kp7m/bZmNZv95cU1
8gHPA8QCgATWtSBtZQr299166brw2OGv9qx0FSqLVjvyPi7FPeJZ
-----END RSA PRIVATE KEY-----
-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvEzwE1+D6TX2wDGUBhSZ
mwYkVsnVjoYiklhGBBIdg5jMHVkh93HLlvu04KWAwSQHLIUFy4teTxovw+eo/5+V
JAlelJZWcgctMsL+U1uRImD+aieVuKEN65fCMdRIautEnPDAi9g51XleqpXvK/nG
R9BRA5ibR31kcL+OYSqjFY0tlTdV5JQ0jSZdudjgnNE33lrBwpdCUL112C4dT2r/
gDfHM8icsitkhqnGxJ/xsw1sDaW8ENSg73/lJO9Sc8j8d/mjVVVPHGs0TJneLq6Y
/mF7QQq8Os0TAlXG+EnR/bX1saKaqhxiFmKvF5ww/uSu79xkK2LajPY+DS27kia7
yQIDAQAB
-----END PUBLIC KEY-----
In [39]:
#Spin up digital ocean server, with public key and 
#user created.
In [1]:
#import digitalocean
In [2]:
#tok  = ('c54ea484dcf55053743215cdb37309cb77a153e9810f35851b4701d4c8bf2881')
In [3]:
#digid = digitalocean.Manager(token='c54ea484dcf55053743215cdb37309cb77a153e9810f35851b4701d4c8bf2881')
In [4]:
#digid.get_account
Out[4]:
<bound method Manager.get_account of <digitalocean.Manager.Manager object at 0xb1a49390>>
In [15]:
#my_droplets = digid.get_all_droplets()
In [16]:
#lisdrop = []
In [17]:
#for myd in my_droplets:
#    print myd
    #lisdrop.append(myd.image)
    #
#    lisdrop.append(myd.ip_address)
1331748 brobeur.com
2109421 brobeurkids
2531143 wcmckee-notebook
3353353 getsdrawn
In [18]:
#lisdrop
Out[18]:
[u'128.199.199.74', u'178.62.53.181', u'104.131.11.174', u'128.199.60.12']
In [ ]:
 
In [7]:
#droplet = digitalocean.Droplet(token=tok,
#                               name='Example',
#                               region='nyc2', # New York 2
##                               image= , # Ubuntu 14.04 x64
 #                              size_slug='512mb',  # 512MB
#                              backups=True)
  File "<ipython-input-7-cdb0ee9afb58>", line 4
    image= , # Ubuntu 14.04 x64
           ^
SyntaxError: invalid syntax
In [8]:
#droplet.create()
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-8-e40debe66120> in <module>()
----> 1 droplet.create()

NameError: name 'droplet' is not defined
In [9]:
#dimg = digid.get_all_images()
In [10]:
#for di in dimg:
##    print di
4985495 wcmckee Debian
6126511 wcmckee Ubuntu
10690295 artcontrol final Debian
10564942 557.2.0 (beta) CoreOS
10679356 557.2.0 (stable) CoreOS
10679369 593.0.0 (alpha) CoreOS
6370882 20 x64 Fedora
6370885 20 x32 Fedora
6370968 19 x64 Fedora
6370969 19 x32 Fedora
6372321 5.10 x64 CentOS
6372425 5.10 x32 CentOS
6372581 6.0 x64 Debian
6372662 6.0 x32 Debian
9640922 21 x64 Fedora
9801948 14.04 x32 Ubuntu
9801950 14.04 x64 Ubuntu
9801951 14.10 x32 Ubuntu
9801954 14.10 x64 Ubuntu
10144573 10.1 FreeBSD
10321756 12.04.5 x64 Ubuntu
10321777 12.04.5 x32 Ubuntu
10321819 10.04 x64 Ubuntu
10321870 10.04 x32 Ubuntu
10322059 7.0 x64 Debian
10322378 7.0 x32 Debian
10322623 7 x64 CentOS
10325922 6.5 x64 CentOS
10325992 6.5 x32 CentOS
6376601 Ruby on Rails on 14.04 (Nginx + Unicorn) Ubuntu
6423475 WordPress on 14.04 Ubuntu
6732690 LEMP on 14.04 Ubuntu
6732691 LAMP on 14.04 Ubuntu
6798184 MEAN on 14.04 Ubuntu
8375425 Drupal 7.34 on 14.04 Ubuntu
8412876 Magento 1.9.1.0 on 14.04 Ubuntu
8953301 ELK Logging Stack on 14.04 Ubuntu
9918633 Ghost 0.5.8 on 14.04 Ubuntu
9967718 Django on 14.04 Ubuntu
10163059 FreeBSD AMP on 10.1 FreeBSD
10274087 GitLab 7.7.1 CE on 14.04 Ubuntu
10321359 MediaWiki 1.24.0 on 14.04 Ubuntu
10462503 Drone on 14.04 Ubuntu
10507592 node-v0.12.0 on 14.04 Ubuntu
10563620 Dokku v0.3.14 on 14.04 Ubuntu
10565666 ownCloud 8.0 on 14.04 Ubuntu
10581649 Docker 1.5.0 on 14.04 Ubuntu
7572830 Redmine on 14.04 Ubuntu
In [23]:
#opdel = os.listdir('/home/wcmckee/signinlca/deleteusers')
In [24]:
#opdel
Out[24]:
[]
In [ ]:
usrtodel = raw_input('Account to delete: ')
In [ ]:
locacc = os.system('sudo passwd -l ' + usrtodel)
In [ ]:
locacc
In [ ]:
os.system('mv ' + '  ' + '/home/wcmckee/signinlca/usernames/' + usrtodel + ' /home/wcmckee/signinlca/username/deleteusers/')