Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.