-
Notifications
You must be signed in to change notification settings - Fork 2
/
bulkremote.py
64 lines (55 loc) · 2.55 KB
/
bulkremote.py
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
58
59
60
61
62
63
64
"""The Python implementation of the gRPC Godbledger client. Sends bulk transactions using generatedExpenses.json and generatedIncome.json to a remote server"""
from __future__ import print_function
import random
import logging
import grpc
import json
import transaction_pb2
import transaction_pb2_grpc
from tqdm import tqdm
def run():
with grpc.insecure_channel('play.godbledger.com:50051') as channel:
stub = transaction_pb2_grpc.TransactorStub(channel)
with open('generatedIncome.json') as f:
incometransactions = json.load(f)
print("-------------- Sending Income Transactions --------------")
for transaction in tqdm(incometransactions):
response = stub.AddTransaction(transaction_pb2.TransactionRequest(
date= transaction["date"][0:10],
description= transaction["description"],
lines=[
transaction_pb2.LineItem(
accountname= transaction["account"],
description= transaction["description"],
amount=-transaction["balance"]),
transaction_pb2.LineItem(
accountname="Cash",
description= transaction["description"],
amount=transaction["balance"])
]
))
# print(response)
# quit()
with open('generatedExpenses.json') as f:
expensetransactions = json.load(f)
print("-------------- Sending Expense Transactions --------------")
for transaction in tqdm(expensetransactions):
response = stub.AddTransaction(transaction_pb2.TransactionRequest(
date= transaction["date"][0:10],
description= transaction["description"],
lines=[
transaction_pb2.LineItem(
accountname= transaction["account"],
description= transaction["description"],
amount=transaction["balance"]),
transaction_pb2.LineItem(
accountname="Cash",
description= transaction["description"],
amount=-transaction["balance"])
]
))
# print(response)
# quit()
if __name__ == '__main__':
logging.basicConfig()
run()