eceallid

eceallid

Create post for each ECE in New Zealand using data from Ministry of Education. Parse data from the json file. Title of post is ID, content is Name, Address, Suburb and City.

In [47]:
import requests
import os
import getpass
import json
import arrow
In [48]:
jsonlis = os.listdir('/home/{}/ececentres'.format(getpass.getuser()))
In [49]:
#jsonlis
In [50]:
#with open('/home/{}/ececentres/10000.json'.format(getpass.getuser()), 'r') as jsn:
 #       centrejson = jsn.read()
#        cenj = json.loads(centrejson)
#        print(cenj)
In [51]:
raw = arrow.now()
In [52]:
yraw = raw.strftime("%Y")
mntaw = raw.strftime("%m")
dytaw = raw.strftime("%d")
In [53]:
fulda = yraw + '/' + mntaw + '/' + dytaw
In [54]:
fultim = fulda + ' ' + raw.strftime('%H:%M:%S')
In [55]:
fultim
Out[55]:
'2016/12/06 14:14:21'
In [63]:
for jsons in jsonlis:
    #print(jsons)
    #gejs = requests.get('http://192.168.1.15:4321/{}.json'.format(jsons))
    #centrejson = gejs.json()
    #print(centrejson)
    with open('/home/{}/ececentres/{}'.format(getpass.getuser(), jsons), 'r') as jsn:
        centrejson = jsn.read()
        cenj = json.loads(centrejson)
        #print(cenj['ID'])
        #print(cenj['Name'])
        #print(jsn)
        with open('/home/{}/ecenik/posts/{}.rst'.format(getpass.getuser(), str(cenj['ID'])), 'w') as indx:
            indx.write(cenj['Name'] + '\n ' + (cenj['Street']) + '\n' + (cenj['Suburb'] + '\n' + (cenj['City'])))
            
        with open('/home/{}/ecenik/posts/{}.meta'.format(getpass.getuser(), str(cenj['ID'])), 'w') as indx:
            indx.write('.. title: ' + str(cenj['ID']) + ' \n' + '.. slug: ' + str(cenj['ID']) + ' \n' + '.. date: ' + fultim + ' \n' + '.. author: ' + getpass.getuser())
In [57]:
#gejs = requests.get('http://192.168.1.15:4321/{}.json'.format(centreid))
In [58]:
#centrejson = gejs.json()

Comments

Comments powered by Disqus