btcethaud

In [100]:
import requests
import time
import getpass
import os
import json
import arrow
In [101]:
import sqlite3
In [102]:
blockconnect = sqlite3.connect('blockchain.db')
In [103]:
bcon = blockconnect.cursor()
In [104]:
try:
    bcon.execute('''CREATE TABLE blockchain
                    (datetime, ethval, bcval)''')
    bcon.execute('INSERT INTO blockchain VALUES ({}, {}. {})'.format())
except Exception:
        pass
In [105]:
nowtime = arrow.now()
In [106]:
myusr = getpass.getuser()
In [107]:
#confpat = '/home/{}/.config'.format(myusr)

#fulpat = '{}/blockchain.json'.format(confpat)

#if 'blockchain.json' in os.listdir(confpat):
#    pass
#else:
#    bcdic = dict({'oldbtc' : '0', 'oldeth' : '0', 'updated' : '2017-08-19T13:26:29.240023+12:00'})
#    bcjs = json.dumps(bcdic)
#    print(bcjs)
    # Writing our configuration file to 'example.cfg'
#    with open(fulpat, 'w') as configfile:
#        configfile.write(bcjs)
    
#with open(fulpat, 'r') as faljs:
    #print(faljs.read())
#    convjs = json.loads(faljs.read())
    
#print(convjs)
#oldbtc = convjs['oldbtc']
#oldeth = convjs['oldeth']

payload = {'fsyms' : 'ETH,BTC', 'tsyms' : 'AUD'}

reqetc = requests.get('https://min-api.cryptocompare.com/data/pricemulti', params= payload)
nowtime = arrow.now()
etjs = reqetc.json()

#if float(etjs['BTC']['AUD']) == float(oldbtc):
#    btcchange = 'no change'
#elif float(etjs['BTC']['AUD']) > float(oldbtc):
#    btcchange = 'increase'
#elif float(etjs['BTC']['AUD']) < float(oldbtc):
#    btcchange = 'decrease'
    
#if float(etjs['ETH']['AUD']) == float(oldeth):
#    ethchange = 'no change'
#elif float(etjs['ETH']['AUD']) > float(oldeth):
#    ethchange = 'increase'
#elif float(etjs['ETH']['AUD']) < float(oldeth):
#    ethchange = 'decrease'
    
#diffbtc = abs(float(etjs['BTC']['AUD'])-float(oldbtc))
#diffeth = abs(float(etjs['ETH']['AUD'])-float(oldeth))
#print(str(float(diffbtc)) + ' ' + str(float(diffeth)))
#oldtime = convjs['updated']
#print('AUD. BTC: {}. Old price: {}. {}. ETH: {}. Old price: {}. {}'.format(etjs['BTC']['AUD'], oldbtc, btcchange, etjs['ETH']['AUD'], oldeth, ethchange))
#print('old time: ' + oldtime + ' current time: ' + nowtime.for_json())
#print(bt hchange)


#bcdic = dict({'oldbtc' : etjs['BTC']['AUD'], 'oldeth' : etjs['ETH']['AUD'], 'btcdiff' : diffbtc, 'ethdiff' : diffeth, 'updated' : nowtime.for_json()})
#bcjs = json.dumps(bcdic)

#with open(fulpat, 'w') as configfile:
#    configfile.write(bcjs)
In [108]:
#bcdic
In [109]:
bcon.execute('INSERT INTO blockchain VALUES ({}, {}, {})'.format(nowtime.timestamp, etjs['BTC']['AUD'], etjs['ETH']['AUD']))
---------------------------------------------------------------------------
OperationalError                          Traceback (most recent call last)
<ipython-input-109-e4fcb48d2d08> in <module>()
----> 1 bcon.execute('INSERT INTO blockchain VALUES ({}, {}, {})'.format(nowtime.timestamp, etjs['BTC']['AUD'], etjs['ETH']['AUD']))

OperationalError: database is locked
In [ ]:
blockconnect.commit()
In [110]:
for row in bcon.execute('SELECT * FROM blockchain'):
    print(row)
In [111]:
#bcon.commit()
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-111-f467ff2d8d78> in <module>()
----> 1 bcon.commit()

AttributeError: 'sqlite3.Cursor' object has no attribute 'commit'
In [112]:
blockconnect.close()
In [ ]:
 
In [ ]:
 

rbnz-blog

parse reserve bank blog

In [1]:
import requests
import xmltodict
import bs4
from bs4 import BeautifulSoup
import getpass
import nltk
In [2]:
myusr = getpass.getuser()
In [3]:
myreq = requests.get('http://www.rbnz.govt.nz/feeds/news')
In [4]:
xlpars = xmltodict.parse(myreq.text)
In [5]:
xlitem = xlpars['rss']['channel']['item']
In [6]:
blogtxt = list()
In [8]:
for xli in xlitem:
    tit = (xli['title'])
    titslug = tit.replace(' ', '-')
    print(titslug)
    print(xli['link'])
    myxl = requests.get(xli['link'])
    #myso = bs4.BeautifulSoup(myxl)
    #print(myso.)
    #print(myxl.text)
    #print(myxl)
    putime = (xli['pubDate'])
    
    with open('/home/{}/artctrl/posts/{}.meta'.format(myusr, titslug[0:15]), 'w') as rbn:
        rbn.write('..title: {}\n.. slug: {}\n.. date: {}\n'.format(titslug, titslug, putime))
        rbn.write(xli['description'])
        
#    .. title: wer
#.. slug: wer
#.. date: 2017-07-30 00:56:50 UTC+12:00
#.. tags: 
#.. link: 
#.. description: 
#.. type: text
    #with open(newfile, 'w') as outfile
        
        
    
    
    soup = BeautifulSoup(myxl.text, 'html.parser')
    #print(soup)
    finpo = soup.find_all('p')
    
    finp = finpo[:2]
    #finp.text
    with open('/home/{}/artctrl/posts/{}.rst'.format(myusr, titslug[0:15]), 'w') as rbn:
        rbn.write('{}\n\n{}\n\n{}'.format(titslug, xli['description'], finp))
    
    for finp in finpo[:2]:
        print(finp.text)
        blogtxt.append(finp.text)
        #with open('/home/{}/rbnz/posts/{}.rst'.format(myusr, titslug[0:15]), 'a') as rbn:
        #    rbn.write('{\n\n{}\n\n'.format(str(finp.text)))
        #rbn.write(xli['description'])
        
        
    #print(finpo[:2])
    #refError = soup.findAll('span', { 'class': 'mw-ext-cite-error'})


    #print(xli['pubDate'])
    #print(xli['description'])
Reserve-Bank-leasing-office-space-to-Defence-Force
http://www.rbnz.govt.nz/news/2017/09/reserve-bank-leasing-office-space-to-defence-force
The New Zealand Defence Force has signed a lease to occupy three floors in the Reserve Bank of New Zealand building, beginning later this year.
Reserve Bank Head of Currency, Property and Security, Steve Gordon, said that the Defence Force will be the fourth tenant in the building, joining the Parliamentary Counsel Office; Parliamentary Commissioner for the Environment; and the State Services Commission. The Reserve Bank has vacated the floors that are being leased to the Defence Force, as part of a strategy to increase its property income to meet its Funding Agreement. 
Reserve-Bank-policy-a-key-driver-in-economic-performance
http://www.rbnz.govt.nz/news/2017/08/reserve-bank-policy-a-key-driver-in-economic-performance
---------------------------------------------------------------------------
UnicodeEncodeError                        Traceback (most recent call last)
<ipython-input-8-a681473fa36f> in <module>()
     13     with open('/home/{}/artctrl/posts/{}.meta'.format(myusr, titslug[0:15]), 'w') as rbn:
     14         rbn.write('..title: {}\n.. slug: {}\n.. date: {}\n'.format(titslug, titslug, putime))
---> 15         rbn.write(xli['description'])
     16 
     17 #    .. title: wer

UnicodeEncodeError: 'ascii' codec can't encode character '\u2019' in position 16: ordinal not in range(128)
In [ ]:
mybltx = ' '.join(blogtxt)
In [ ]:
nltool = nltk.word_tokenize(mybltx)
In [ ]:
tagged = nltk.pos_tag(nltool)
In [1]:
word_tag_pairs = nltk.bigrams(nbrown_news_tagged)
noun_preceders = [a[1] for (a, b) in word_tag_pairs if b[1] == 'NOUN']
fdist = nltk.FreqDist(noun_preceders)
[tag for (tag, _) in fdist.most_common()]
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-1-55f5a166a831> in <module>()
----> 1 word_tag_pairs = nltk.bigrams(nbrown_news_tagged)
      2 noun_preceders = [a[1] for (a, b) in word_tag_pairs if b[1] == 'NOUN']
      3 fdist = nltk.FreqDist(noun_preceders)
      4 [tag for (tag, _) in fdist.most_common()]

NameError: name 'nltk' is not defined

xchangerate

reserve bank exchange rate

downloads excel file from rbnz. Saves to to local file system. Convert content to json and serve.

In [2]:
import xmltodict
import requests
import shutil
import getpass
import arrow
#import pandas
import json
In [3]:
myusr = getpass.getuser()
In [5]:
reqdaily = requests.get('http://www.rbnz.govt.nz/-/media/ReserveBank/Files/Statistics/tables/b1/hb1-daily.xls', stream=True)
---------------------------------------------------------------------------
SSLError                                  Traceback (most recent call last)
/usr/local/lib/python3.5/dist-packages/requests/packages/urllib3/connectionpool.py in urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, **response_kw)
    599                                                   body=body, headers=headers,
--> 600                                                   chunked=chunked)
    601 

/usr/local/lib/python3.5/dist-packages/requests/packages/urllib3/connectionpool.py in _make_request(self, conn, method, url, timeout, chunked, **httplib_request_kw)
    344         try:
--> 345             self._validate_conn(conn)
    346         except (SocketTimeout, BaseSSLError) as e:

/usr/local/lib/python3.5/dist-packages/requests/packages/urllib3/connectionpool.py in _validate_conn(self, conn)
    843         if not getattr(conn, 'sock', None):  # AppEngine might not have  `.sock`
--> 844             conn.connect()
    845 

/usr/local/lib/python3.5/dist-packages/requests/packages/urllib3/connection.py in connect(self)
    325             server_hostname=hostname,
--> 326             ssl_context=context)
    327 

/usr/local/lib/python3.5/dist-packages/requests/packages/urllib3/util/ssl_.py in ssl_wrap_socket(sock, keyfile, certfile, cert_reqs, ca_certs, server_hostname, ssl_version, ciphers, ssl_context, ca_cert_dir)
    324     if HAS_SNI:  # Platform-specific: OpenSSL with enabled SNI
--> 325         return context.wrap_socket(sock, server_hostname=server_hostname)
    326 

/usr/lib/python3.5/ssl.py in wrap_socket(self, sock, server_side, do_handshake_on_connect, suppress_ragged_eofs, server_hostname)
    384                          server_hostname=server_hostname,
--> 385                          _context=self)
    386 

/usr/lib/python3.5/ssl.py in __init__(self, sock, keyfile, certfile, server_side, cert_reqs, ssl_version, ca_certs, do_handshake_on_connect, family, type, proto, fileno, suppress_ragged_eofs, npn_protocols, ciphers, server_hostname, _context)
    759                         raise ValueError("do_handshake_on_connect should not be specified for non-blocking sockets")
--> 760                     self.do_handshake()
    761 

/usr/lib/python3.5/ssl.py in do_handshake(self, block)
    995                 self.settimeout(None)
--> 996             self._sslobj.do_handshake()
    997         finally:

/usr/lib/python3.5/ssl.py in do_handshake(self)
    640         """Start the SSL/TLS handshake."""
--> 641         self._sslobj.do_handshake()
    642         if self.context.check_hostname:

SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:720)

During handling of the above exception, another exception occurred:

SSLError                                  Traceback (most recent call last)
/usr/local/lib/python3.5/dist-packages/requests/adapters.py in send(self, request, stream, timeout, verify, cert, proxies)
    437                     retries=self.max_retries,
--> 438                     timeout=timeout
    439                 )

/usr/local/lib/python3.5/dist-packages/requests/packages/urllib3/connectionpool.py in urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, **response_kw)
    629             clean_exit = False
--> 630             raise SSLError(e)
    631 

SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:720)

During handling of the above exception, another exception occurred:

SSLError                                  Traceback (most recent call last)
<ipython-input-5-1e3388871684> in <module>()
----> 1 reqdaily = requests.get('http://www.rbnz.govt.nz/-/media/ReserveBank/Files/Statistics/tables/b1/hb1-daily.xls', stream=True)

/usr/local/lib/python3.5/dist-packages/requests/api.py in get(url, params, **kwargs)
     70 
     71     kwargs.setdefault('allow_redirects', True)
---> 72     return request('get', url, params=params, **kwargs)
     73 
     74 

/usr/local/lib/python3.5/dist-packages/requests/api.py in request(method, url, **kwargs)
     56     # cases, and look like a memory leak in others.
     57     with sessions.Session() as session:
---> 58         return session.request(method=method, url=url, **kwargs)
     59 
     60 

/usr/local/lib/python3.5/dist-packages/requests/sessions.py in request(self, method, url, params, data, headers, cookies, files, auth, timeout, allow_redirects, proxies, hooks, stream, verify, cert, json)
    516         }
    517         send_kwargs.update(settings)
--> 518         resp = self.send(prep, **send_kwargs)
    519 
    520         return resp

/usr/local/lib/python3.5/dist-packages/requests/sessions.py in send(self, request, **kwargs)
    659 
    660         # Resolve redirects if allowed.
--> 661         history = [resp for resp in gen] if allow_redirects else []
    662 
    663         # Shuffle things around if there's history.

/usr/local/lib/python3.5/dist-packages/requests/sessions.py in <listcomp>(.0)
    659 
    660         # Resolve redirects if allowed.
--> 661         history = [resp for resp in gen] if allow_redirects else []
    662 
    663         # Shuffle things around if there's history.

/usr/local/lib/python3.5/dist-packages/requests/sessions.py in resolve_redirects(self, resp, req, stream, timeout, verify, cert, proxies, **adapter_kwargs)
    212                 proxies=proxies,
    213                 allow_redirects=False,
--> 214                 **adapter_kwargs
    215             )
    216 

/usr/local/lib/python3.5/dist-packages/requests/sessions.py in send(self, request, **kwargs)
    637 
    638         # Send the request
--> 639         r = adapter.send(request, **kwargs)
    640 
    641         # Total elapsed time of the request (approximately)

/usr/local/lib/python3.5/dist-packages/requests/adapters.py in send(self, request, stream, timeout, verify, cert, proxies)
    510         except (_SSLError, _HTTPError) as e:
    511             if isinstance(e, _SSLError):
--> 512                 raise SSLError(e, request=request)
    513             elif isinstance(e, ReadTimeoutError):
    514                 raise ReadTimeout(e, request=request)

SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:720)
In [ ]:
usrpat = '/home/{}'.format(myusr)
In [46]:
#import requests
#dls = "http://www.muellerindustries.com/uploads/pdf/UW SPD0114.xls"
#resp = requests.get(dls)
with open('{}/daily.xls'.format(usrpat), 'wb') as output:
    output.write(reqdaily.content)
In [49]:
dailyrd = pandas.read_excel('{}/daily.xls'.format(usrpat), header=1, index_col=0, skiprows=[2,3,4])
In [53]:
tojsn = dailyrd.to_json()
In [55]:
jsz = json.loads(tojsn)
In [41]:
with open('/home/{}/artctrl/exchange.json'.format(myusr), 'w') as exchan:
          exchan.write(str(jsz))

          

creates3site

creates3site

Python script to ask for bucket name, creates a aws s3 bucket, config for static site, uploads permissions, creates a nikola site, uploads site.

In [1]:
import subprocess
import json
import os
In [2]:
import getpass
In [3]:
myusr = getpass.getuser()
In [ ]:
 
In [4]:
class devsite():
    def makebucket(namebucket):
        subprocess.call('aws s3 mb s3://{}'.format(namebucket), shell=True)
    
    def makewwwbucket(namebucket):
        subprocess.call('aws s3 mb s3://www.{}'.format(namebucket), shell=True)
        
    def createapp(namebucket):
        subprocess.call('aws elasticbeanstalk create-application --application-name {} --description "{}"'.format(namebucket, namebucket), shell=True)
        
    def deleteapp(namebucket):
        subprocess.call('aws elasticbeanstalk delete-application --application-name {}'.format(namebucket))
        
    def infoapp():
        #subprocess.call('aws elasticbeanstalk describe-applications')
        return(subprocess.check_output(["aws", "elasticbeanstalk", "describe-applications"]))
    
    def listbucket():
        return(subprocess.check_output('aws s3api list-buckets --query "Buckets[].Name" --output "json"', shell=True))
    
    def wsconf(namebucket):
        subprocess.call('aws s3api put-bucket-website --bucket {} --website-configuration file://website.json'.format(namebucket), shell=True)
    
    def nikinit(namebucket):
        subprocess.call('nikola init -q /home/{}/sites/{}'.format(myusr, namebucket), shell=True)
In [5]:
devsite.infoapp()
Out[5]:
b'{\n    "Applications": [\n        {\n            "DateCreated": "2018-04-08T06:51:52.953Z",\n            "ConfigurationTemplates": [],\n            "Description": "testing",\n            "ApplicationName": "testing",\n            "DateUpdated": "2018-04-08T06:51:52.953Z"\n        },\n        {\n            "DateCreated": "2018-04-08T02:28:16.318Z",\n            "ConfigurationTemplates": [],\n            "Description": "my application",\n            "ApplicationName": "MyApp",\n            "DateUpdated": "2018-04-08T02:28:16.318Z"\n        },\n        {\n            "Versions": [\n                "Sample Application"\n            ],\n            "DateCreated": "2018-04-06T14:59:34.304Z",\n            "ConfigurationTemplates": [],\n            "ApplicationName": "lonesearch",\n            "DateUpdated": "2018-04-06T14:59:34.304Z"\n        }\n    ]\n}\n'
In [ ]:
 
In [9]:
devsite.nikinit('newtest')
In [ ]:
with open('/home/{}/sites/{}/conf.py'.format(myusr, ))
In [ ]:
 
In [3]:
devsite.infoapp()
---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
<ipython-input-3-0c87a5520995> in <module>()
----> 1 devsite.infoapp()

<ipython-input-2-8dbc3a253c7d> in infoapp()
     14     def infoapp():
     15         #subprocess.call('aws elasticbeanstalk describe-applications')
---> 16         return(subprocess.check_output('aws elasticbeanstalk describe-applications'))
     17 
     18     def listbucket():

/usr/lib/python3.5/subprocess.py in check_output(timeout, *popenargs, **kwargs)
    624 
    625     return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
--> 626                **kwargs).stdout
    627 
    628 

/usr/lib/python3.5/subprocess.py in run(input, timeout, check, *popenargs, **kwargs)
    691         kwargs['stdin'] = PIPE
    692 
--> 693     with Popen(*popenargs, **kwargs) as process:
    694         try:
    695             stdout, stderr = process.communicate(input, timeout=timeout)

/usr/lib/python3.5/subprocess.py in __init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds)
    945                                 c2pread, c2pwrite,
    946                                 errread, errwrite,
--> 947                                 restore_signals, start_new_session)
    948         except:
    949             # Cleanup if the child failed starting.

/usr/lib/python3.5/subprocess.py in _execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, restore_signals, start_new_session)
   1549                             else:
   1550                                 err_msg += ': ' + repr(orig_executable)
-> 1551                     raise child_exception_type(errno_num, err_msg)
   1552                 raise child_exception_type(err_msg)
   1553 

FileNotFoundError: [Errno 2] No such file or directory: 'aws elasticbeanstalk describe-applications'
In [4]:
devsite.deleteapp('MyApp')
---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
<ipython-input-4-2db2f960bca5> in <module>()
----> 1 devsite.deleteapp('MyApp')

<ipython-input-2-8dbc3a253c7d> in deleteapp(namebucket)
     10 
     11     def deleteapp(namebucket):
---> 12         subprocess.call('aws elasticbeanstalk delete-application --application-name {}'.format(namebucket))
     13 
     14     def infoapp():

/usr/lib/python3.5/subprocess.py in call(timeout, *popenargs, **kwargs)
    555     retcode = call(["ls", "-l"])
    556     """
--> 557     with Popen(*popenargs, **kwargs) as p:
    558         try:
    559             return p.wait(timeout=timeout)

/usr/lib/python3.5/subprocess.py in __init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds)
    945                                 c2pread, c2pwrite,
    946                                 errread, errwrite,
--> 947                                 restore_signals, start_new_session)
    948         except:
    949             # Cleanup if the child failed starting.

/usr/lib/python3.5/subprocess.py in _execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, restore_signals, start_new_session)
   1549                             else:
   1550                                 err_msg += ': ' + repr(orig_executable)
-> 1551                     raise child_exception_type(errno_num, err_msg)
   1552                 raise child_exception_type(err_msg)
   1553 

FileNotFoundError: [Errno 2] No such file or directory: 'aws elasticbeanstalk delete-application --application-name MyApp'
In [ ]:
 
In [5]:
devsite.createapp('testing')
In [6]:
myitems = devsite.listbucket()
In [7]:
myitems
Out[7]:
b'[\n    "artcontrol.me",\n    "artcontrolme",\n    "artcontrolstage.me",\n    "artctrl-stage",\n    "artctrl-staging",\n    "artctrl.com",\n    "artctrl.me",\n    "artctrlme.com",\n    "breakdownand.com",\n    "breakdownandcry.com",\n    "edlawlx",\n    "edlawlx.com",\n    "edugovtnzjobs",\n    "elasticbeanstalk-ap-southeast-2-457225832206",\n    "govhacknz.org.nz",\n    "grandmasparty",\n    "hellotesting",\n    "jobsgovtnz",\n    "kiwijamnowtest",\n    "lifedrawinghamilton",\n    "moejobs",\n    "moejobs-govthacknz16",\n    "wcmckee.tk",\n    "writersdenhamilton.org.nz",\n    "www.artctrl.me",\n    "www.artctrlme.com",\n    "www.breakdownand.com",\n    "www.breakdownandcry.com",\n    "www.wcmckee.tk",\n    "www.writersdenhamilton.org.nz"\n]\n'
In [19]:
myitems.replace('\n', '')
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-19-4cf8d037f9e0> in <module>()
----> 1 myitems.replace('\n', '')

TypeError: a bytes-like object is required, not 'str'
In [ ]:
str(myitems)
In [7]:
type (myitems)
Out[7]:
bytes
In [28]:
myitems.capitalize()
Out[28]:
b'[\n    "artcontrol.me",\n    "artcontrolme",\n    "artcontrolstage.me",\n    "artctrl-stage",\n    "artctrl-staging",\n    "artctrl.com",\n    "artctrl.me",\n    "artctrlme.com",\n    "breakdownand.com",\n    "breakdownandcry.com",\n    "edlawlx",\n    "edlawlx.com",\n    "edugovtnzjobs",\n    "elasticbeanstalk-ap-southeast-2-457225832206",\n    "govhacknz.org.nz",\n    "grandmasparty",\n    "hellotesting",\n    "jobsgovtnz",\n    "kiwijamnowtest",\n    "lifedrawinghamilton",\n    "moejobs",\n    "moejobs-govthacknz16",\n    "wcmckee.tk",\n    "writersdenhamilton.org.nz",\n    "www.artctrl.me",\n    "www.artctrlme.com",\n    "www.breakdownand.com",\n    "www.breakdownandcry.com",\n    "www.wcmckee.tk",\n    "www.writersdenhamilton.org.nz"\n]\n'
In [31]:
for it in myitems:
    print(it.from_bytes{})
  File "<ipython-input-31-92ca706ce492>", line 2
    print(it.from_bytes{})
                       ^
SyntaxError: invalid syntax
In [8]:
mydecode = myitems.decode("utf-8")
In [9]:
mylis = mydecode.replace('\n', '')
In [10]:
type(mylis)
Out[10]:
str
In [11]:
myspli =  mylis.split('  ')
In [12]:
type(myspli)
Out[12]:
list
In [14]:
lenspi = len(myspli)
In [16]:
for mys in range(0, lenspi, 2):
    print(myspli[mys])
[
"artcontrol.me",
"artcontrolme",
"artcontrolstage.me",
"artctrl-stage",
"artctrl-staging",
"artctrl.com",
"artctrl.me",
"artctrlme.com",
"breakdownand.com",
"breakdownandcry.com",
"edlawlx",
"edlawlx.com",
"edugovtnzjobs",
"elasticbeanstalk-ap-southeast-2-457225832206",
"govhacknz.org.nz",
"grandmasparty",
"hellotesting",
"jobsgovtnz",
"kiwijamnowtest",
"lifedrawinghamilton",
"moejobs",
"moejobs-govthacknz16",
"wcmckee.tk",
"writersdenhamilton.org.nz",
"www.artctrl.me",
"www.artctrlme.com",
"www.breakdownand.com",
"www.breakdownandcry.com",
"www.wcmckee.tk",
"www.writersdenhamilton.org.nz"]
In [ ]:
 
In [13]:
print(myspli[8])
"artctrl-stage",
In [ ]:
range(0, 10, 2)
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [39]:
list(mydecode)
Out[39]:
['[',
 '\n',
 ' ',
 ' ',
 ' ',
 ' ',
 '"',
 'a',
 'r',
 't',
 'c',
 'o',
 'n',
 't',
 'r',
 'o',
 'l',
 '.',
 'm',
 'e',
 '"',
 ',',
 '\n',
 ' ',
 ' ',
 ' ',
 ' ',
 '"',
 'a',
 'r',
 't',
 'c',
 'o',
 'n',
 't',
 'r',
 'o',
 'l',
 'm',
 'e',
 '"',
 ',',
 '\n',
 ' ',
 ' ',
 ' ',
 ' ',
 '"',
 'a',
 'r',
 't',
 'c',
 'o',
 'n',
 't',
 'r',
 'o',
 'l',
 's',
 't',
 'a',
 'g',
 'e',
 '.',
 'm',
 'e',
 '"',
 ',',
 '\n',
 ' ',
 ' ',
 ' ',
 ' ',
 '"',
 'a',
 'r',
 't',
 'c',
 't',
 'r',
 'l',
 '-',
 's',
 't',
 'a',
 'g',
 'e',
 '"',
 ',',
 '\n',
 ' ',
 ' ',
 ' ',
 ' ',
 '"',
 'a',
 'r',
 't',
 'c',
 't',
 'r',
 'l',
 '-',
 's',
 't',
 'a',
 'g',
 'i',
 'n',
 'g',
 '"',
 ',',
 '\n',
 ' ',
 ' ',
 ' ',
 ' ',
 '"',
 'a',
 'r',
 't',
 'c',
 't',
 'r',
 'l',
 '.',
 'c',
 'o',
 'm',
 '"',
 ',',
 '\n',
 ' ',
 ' ',
 ' ',
 ' ',
 '"',
 'a',
 'r',
 't',
 'c',
 't',
 'r',
 'l',
 '.',
 'm',
 'e',
 '"',
 ',',
 '\n',
 ' ',
 ' ',
 ' ',
 ' ',
 '"',
 'a',
 'r',
 't',
 'c',
 't',
 'r',
 'l',
 'm',
 'e',
 '.',
 'c',
 'o',
 'm',
 '"',
 ',',
 '\n',
 ' ',
 ' ',
 ' ',
 ' ',
 '"',
 'b',
 'r',
 'e',
 'a',
 'k',
 'd',
 'o',
 'w',
 'n',
 'a',
 'n',
 'd',
 '.',
 'c',
 'o',
 'm',
 '"',
 ',',
 '\n',
 ' ',
 ' ',
 ' ',
 ' ',
 '"',
 'b',
 'r',
 'e',
 'a',
 'k',
 'd',
 'o',
 'w',
 'n',
 'a',
 'n',
 'd',
 'c',
 'r',
 'y',
 '.',
 'c',
 'o',
 'm',
 '"',
 ',',
 '\n',
 ' ',
 ' ',
 ' ',
 ' ',
 '"',
 'e',
 'd',
 'l',
 'a',
 'w',
 'l',
 'x',
 '"',
 ',',
 '\n',
 ' ',
 ' ',
 ' ',
 ' ',
 '"',
 'e',
 'd',
 'l',
 'a',
 'w',
 'l',
 'x',
 '.',
 'c',
 'o',
 'm',
 '"',
 ',',
 '\n',
 ' ',
 ' ',
 ' ',
 ' ',
 '"',
 'e',
 'd',
 'u',
 'g',
 'o',
 'v',
 't',
 'n',
 'z',
 'j',
 'o',
 'b',
 's',
 '"',
 ',',
 '\n',
 ' ',
 ' ',
 ' ',
 ' ',
 '"',
 'e',
 'l',
 'a',
 's',
 't',
 'i',
 'c',
 'b',
 'e',
 'a',
 'n',
 's',
 't',
 'a',
 'l',
 'k',
 '-',
 'a',
 'p',
 '-',
 's',
 'o',
 'u',
 't',
 'h',
 'e',
 'a',
 's',
 't',
 '-',
 '2',
 '-',
 '4',
 '5',
 '7',
 '2',
 '2',
 '5',
 '8',
 '3',
 '2',
 '2',
 '0',
 '6',
 '"',
 ',',
 '\n',
 ' ',
 ' ',
 ' ',
 ' ',
 '"',
 'g',
 'o',
 'v',
 'h',
 'a',
 'c',
 'k',
 'n',
 'z',
 '.',
 'o',
 'r',
 'g',
 '.',
 'n',
 'z',
 '"',
 ',',
 '\n',
 ' ',
 ' ',
 ' ',
 ' ',
 '"',
 'g',
 'r',
 'a',
 'n',
 'd',
 'm',
 'a',
 's',
 'p',
 'a',
 'r',
 't',
 'y',
 '"',
 ',',
 '\n',
 ' ',
 ' ',
 ' ',
 ' ',
 '"',
 'h',
 'e',
 'l',
 'l',
 'o',
 't',
 'e',
 's',
 't',
 'i',
 'n',
 'g',
 '"',
 ',',
 '\n',
 ' ',
 ' ',
 ' ',
 ' ',
 '"',
 'j',
 'o',
 'b',
 's',
 'g',
 'o',
 'v',
 't',
 'n',
 'z',
 '"',
 ',',
 '\n',
 ' ',
 ' ',
 ' ',
 ' ',
 '"',
 'k',
 'i',
 'w',
 'i',
 'j',
 'a',
 'm',
 'n',
 'o',
 'w',
 't',
 'e',
 's',
 't',
 '"',
 ',',
 '\n',
 ' ',
 ' ',
 ' ',
 ' ',
 '"',
 'l',
 'i',
 'f',
 'e',
 'd',
 'r',
 'a',
 'w',
 'i',
 'n',
 'g',
 'h',
 'a',
 'm',
 'i',
 'l',
 't',
 'o',
 'n',
 '"',
 ',',
 '\n',
 ' ',
 ' ',
 ' ',
 ' ',
 '"',
 'm',
 'o',
 'e',
 'j',
 'o',
 'b',
 's',
 '"',
 ',',
 '\n',
 ' ',
 ' ',
 ' ',
 ' ',
 '"',
 'm',
 'o',
 'e',
 'j',
 'o',
 'b',
 's',
 '-',
 'g',
 'o',
 'v',
 't',
 'h',
 'a',
 'c',
 'k',
 'n',
 'z',
 '1',
 '6',
 '"',
 ',',
 '\n',
 ' ',
 ' ',
 ' ',
 ' ',
 '"',
 'w',
 'c',
 'm',
 'c',
 'k',
 'e',
 'e',
 '.',
 't',
 'k',
 '"',
 ',',
 '\n',
 ' ',
 ' ',
 ' ',
 ' ',
 '"',
 'w',
 'r',
 'i',
 't',
 'e',
 'r',
 's',
 'd',
 'e',
 'n',
 'h',
 'a',
 'm',
 'i',
 'l',
 't',
 'o',
 'n',
 '.',
 'o',
 'r',
 'g',
 '.',
 'n',
 'z',
 '"',
 ',',
 '\n',
 ' ',
 ' ',
 ' ',
 ' ',
 '"',
 'w',
 'w',
 'w',
 '.',
 'a',
 'r',
 't',
 'c',
 't',
 'r',
 'l',
 '.',
 'm',
 'e',
 '"',
 ',',
 '\n',
 ' ',
 ' ',
 ' ',
 ' ',
 '"',
 'w',
 'w',
 'w',
 '.',
 'a',
 'r',
 't',
 'c',
 't',
 'r',
 'l',
 'm',
 'e',
 '.',
 'c',
 'o',
 'm',
 '"',
 ',',
 '\n',
 ' ',
 ' ',
 ' ',
 ' ',
 '"',
 'w',
 'w',
 'w',
 '.',
 'b',
 'r',
 'e',
 'a',
 'k',
 'd',
 'o',
 'w',
 'n',
 'a',
 'n',
 'd',
 '.',
 'c',
 'o',
 'm',
 '"',
 ',',
 '\n',
 ' ',
 ' ',
 ' ',
 ' ',
 '"',
 'w',
 'w',
 'w',
 '.',
 'b',
 'r',
 'e',
 'a',
 'k',
 'd',
 'o',
 'w',
 'n',
 'a',
 'n',
 'd',
 'c',
 'r',
 'y',
 '.',
 'c',
 'o',
 'm',
 '"',
 ',',
 '\n',
 ' ',
 ' ',
 ' ',
 ' ',
 '"',
 'w',
 'w',
 'w',
 '.',
 'w',
 'c',
 'm',
 'c',
 'k',
 'e',
 'e',
 '.',
 't',
 'k',
 '"',
 ',',
 '\n',
 ' ',
 ' ',
 ' ',
 ' ',
 '"',
 'w',
 'w',
 'w',
 '.',
 'w',
 'r',
 'i',
 't',
 'e',
 'r',
 's',
 'd',
 'e',
 'n',
 'h',
 'a',
 'm',
 'i',
 'l',
 't',
 'o',
 'n',
 '.',
 'o',
 'r',
 'g',
 '.',
 'n',
 'z',
 '"',
 '\n',
 ']',
 '\n']
In [ ]:
 
In [ ]:
 
In [36]:
for myit in myitems.decode("utf-8"):
    print(myit )
[


 
 
 
 
"
a
r
t
c
o
n
t
r
o
l
.
m
e
"
,


 
 
 
 
"
a
r
t
c
o
n
t
r
o
l
m
e
"
,


 
 
 
 
"
a
r
t
c
o
n
t
r
o
l
s
t
a
g
e
.
m
e
"
,


 
 
 
 
"
a
r
t
c
t
r
l
-
s
t
a
g
e
"
,


 
 
 
 
"
a
r
t
c
t
r
l
-
s
t
a
g
i
n
g
"
,


 
 
 
 
"
a
r
t
c
t
r
l
.
c
o
m
"
,


 
 
 
 
"
a
r
t
c
t
r
l
.
m
e
"
,


 
 
 
 
"
a
r
t
c
t
r
l
m
e
.
c
o
m
"
,


 
 
 
 
"
b
r
e
a
k
d
o
w
n
a
n
d
.
c
o
m
"
,


 
 
 
 
"
b
r
e
a
k
d
o
w
n
a
n
d
c
r
y
.
c
o
m
"
,


 
 
 
 
"
e
d
l
a
w
l
x
"
,


 
 
 
 
"
e
d
l
a
w
l
x
.
c
o
m
"
,


 
 
 
 
"
e
d
u
g
o
v
t
n
z
j
o
b
s
"
,


 
 
 
 
"
e
l
a
s
t
i
c
b
e
a
n
s
t
a
l
k
-
a
p
-
s
o
u
t
h
e
a
s
t
-
2
-
4
5
7
2
2
5
8
3
2
2
0
6
"
,


 
 
 
 
"
g
o
v
h
a
c
k
n
z
.
o
r
g
.
n
z
"
,


 
 
 
 
"
g
r
a
n
d
m
a
s
p
a
r
t
y
"
,


 
 
 
 
"
h
e
l
l
o
t
e
s
t
i
n
g
"
,


 
 
 
 
"
j
o
b
s
g
o
v
t
n
z
"
,


 
 
 
 
"
k
i
w
i
j
a
m
n
o
w
t
e
s
t
"
,


 
 
 
 
"
l
i
f
e
d
r
a
w
i
n
g
h
a
m
i
l
t
o
n
"
,


 
 
 
 
"
m
o
e
j
o
b
s
"
,


 
 
 
 
"
m
o
e
j
o
b
s
-
g
o
v
t
h
a
c
k
n
z
1
6
"
,


 
 
 
 
"
w
c
m
c
k
e
e
.
t
k
"
,


 
 
 
 
"
w
r
i
t
e
r
s
d
e
n
h
a
m
i
l
t
o
n
.
o
r
g
.
n
z
"
,


 
 
 
 
"
w
w
w
.
a
r
t
c
t
r
l
.
m
e
"
,


 
 
 
 
"
w
w
w
.
a
r
t
c
t
r
l
m
e
.
c
o
m
"
,


 
 
 
 
"
w
w
w
.
b
r
e
a
k
d
o
w
n
a
n
d
.
c
o
m
"
,


 
 
 
 
"
w
w
w
.
b
r
e
a
k
d
o
w
n
a
n
d
c
r
y
.
c
o
m
"
,


 
 
 
 
"
w
w
w
.
w
c
m
c
k
e
e
.
t
k
"
,


 
 
 
 
"
w
w
w
.
w
r
i
t
e
r
s
d
e
n
h
a
m
i
l
t
o
n
.
o
r
g
.
n
z
"


]


In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [12]:
for devs in devsite.listbucket():
    print(devs)
91
10
32
32
32
32
34
97
114
116
99
111
110
116
114
111
108
46
109
101
34
44
10
32
32
32
32
34
97
114
116
99
111
110
116
114
111
108
109
101
34
44
10
32
32
32
32
34
97
114
116
99
111
110
116
114
111
108
115
116
97
103
101
46
109
101
34
44
10
32
32
32
32
34
97
114
116
99
116
114
108
45
115
116
97
103
101
34
44
10
32
32
32
32
34
97
114
116
99
116
114
108
45
115
116
97
103
105
110
103
34
44
10
32
32
32
32
34
97
114
116
99
116
114
108
46
99
111
109
34
44
10
32
32
32
32
34
97
114
116
99
116
114
108
46
109
101
34
44
10
32
32
32
32
34
97
114
116
99
116
114
108
109
101
46
99
111
109
34
44
10
32
32
32
32
34
98
114
101
97
107
100
111
119
110
97
110
100
46
99
111
109
34
44
10
32
32
32
32
34
98
114
101
97
107
100
111
119
110
97
110
100
99
114
121
46
99
111
109
34
44
10
32
32
32
32
34
101
100
108
97
119
108
120
34
44
10
32
32
32
32
34
101
100
108
97
119
108
120
46
99
111
109
34
44
10
32
32
32
32
34
101
100
117
103
111
118
116
110
122
106
111
98
115
34
44
10
32
32
32
32
34
101
108
97
115
116
105
99
98
101
97
110
115
116
97
108
107
45
97
112
45
115
111
117
116
104
101
97
115
116
45
50
45
52
53
55
50
50
53
56
51
50
50
48
54
34
44
10
32
32
32
32
34
103
111
118
104
97
99
107
110
122
46
111
114
103
46
110
122
34
44
10
32
32
32
32
34
103
114
97
110
100
109
97
115
112
97
114
116
121
34
44
10
32
32
32
32
34
104
101
108
108
111
116
101
115
116
105
110
103
34
44
10
32
32
32
32
34
106
111
98
115
103
111
118
116
110
122
34
44
10
32
32
32
32
34
107
105
119
105
106
97
109
110
111
119
116
101
115
116
34
44
10
32
32
32
32
34
108
105
102
101
100
114
97
119
105
110
103
104
97
109
105
108
116
111
110
34
44
10
32
32
32
32
34
109
111
101
106
111
98
115
34
44
10
32
32
32
32
34
109
111
101
106
111
98
115
45
103
111
118
116
104
97
99
107
110
122
49
54
34
44
10
32
32
32
32
34
119
99
109
99
107
101
101
46
116
107
34
44
10
32
32
32
32
34
119
114
105
116
101
114
115
100
101
110
104
97
109
105
108
116
111
110
46
111
114
103
46
110
122
34
44
10
32
32
32
32
34
119
119
119
46
97
114
116
99
116
114
108
46
109
101
34
44
10
32
32
32
32
34
119
119
119
46
97
114
116
99
116
114
108
109
101
46
99
111
109
34
44
10
32
32
32
32
34
119
119
119
46
98
114
101
97
107
100
111
119
110
97
110
100
46
99
111
109
34
44
10
32
32
32
32
34
119
119
119
46
98
114
101
97
107
100
111
119
110
97
110
100
99
114
121
46
99
111
109
34
44
10
32
32
32
32
34
119
119
119
46
119
99
109
99
107
101
101
46
116
107
34
44
10
32
32
32
32
34
119
119
119
46
119
114
105
116
101
114
115
100
101
110
104
97
109
105
108
116
111
110
46
111
114
103
46
110
122
34
10
93
10
In [ ]:
 
In [ ]:
 
In [3]:
devSite.makebucket('lonewill')
In [ ]:
 
In [2]:
def makebucket(namebucket):
    subprocess.call('aws s3 mb s3://{}'.format(namebucket), shell=True)
    
In [3]:
def makewwwbucket(namebucket):
    subprocess.call('aws s3 mb s3://www.{}'.format(namebucket), shell=True)
    
In [4]:
def wsconf(namebucket):
    subprocess.call('aws s3api put-bucket-website --bucket {} --website-configuration file://website.json'.format(namebucket), shell=True)
In [5]:
def wsindex(namebucket):
    subprocess.call('aws s3 website s3://{} --index-document index.html --error-document error.html'.format(namebucket), shell=True)
In [6]:
def nikinit(namebucket):
    subprocess.call('nikola init -q {}'.format(namebucket), shell=True)
In [7]:
makebucket('breakdownand.com')
In [8]:
makewwwbucket('breakdownand.com')
In [9]:
wsconf('breakdownand.com')
In [11]:
wsindex('breakdownand.com')
In [13]:
nikinit('breakdownand.com')
In [43]:
def permop(namebucket):
    with open('permission.json', 'r') as permj:
        permrd = (permj.read())
        editjs = permrd.replace('editthis', namebucket)
    with open('permission.json', 'w') as permwrit:
        permwrit.write(editjs)
    subprocess.call('aws s3api put-bucket-policy --bucket {} --policy file://permission.json'.format(namebucket), shell=True)
        
In [45]:
with open('permission.json', 'r') as permj:
        permrd = (permj.read())
        editjs = permrd.replace('editthis', namebucket)
with open('permission.json', 'w') as permwrit:
    permwrit.write(editjs)
        
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-45-8ebf0f6de56c> in <module>()
      1 with open('permission.json', 'r') as permj:
      2         permrd = (permj.read())
----> 3         editjs = permrd.replace('editthis', namebucket)
      4 with open('permission.json', 'w') as permwrit:
      5     permwrit.write(editjs)

NameError: name 'namebucket' is not defined
In [ ]:
 
In [44]:
permop('breakdownand.com')
In [39]:
permop('breakdown.com')
Out[39]:
'{"Version": "2012-10-17", "Statement": [{"Sid": "PublicReadGetObject", "Action": ["s3:GetObject"], "Principal": "*", "Resource": ["arn:aws:s3:::breakdownandcry.com/*"], "Effect": "Allow"}]}'
In [47]:
def retusome(namebucket):
    return namebucket 
In [48]:
retusome('breakdownand.com')
Out[48]:
'breakdownand.com'
In [ ]:
 
In [11]:
with open('permission.json', 'r+') as permj:
    permrd = (permj.read())
In [12]:
anperz = permrd.replace('examplebucket', retusome('breakdownand.com'))
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-12-5e15dc492438> in <module>()
----> 1 anperz = permrd.replace('examplebucket', retusome('breakdownand.com'))

NameError: name 'retusome' is not defined
In [13]:
jslo = json.loads(anperz)
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-13-47bc08ee43e6> in <module>()
----> 1 jslo = json.loads(anperz)

NameError: name 'anperz' is not defined
In [63]:
editjs = json.dumps(jslo)
In [66]:
with open('permission.json', 'w') as permwrit:
    permwrit.write(editjs)
In [69]:
def sstact(namebucket):
    subprocess.call('aws s3api put-bucket-policy --bucket {} --policy file://permission.json'.format(namebucket), shell=True)
In [70]:
sstact('breakdownand.com')
In [105]:
with open('{}/conf.py'.format(inputnam), 'r+') as configz:
    confrd = (configz.read())
In [110]:
confiza = confrd.replace("Demo Site", inputnam.replace('.com', ''))
    
In [112]:
with open('{}/conf.py'.format(inputnam), 'w') as confix:
    confix.write(confiza)    
In [114]:
os.chdir('breakdownandcry.com/')
In [116]:
subprocess.call('nikola build', shell= True)
Out[116]:
0
In [119]:
os.chdir('output')
In [121]:
subprocess.call('aws s3 sync . s3://{}'.format(inputnam), shell=True)
Out[121]:
0