-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
57 lines (48 loc) · 1.3 KB
/
main.py
File metadata and controls
57 lines (48 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
"""
this demo python application create random data
fro the I1820 platform.
"""
import datetime
import random
import sys
import pymongo
def data() -> dict:
"""
generate random data
"""
lng, lat = random.choice(
[(51.4133924, 35.7944779), (50.952981, 35.723737)]
)
return {
"data": {
"motion": str(random.randint(0, 1)),
"humidity": str(random.randint(0, 100)),
"temperature": str(random.randint(20, 40)),
"light": str(random.randint(0, 1024)),
"_location": {"type": "Point", "coordinate": [lng, lat]},
},
"timestamp": datetime.datetime.now(),
"thingid": "0000000000000074",
"rxinfo": None,
"txinfo": None,
"project": "5d08d39f5958ce34d42058d6",
"protocol": "lan",
"model": "aolab",
}
def usage():
"""
usage function print a usage message
"""
print(
"main.py <database-url e.g. mongodb://127.0.0.1:27017>"
"<database-name> <collection-name> <count>"
)
sys.exit(-1)
if __name__ == "__main__":
if len(sys.argv) != 5:
usage()
cli = pymongo.MongoClient(sys.argv[1])
db = cli[sys.argv[2]]
collection = db[sys.argv[3]]
for _ in range(int(sys.argv[4])):
collection.insert_one(data())