Skip to content

Instantly share code, notes, and snippets.

@AnyISalIn
Last active July 21, 2017 06:00
Show Gist options
  • Save AnyISalIn/696c1bd7cf739cbce61ac48b378fcbc8 to your computer and use it in GitHub Desktop.
Save AnyISalIn/696c1bd7cf739cbce61ac48b378fcbc8 to your computer and use it in GitHub Desktop.
water quality test data
from datetime import datetime
from water_quality.security import WaterCipher
import csv
import requests
import logging
import json
TITLE = ['TIMESTAMP', 'Turbid', 'TOC', 'COD', 'DOC', 'NH3']
def read_data():
with open('./water_quality.csv', 'rU') as f:
reader = csv.reader(f)
items = [row for row in reader][1:]
for item in items:
date = item.pop(0)
time = item.pop(0)
item.insert(0, datetime.strptime(
'{} {}'.format(date, time), '%d/%m/%Y %H:%M').strftime('%s'))
yield dict(zip(TITLE, item))
def request():
w = WaterCipher()
for item in read_data():
enc_data = w.encrypt(json.dumps(item))
res = requests.post(
'http://localhost:5000/api/water_quality', data=enc_data)
if res.status_code > 400:
logging.warning('some error {}'.format(res.json()))
else:
logging.info('success')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment