Skip to content

Instantly share code, notes, and snippets.

@tdgunes
Created July 10, 2014 13:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tdgunes/920b76a4d84244bf541b to your computer and use it in GitHub Desktop.
Save tdgunes/920b76a4d84244bf541b to your computer and use it in GitHub Desktop.
Test data generator
# !/usr/bin/python
# -*- coding: utf-8 -*-
"""
geo_test_gen.py
~~~~~~~~~~
Author: Taha Dogan Gunes
"""
import json
def ask():
while True:
try:
lat = float(raw_input("Lat: "))
lon = float(raw_input("Lon: "))
comment = raw_input("Comment: ")
return {"lat":lat,"lon":lon,"comment":comment}
except KeyboardInterrupt:
return
except:
print "Wrong input type!"
continue
def main():
with open("test.json", "a") as f, open('test_wc.json', 'a') as g:
while True:
data = ask()
if data:
g.write(json.dumps(data)+"\n")
data.pop("comment",None)
f.write(json.dumps(data)+"\n")
else:
break
if __name__ == '__main__':
print "Control-C to Exit&Save"
main()
print "Files saved as test.json and test_wc.json, wc is not WC :)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment